akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
struct l
{
    int v;
    l* prv;
    l* next;
};
void DeleteNode(l* del, l** first, l** last)
{
    if (del->prv != NULL)
        del->prv->next = del->next;
    else
        *first = del->next;
        
    if (del->next != NULL)
        del->next->prv = del->prv;
    else
        *last = del->prv;

    delete del;
    del = NULL;
}
int main()
{
    l* t;
    l* first = NULL;
    l* last = NULL;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        long v; char s[12];
        cin >> s;
        if (s[0] == 'i')
        {
            l* t = new l();
            t->prv = NULL;
            t->next = NULL;
            cin >> t->v;
            if (last == NULL)
            {
                last = t;
            }
            else
            {
                first->prv = t;
            }
            t->next = first;
            first = t;
            continue;
        }

        if (first == NULL)
            continue;

        if (s[6] == 'F')
        {
            DeleteNode(first, &first, &last);
        }
        else if (s[6] == 'L')
        {
            DeleteNode(last, &first, &last);
        }
        else
        {
            long a;
            cin >> a;

            for (l* t = first; t != NULL; t = t->next)
            {
                if (t->v == a)
                {
                    DeleteNode(t, &first, &last);
                    break;
                }
            }
        }
    }

    t = first;
    while (t != NULL)
    {
        l* old = t;
        cout << t->v << (t->next != NULL ? " " : "\n");
        t = t->next;
        delete old;
    }
}



Measured memory_bytes: 34348
#include <stdio.h>

typedef int keytype;

void inssort(int n, keytype a[])
{
    int i, j;
    keytype x;

    for (i = 1; i < n; i++) {
        x = a[i];
        for (j = i - 1; j >= 0 && a[j] > x; j--)
            a[j + 1] = a[j];
        a[j + 1] = x;
    }
}

#define THRESHOLD 10
#define STACKSIZE 32  /* たかだか int のビット数程度 */

void quicksort(int n, keytype a[])
{
    int i, j, left, right, p;
    int leftstack[STACKSIZE], rightstack[STACKSIZE];
    keytype x, t;

    left = 0;  right = n - 1;  p = 0;
    for ( ; ; ) {
        if (right - left <= THRESHOLD) {
            if (p == 0) break;
            p--;
            left = leftstack[p];
            right = rightstack[p];
        }
        x = a[(left + right) / 2];
        i = left;  j = right;
        for ( ; ; ) {
            while (a[i] < x) i++;
            while (x < a[j]) j--;
            if (i >= j) break;
            t = a[i];  a[i] = a[j];  a[j] = t;
            i++;  j--;
        }
        if (i - left > right - j) {
            if (i - left > THRESHOLD) {
                leftstack[p] = left;
                rightstack[p] = i - 1;
                p++;
            }
            left = j + 1;
        } else {
            if (right - j > THRESHOLD) {
                leftstack[p] = j + 1;
                rightstack[p] = right;
                p++;
            }
            right = i - 1;
        }
    }
    inssort(n, a);
}

int main(){
    int x, n;
    int p[110];

    scanf("%d %d", &x, &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &p[i]);
    }

    quicksort(n, p);

    /*
    for(int i = 0; i < n; i++){
        printf("%d ", p[i]);
    }
    puts("");
    */
    int flag = 0, ans = x;
    int i;
    for(i = 0; i < n; ++i){
        if(p[i] == x){
            flag = 1;
            break;
        }
    }


    if(flag){
        int j = 1;
        while(1){
            if((x - j) != p[i - j]){
                ans = x - j;
                break;
            }
            if((x + j) != p[i + j]){
                ans = x + j;
                break;
            }
            j++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N,A[MAXN];

void Solve() {
	read(N);
	for(int i = 1 ; i <= N ; ++i) read(A[i]);
	int cnt = 0;
	for(int i = 1 ; i <= N ; ++i) {
		if(A[i] == i) {
			if(i == N) swap(A[i],A[i - 1]);
			else swap(A[i],A[i + 1]);
			++cnt;
		}
	}
	out(cnt);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 640
import copy

N, K = (int(i) for i in input().split())

G = [[] for i in range(N)]
E = []
for i in range(N-1):
    A, B = (int(i) for i in input().split())
    E.append((A-1, B-1))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

def DFS(u, n, G):
    q = [u]
    v = [0]*N
    d = [0]*N
    while q:
        u1 = q.pop()
        v[u1] = 1
        if d[u1] < n:
            for u2 in G[u1]:
                if not v[u2]:
                    d[u2] = d[u1] + 1
                    q.append(u2)
    return sum(v)

def DFS_E(u, uu, n, G):
    q = [u, uu]
    v = [0]*N
    d = [0]*N
    while q:
        u1 = q.pop()
        v[u1] = 1
        if d[u1] < n:
            for u2 in G[u1]:
                if not v[u2] and u2 != u:
                    d[u2] = d[u1] + 1
                    q.append(u2)
    return sum(v)


if K % 2 == 0:
    ans = 0
    for v in range(N):
        ans = max(ans, DFS(v, K//2, G))
    print(N-ans)
else:
    ans = 0
    for u, v in E:
        ans = max(ans, DFS_E(u,v,(K-1)//2,G))
    print(N-ans)


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


int main() {
  int a, b;
  cin >> a >> b;
  if(b == 1) {
    cout << 0 << endl;
    return 0;
  }
  if(a >= b) {
    cout << 1 << endl;
    return 0;
  }else {
    for (int i = 2; i <= 100; i++) {
      if(a + (a - 1) * (i - 1) >= b){
        cout << i << endl;
        break;
        return 0;
      }
    }
  }
  return 0;
}

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

int main(){
	// sengen
	long long a,b,x;
	// nyuryoku
	cin >> a >> b >> x;
	// keisan
	if(a%x == 0){
		cout << b/x-a/x+1;
	}else{
		cout << b/x-a/x;
	}
}

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

int main()
{
	int N;
	cin >> N;
	int t = N, c = 0;
	while (t > 0) {
		c += (t % 10);
		t /= 10;
	}
	if (N % c == 0) puts(" Yes ");
	else puts(" No ");
}


Measured memory_bytes: 3588
S = str(input())
T = str(input())

flg = False
ok = False


if S == T:
    print('Yes')
else:
    for i in range(0,len(S)-1):
        temp = S[-i-1:]
        ret = temp + S[:len(S)- i -1]
        
        if ret == T:
            flg = True
            break
        
    if flg == True:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9004
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

void pr(ll ans){
    cout1(ans)
    exit(0);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,a,b;
    cin>>n>>a>>b;
    
    if(a>b) pr(0);
    if(n==1){
        if(a==b) pr(1);
        else pr(0);
    }
    
    ll ans=(b-a)*(n-2)+1;
    pr(ans);
    
    
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  stack<char> st;
  rep(i, n) {
    if(s[i] == '0') {
      if(!st.empty() && st.top() == '1') st.pop();
      else st.push(s[i]);
    }
    else {
      if(!st.empty() && st.top() == '0') st.pop();
      else st.push(s[i]);
    }
  }
  int ans = n-SZ(st);
  cout << ans << endl;
}


Measured memory_bytes: 3764
N = int(input())
S = []
for n in range(N):
    S.append(input())
d={}
for s in S:
    s=s.split(" ")
    c=s[0]
    n=int(s[1])
    if c not in d:
        d[c]=[]
    d[c].append(n)

d_sorted=sorted(d.items(), key=lambda x:x[0])
for k in d_sorted:
    k[1].sort(reverse=True)
    for p in k[1]:
        key = k[0] + " " + str(p)
        print(S.index(key)+1)


Measured memory_bytes: 3064
S = input()
T = []
T.append("".join(S[0:2]))
T.append("".join(S[2:4]))
MM = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
if (T[0] in MM) and (T[1] in MM):
  print("AMBIGUOUS")
elif (T[0] in MM) and (T[1] not in MM):
  print("MMYY")
elif (T[0] not in MM) and (T[1] in MM):
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 3064
s = input()
if s == 'KIHBR':
    print('YES')
elif s == 'KIHBRA':
    print('YES')
elif s == 'KIHBAR':
    print('YES')
elif s == 'KIHBARA':
    print('YES')
elif s == 'KIHABR':
    print('YES')
elif s == 'KIHABRA':
    print('YES')
elif s == 'KIHABAR':
    print('YES')
elif s == 'KIHABARA':
    print('YES')
elif s == 'AKIHBR':
    print('YES')
elif s == 'AKIHBRA':
    print('YES')
elif s == 'AKIHBAR':
    print('YES')
elif s == 'AKIHBARA':
    print('YES')
elif s == 'AKIHABR':
    print('YES')
elif s == 'AKIHABRA':
    print('YES')
elif s == 'AKIHABAR':
    print('YES')
elif s == 'AKIHABARA':
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9088
using System;
class Program
 {
        static void Main(string[] args)
        {
    　　string a, b, c;
            a = Console.ReadLine(); //標準入力
            //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            //b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            //c = int.Parse(str[1]);
            //Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            //Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            //string a = "10B10";

            string result = "";
            int position = 0;
            for (int i = 0; i <a.Length ; i++)
            {
                string s1 = a.Substring(i, 1);
                //Console.Write(s1);
                
                if (s1 == "0" || s1 == "1")
                {
                    result += s1;
                    position++;
                }
                else
                {
                    if(position != 0)
                    {
                        result = result.Remove(position - 1);
                        position--;
                    }
                    
                }
                //Console.WriteLine(result);
            }
            Console.WriteLine(result);
        }
 }

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

ll N;
vector<pll> ranges;
void solve() {
    cin >> N;
    vll H(N);
    rep(i,N){
        cin >> H[i];
    }

    ll ans = 1;
    rng(i,1,N){
        bool ok = true;
        rep(j,i){
            if(H[j] > H[i]){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3660
import sys
input = sys.stdin.readline

N, K = map(int,input().split())
A = list(map(int, input().split()))
sumA = sum(A)

yakusu = []
for i in range(1,int(sumA**0.5)+1):
    if sumA%i==0:
        yakusu.append(i)
        if sumA//i!=i:
            yakusu.append(sumA//i)
yakusu.sort(reverse=True)

for x in yakusu:
    tmp = list(map(lambda y: y%x, A))
    tmp.sort()
    for i in range(N):
        minuscnt = sum(tmp[:i+1])
        pluscnt = x*(N-i-1)-sum(tmp[i+1:])
        if minuscnt%x == pluscnt%x and K >= max(minuscnt,pluscnt):
            print(x)
            sys.exit()


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a = INT()

if a == 0:
    print(0)
    exit()

ans = ''
while abs(a) > 0:
    # 小さいビットから見て行って、その時点の偶奇で値を特定していく
    if a % 2 == 1:
        # 今の末尾の桁は1だったので、その分を引く
        a -= 1
        ans += '1'
    else:
        ans += '0'
    # -2進数は-2で割れば桁を落とせる(10進数で割る10する感じ)
    a /= -2
print(ans[::-1])


Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int N; cin >> N;
    vector <int> a(N); rep(i,N) cin >> a[i];
    map<int,int> mp;
    ll ans = 0;
    for (int i = N - 1; 0 <= i; --i) {
        ans += mp[i+a[i]];
        ++mp[i-a[i]];
    }
    out(ans);
    
    
    
    
    return 0;
}






Measured memory_bytes: 20936
#include <iostream>

int main() {
    
    int W,H,x,y,r;
    
    std::cin >> W >> H >> x >> y >> r;
    if( (r <= x && x <= (W-r)) && (r <= y && y <= H-r)){
        std::cout << "Yes\n";
    } else std::cout << "No\n";
    
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[3 * n];
    REP(i,3 * n){
        cin >> a[i];
    }
    sort(a, a + 3 * n);
    reverse(a, a + 3 * n);
    ll ans = 0;
    REP(i,n){
        ans += a[i * 2 + 1];
    }
    cout << ans << endl;
    return 0;
}

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

#define maxn 2002
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 __y0
#define y1 __y1
#define x0 __x0
#define x1 __x1
#define next __next
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

int m, n, a[maxn][maxn], Left[maxn], Right[maxn], f[maxn][maxn];
vector<int> p;
stack<int> st;

int solve(const vector<int> &p) {
    while (st.sz()) st.pop();
    REP(i, p.sz()) {
        while (st.sz() && p[st.top()]>=p[i]) st.pop();
        if (st.sz()) Left[i] = st.top();
        else Left[i] = -1;
        st.push(i);
    }
    while (st.sz()) st.pop();
    REPD(i, p.sz()) {
        while (st.sz() && p[st.top()]>=p[i]) st.pop();
        if (st.sz()) Right[i] = st.top();
        else Right[i] = p.sz();
        st.push(i);
    }
    int res = 0;
    REP(i, p.sz()) {
        res = max(res, (Right[i]-Left[i])*p[i]);
    }
    return res;
}

int main() {
    //freopen("fliprect.inp", "r", stdin);
    //freopen("fliprect.ans", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> m >> n;
    FOR(i, 1, m) FOR(j, 1, n) {
        char x; cin >> x;
        a[i][j] = (x=='#' ? 1 : 0);
    }
    FOR(j, 2, n) f[1][j] = 1;
    FOR(i, 2, m) {
        FOR(j, 2, n) {
            if ((a[i][j]+a[i-1][j]+a[i][j-1]+a[i-1][j-1])%2==0) {
                f[i][j] = f[i-1][j]+1;
            }
            else f[i][j] = 1;
        }
    }
    int res = max(m, n);
    FOR(i, 2, m) {
        p.clear();
        FOR(j, 2, n) {
            p.push_back(f[i][j]);
        }
        res = max(res, solve(p));
    }
    cout << res;
}


Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

ll gcd(ll m, ll n){
  // 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd

ll lcm( ll m, ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

// a x + b y = gcd(a, b)
int extgcd(int a, int b, int &x, int &y) {
  int g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
int invMod(int a, int m) {
  int x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;
  else                         return 0; // unsolvable
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  string S,T;
  ll ans=lcm(N,M);
  cin >> S >> T;
  for(int i=0;i<gcd(N,M);i++){
    if(S[i*ans/M]!=T[i*ans/N]){
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

static const int dy[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
static const int dx[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
int H, W, N;
map<pair<int, int>, int> G;
i64 A[10];


int main()
{
	scanf("%d%d%d", &H, &W, &N);
	for (int i = 0; i < N; i++)
	{
		int y, x;
		scanf("%d%d", &y, &x);
		for (int j = 0; j < 9; j++)
		{
			int ty = y + dy[j];
			int tx = x + dx[j];
			if(ty <= 1 || tx <= 1 || ty >= H || tx >= W) continue;
			pair<int, int> p = { ty,tx };
			if (G.end() == G.find(p)) G.insert({ p,1 });
			else G[p]++;
		}
	}
	A[0] = (i64)(H - 2)*(W - 2) - G.size();
	for (auto a : G)
	{
		A[a.second]++;
	}
	for (int i = 0; i < 10; i++)
	{
		printf("%lld\n", A[i]);
	}

    return 0;
}



Measured memory_bytes: 56448
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,a,b,c1=0,c2=0,c3=0,p;
    cin>>n>>a>>b;
    rep(i,0,n)
    {
    	cin>>p;
    	if(p<=a)
    		c1++;
    	else if(p<=b)
    		c2++;
    	else
    		c3++;
    }
    cout<<min({c1,c2,c3});
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n;
struct node
{
    int x, y;
    int id;
} town[maxn];
struct edge
{
    int st, ed;
    int cost;
} e[maxn*4];
int fa[maxn];
bool cmp1 (const node &a, const node &b)
{
    return a.x < b.x;
}
bool cmp2 (const node &a, const node &b)
{
    return a.y < b.y;
}
bool cmp3 (const edge &a, const edge &b)
{
    return a.cost < b.cost;
}
int Find (int x)
{
    if (fa[x] != x)
        fa[x] = Find (fa[x]);
    return fa[x];
}
int main()
{
	cin >> n;
    for (int i=1; i<=n; i++)
    {
        cin >> town[i].x >> town[i].y;
        town[i].id = i;
    }
    int k=0;
    sort (town+1, town+1+n, cmp1);
    for(int i=1; i<n; i++)
    {
        e[k].st = town[i].id;
        e[k].ed = town[i+1].id;
        e[k++].cost = abs (town[i].x-town[i+1].x);
    }
    sort (town+1,town+1+n,cmp2);
    for (int i=1;i<=n-1;i++)
    {
        e[k].st = town[i].id;
        e[k].ed = town[i+1].id;
        e[k++].cost = abs (town[i].y-town[i+1].y);
    }
    sort (e, e+k, cmp3);
    for (int i=1; i<=n; i++) fa[i]=i;
    int ans = 0;
    for (int i=0;i<k;i++)
    {
        int a = Find(e[i].st), b = Find(e[i].ed);
        if (a != b)
        {
            ans += e[i].cost;
            fa[b] = a;
        }
    }
    cout << ans;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int ans=0;
    for(char c:s){
        ans+=(c-'0');
    }
    if(ans%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
const int di[]={0,-1,0,1};
const int dj[]={-1,0,1,0};
int main(){
  ll h,w;
  cin>>h>>w;
  vstr ta(h);
  ll ans=0;
  rep(i,h) cin>>ta[i];
  rep(si,h) rep(sj,w){
    if(ta[si][sj]=='#') continue;
    vvll dist(h,vll(w,INF));
    queue<pll> q;
    auto jj = [&](int i, int j, int x) {
      if (dist[i][j] != INF) return;
      dist[i][j] = x;
      q.push(pll(i,j)); // .emplace(i,j)
    };
    jj(si,sj,0);
    while(!q.empty()){
      ll i=q.front().F;
      ll j=q.front().S;
      q.pop();
      rep(dir,4){
        ll ni=i+di[dir],nj=j+dj[dir];
        if(ni<0||ni>=h||nj<0||nj>=w) continue;
        if(ta[ni][nj]=='#') continue;
        jj(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w){
      if(ta[i][j]=='#') continue;
      ans=max(ans,dist[i][j]);
    }
  }
  COUT(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int m = 1e9+7;
    int h, w;
    cin >> h >> w;
    char grid[h][w];
    vector<vector<int>>dp(h, vector<int>(w,0));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> grid[i][j];
            if(grid[i][j] == '#'){
                dp[i][j] = -1;
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(dp[i][j] == -1) continue;
            else if (i == 0 && j == 0) dp[i][j] = 1;
            else {
                if( i-1 >= 0 && dp[i-1][j] != -1)
                dp[i][j] += dp[i-1][j];
                if( j-1 >= 0 && dp[i][j-1] != -1)
                dp[i][j] += dp[i][j-1];
            }
            dp[i][j] = dp[i][j]%m;
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 5120
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {

    def read:Unit = {
      var n = readLine.split(" ").map(_.toInt)

      if( n(0) != 0 || n(1) != 0) {
        (1 to n(0)).foreach(s=> {
          (1 to n(1)).foreach(t=> {
            if((s+t)%2==0)
              print("#")
            else
              print(".")
          })
          println()
        })
        println()
        read
      }
    }
    read
  }
}

Measured memory_bytes: 56896
s=input().split()
n=int(s[0])
x=int(s[1])
j=[]
d=input().split()
for i in range(n):
    j.append(int(d[i]))
d= 0
i=0
p=0
while d<=x:
    p+=1
    if i<=len(j)-1:
        d+=j[i]
    else:
        break
    i+=1
print(p)


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

int main()
{
	using namespace std;
	int a, b;
	cin >> a;cin >> b;
	if (a*b > a + b && a - b < a * b) {
		cout << a * b;
	}
	else if (a + b > a - b && a + b > a* b) {
		cout << a + b;
	}
	else {
		cout << a - b;
	}
	
}

Measured memory_bytes: 256
#include <stdio.h>



int main(void){
    int NUM[10000];
    int n,m,i;
    int a = 0;

    scanf("%d",&n);


    //スキャン
    for(i = 0; i<n; i=i+1){
        scanf("%d",&NUM[i]);
    }
    for (m =0;m<n;m=m+1){

        while(NUM[m] % 2 == 0){
            NUM[m] = NUM[m]/2;
            a = a+1;
        }

    }

printf("%d",a);

    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string num; cin >> num;
	int sum = 0;
	int n = num.size();
	for (int i = 0 ; i < n; ++i) {
		int temp = num[i] - '0';
		sum += temp;
	}


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

	return 0;

}

Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int n;
	vector<int> p;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int _p;
		cin >> _p;
		p.push_back(_p);
	}

	int count = 0;
	for (int i = 1; i < n - 1; ++i) {

		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1])) {
			++count;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

//10^9 + 7
#define yojo 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 200001

void Main() {
  //自動整形防止用コメント
  int n;
  cin >> n;
  vector<int> d(n, 0);
  for (int i = 0; i < n; i++)
  {
    cin >> d[i];
  }

  sort(all(d));
  
  
  std::cout << d[(n / 2)] - d[(n / 2) - 1] << std::endl;
  
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define long long long
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;


signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  int N, H, W;
  int ans = 0;
  cin >> N >> H >> W;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    if (a >= H && b >= W) ++ans;
  }

  cout << ans  << endl;

  return 0;
}



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

using namespace std;

int main(){
	int x,y;
	cin>>x>>y;

	int total=0;

	if(x==1){
		total+=300000;
	}else if(x==2){
		total+=200000;
	}else if(x==3){
		total+=100000;
	}

	if(y==1){
		total+=300000;
	}else if(y==2){
		total+=200000;
	}else if(y==3){
		total+=100000;
	}

	if(x==1&&y==1){
		total+=400000;
	}
	

  	cout<<total<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    int n,k;
    cin >> n >> k;
    cout << (n+k-3)/(k-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
template <class T>
T gcd(T a, T b) {

    if(b == 0){
        return a;
    }
    else{
        gcd(b, a%b);
    }
}
int main() {

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

    int ans = a[0];
    rep(i, n){
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
def main():
    n = int(input())
    h=[int(i) for i in input().split()]
    min_h = min(h)
    h_sub = [int(i)-min_h for i in h]
    res = min_h
    i = 0
    while max(h_sub)!=0:
        if(h_sub[i]>0):
            res+=1
            j = i
            while(j<n and h_sub[j]!=0):
                h_sub[j]-=1
                j+=1
        else:
            i+=1
        if(i>=n):
            break
    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9136
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n,a,b;
    string ans = "No";
    int count = 0;
    cin >> n;
    rep(i,n){
        cin >> a >>b ;
        if(a==b){
            count ++;
        }else{
            count = 0;
        }
        if(count == 3){
            ans = "Yes";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3036
N,K=map(int,input().split())
d=[]
A=[]
B=[]
for i in range(1,K+1):
    d=int(input())
    A=list(map(int,input().split()))
    B=B+A

C=set(list(range(1,N+1)))
print(len(C-set(B)))

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

    int now = 1;
    int cnt = 0;
    bool used[100005]; memset(used,0,sizeof(used));
    while(true){
        if(now == 2){
            cout << cnt << endl;
            return 0;
        }
        if(used[now]) break;
        used[now] = true;
        cnt++;
        now = a[now];
    }

    cout << -1 << endl;

    return 0;

}

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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<ll> A, B;
map<ll,ll> M;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
        B.push_back(a);
    }
    sort(B.begin(), B.end());
    for(int i=0;i<N;i++) {
        M[B[i]] = i;
    }
    for(int i=0;i<N;i++) {
        if((i-M[A[i]])%2) {
            ans++;
            //cout << A[i] << " " << M[A[i]] << endl;
        }
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 11144
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int paintedRows = sc.nextInt();
        int paintedCols = sc.nextInt();

        System.out.println((h-paintedRows) * (w-paintedCols));
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
#define vl vector<ll>

vector<ll> dx = {-1, 1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

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



template< typename T >
struct edge {
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
/*
WeightedGraph<ll> g(V);
g[a].emplace_back(b, c);
*/
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main()
{
	ll N;
	cin >> N;

	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	vector<ll> I(N);
	REP(i, N) {
		I[i] = i + A[i];
	}

	vector<ll> J(N);
	REP(j, N) {
		J[j] = j - A[j];
	}

	map<ll, ll> sumj;
	REP(i, N) {
		if (J[i] >= 0)
			sumj[J[i]]++;
	}
	ll ans = 0;
	map<ll, ll> tmpj;
	REP(i, N) {
		if (J[i] >= 0) {
			tmpj[J[i]]++;
		}
		ans += max(0LL, sumj[I[i]] - tmpj[I[i]]);
	}
	PRINT(ans);
	return 0;
}


Measured memory_bytes: 35516
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ul=unsigned long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
template<class C>
struct rev{
    C &c;
    explicit rev(C &x):c(x){}
    auto begin(){return c.rbegin();}
    auto end(){return c.rend();}
};

void solve(){
    int n;
    cin>>n;
    vector<ul> a(n);
    set<ul> base;
    for(auto&i:a) cin>>i;
    string s;
    cin>>s;
    ifr(i,n){
        for(auto&v:rev(base)) chmin(a[i],a[i]^v);
        if(a[i]){
            if(s[i]=='0') base.insert(a[i]);
            else{
                cout<<1<<'\n';
                return;
            }
        }
    }
    cout<<0<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    fr(i,t) solve();
}

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

int su[200005];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&su[i]);
    int ss = 0, ee = 0;
    int sum = 0;
    long long ans = 0;
    while(ss < n){
        if(ee == n){
               // printf("%d %d\n", ss, ee);
            ans += (ee-ss);
            sum -= su[ss];
            ss++;
        }else{
            if((sum + su[ee]) == (sum ^ su[ee])){
                sum += su[ee];
        ee++;
            }else{
                //printf("%d %d %d\n", ss, ee, sum);
                ans += (ee-ss);
                sum -= su[ss];
                ss++;
            }
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LazySegTree_RSQ seg = new LazySegTree_RSQ(n);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int a = sc.nextInt();
            int s = sc.nextInt() -1;
            int t = sc.nextInt();
            if(a == 0){
                int x = sc.nextInt();
                seg.add(s, t, x, 0, 0, seg.size);
            }else{
                sb.append(seg.sum(s, t, 0, 0, seg.size) + "\n");
            }
        }
        System.out.print(sb.toString());
        sc.close();

    }

}

class LazySegTree_RSQ {

    public int n;
    public int size;
    /**
     * 要素全体を含むノードのindex：0.
     * k番目(0-indexed)の要素のindex：k + size - 1
     * ノードkの親要素のindex：(k - 1) / 2.
     * ノードkの子要素のうち左側のindex：k*2+1.
     * ノードkの子要素のうち右側のindex：k*2+2.
     */
    public long[] data;
    public long[] lazy;

    /**
     * コンストラクタ.
     * @param n 要素数
     */
    public LazySegTree_RSQ(int n){
        this.n = n;
        size = 1;
        while(size < n) size *= 2;
        data = new long[size*2];
        lazy = new long[size*2];
    }

    /**
     * 指定したノードが遅延評価待ちの値を保持している場合、
     * 自ノードに反映し、子ノードの遅延評価待ちとして設定する。
     * @param k 自ノードのindex
     * @param l 自ノードの対象区間左側（含む）
     * @param r 自ノードの対象区間右側（含まない）
     */
    public void eval(int k, int l, int r){
        if(lazy[k] != 0){
            data[k] += lazy[k];
            if(1 < r - l){
                lazy[2*k+1]  += lazy[k] / 2;
                lazy[2*k+2]  += lazy[k] / 2;
            }
            lazy[k] = 0L;
        }
    }

    /**
     * 区間[a, b)での○○を求めます.
     * 最初に呼ぶ際は、query(a, b, x, 0, 0, size)として呼ぶ.
     * @param a 求める区間の下限（含む）
     * @param b 求める区間の上限（含まない）
     * @param k 確認するノードのindex
     * @param l 確認するノードの下限（含む）
     * @param r 確認するノードの上限（含まない）
     * @return 区間[a, b)での○○
     */
    public void add(int a, int b, int x, int k, int l, int r){
        eval(k, l, r);

        // 区間外
        if(b <= l || r <= a) return;

        // 完全に含む
        if(a <= l && r <= b){
            lazy[k] += (long)(r - l) * x;
            eval(k, l, r);
            return;
        }

        // それ以外
        add(a, b, x, 2*k+1, l, (l+r)/2);
        add(a, b, x, 2*k+2, (l+r)/2, r);
        data[k] = data[2*k+1] + data[2*k+2];
    }

    /**
     * 区間[a, b)の和を求めます.
     * 最初に呼ぶ際は、query(a, b, 0, 0, size)として呼ぶ.
     * @param a 求める区間の下限（含む）
     * @param b 求める区間の上限（含まない）
     * @param k 確認するノードのindex
     * @param l 確認するノードの下限（含む）
     * @param r 確認するノードの上限（含まない）
     * @return 区間[a, b)の和
     */
    public long sum(int a, int b, int k, int l, int r){
        // 区間外
        if(b <= l || r <= a) return 0;
        eval(k, l, r);
        // 完全に含む
        if(a <= l && r <= b) return data[k];
        // それ以外
        long vl = sum(a, b, 2*k+1, l, (l+r)/2);
        long vr = sum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
}



Measured memory_bytes: 118864