akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:128777216")

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>

#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>

#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>

#include <memory.h>
#include <cassert>
#include <time.h>
#include <functional>

using namespace std;

#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;

const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;

#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  } 
#define dbg( ... ) {  } 
#endif

void prepare(string s) {
#ifdef MY_DEBUG
  freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#endif
}

int N, D, X, a[105];

void read() {
  scanf("%d %d %d", &N, &D, &X);
  forn(i, N) scanf("%d", &a[i]);
}

void solve() {
  int result = X;
  forn(i, N) {
    for (int j = 1; j <= D; j += a[i]) {
      ++result;
    }
  }
  printf("%d\n", result);
}

int main() {
  prepare("");

  read();
  solve();
  dbg("Clock = %.3f\n", clock() / (double)CLOCKS_PER_SEC);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int cnt = 0;
    int n;
    cin >> n;
    int d1, d2;
    for (int i=0; i<n; i++) {
        cin >> d1 >> d2;
        if (d1 == d2) {
            cnt++;
            if (cnt == 3) {
                cout << "Yes" << endl;
                return 0;
            }
        } else {
            cnt = 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define np(str) next_permutation(str.begin(),str.end())
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7;
ll INF = 1e16;
ll n, m;

int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll  i, j, t, k, x, y, z,  N;
	string s;
	cin >> s;
	ll cnt = 0;
	ll ans = 0;
	rep(i, 3) {
		if (s[i] == 'R') {
			cnt++;
		}
		else {
			ans = max(ans, cnt);
			cnt = 0;
		}
	}
	ans = max(ans, cnt);
	cout << ans;



	return 0;
}





Measured memory_bytes: 3644
n,x=map(int,input().split())
hoge=list(map(int,input().split()))
huga=[0]
for i in range(len(hoge)):
  huga.append(huga[-1]+hoge[i])
ans=0
for i in range(len(huga)):
  if(huga[i]<=x):
    ans+=1
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int H, W;
string C[110];

signed main()
{
    cin >> H >> W;
    REP(i,H) cin >> C[i];
    
    REP(i,H) {
        cout << C[i] << endl;
        cout << C[i] << endl;
    }
}


Measured memory_bytes: 256
N,C=map(int,input().split())
D=[list(map(int,input().split())) for _ in range(C)]
G=[list(map(int,input().split())) for _ in range(N)]
C0=[0]*(C+1)
C1=[0]*(C+1)
C2=[0]*(C+1)

for x in range(N):
    for y in range(N):
        if (x+y+2)%3==0: C0[G[x][y]]+=1
        elif (x+y+2)%3==1: C1[G[x][y]]+=1
        elif (x+y+2)%3==2: C2[G[x][y]]+=1

miniwa=250000000
for c0 in range(1,C+1):
    for c1 in range(1,C+1):
        for c2 in range(1,C+1):
            if (c1-c0)*(c2-c1)*(c0-c2)==0: continue
            iwa=0
            for i in range(1,C+1):
                iwa+=(D[i-1][c0-1]*C0[i]+D[i-1][c1-1]*C1[i]+D[i-1][c2-1]*C2[i])
            miniwa=min(miniwa,iwa)
print(miniwa)

Measured memory_bytes: 45916
var
  a,l,i,p:longint;
  s:string;
begin
  readln(s);
  l:=pos(' ',s);
  delete(s,l,1);
  val(s,a,p);
  if trunc(sqrt(a))=sqrt(a) then writeln('Yes')
                            else writeln('No');
end.

Measured memory_bytes: 128
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	int n;
	unsigned long long x=0;
	cin>>n;
	vector<unsigned long long> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		x^=a[i];
	}
	for(int i=0;i<n;i++)
	{
		cout<<(x^a[i])<<'\n';
	}
}


Measured memory_bytes: 4764
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
  string a,z;
  cin>>a>>z;
  sort(a.begin(),a.end());
  sort(z.begin(),z.end());
  reverse(z.begin(),z.end());
  if(a<z)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = [0] * n
for i in range(1, n):
    for j in range(1, k + 1):
        if j == 1:
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])
        
        if i - j < 0:
            continue
        
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[n - 1])

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

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	for (int i = 0; i < N; i++) {
		cin >> P.at(i);
	}
	
	int cnt = 0;
	int minP = 2 * 10e6;
	for (int i = 0; i < N; i++) {
		minP = min(minP, P.at(i));
		if (minP == P.at(i)) {
			cnt++;
		}
	}

	cout << cnt << endl;


}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N, K;
  vector<llong> A;

  cin >> N >> K;
  A.resize(N);
  for (auto &in: A) {
    cin >> in;
  }

  llong before = 0;
  llong now = 0;
  for (int i = K; i < N; i++) {
    if (A[i - K] < A[i]) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 4836
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		int[] a=new int[n];
		long mod=1000000007;
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		long count=0;
		for(int i=0; i<n; i++){
			int aa=a[i];
			for(int j=i+1; j<n; j++){
				if(aa>a[j]){
					count++;
				}
			}
		}
		Arrays.sort(a);
		int min=a[0];
		int pp=0;
		long uu=0;
		int cc=1;
		for(int i=1; i<n; i++){
			if(min==a[i]){
				uu+=pp;
				cc++;
			}else{
				min=a[i];
				pp=cc;
				cc++;
				uu+=pp;
			}
		}
		long hhh=(((k-1)*k)/2)%mod;
		System.out.println((((k*count)%mod)+((hhh)*uu)%mod)%mod);
	}
}



Measured memory_bytes: 26204
from collections import deque
S=input()
queue=deque()
lst=[]
lst.append([0,0])
for i in range(0,len(S)):
    l=len(lst)
    for _ in range(l):
        x,y=lst.pop(0)
        lst.append([x,y*10+int(S[i])])#plus
        lst.append([x+y*10+int(S[i]),0])
l=len(lst)
for _ in range(l):
    x,y=lst.pop(0)
    lst.append(x+y)
print(int(sum(lst)/2))


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

using namespace std;

#define int long long
int n;
vector<int> g[110];
int an1 = 100, an2;
int d[110];
int a = -1, b = -1;

void dfs1(int v, int par, int h){
    for(auto to: g[v]){
        if(a == v && b == to || a == to && b == v) continue;
        if(to != par){
            dfs1(to, v, h + 1);
        }
    }
    d[h + 1] = max(d[h + 1], (int)g[v].size() - (v != par));
}

main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int from, to;
        cin >> from >> to;
        g[from - 1].push_back(to - 1);
        g[to - 1].push_back(from - 1);
    }
    for(int i = 0; i < n; i++){
        memset(d, 0, sizeof(d));
        dfs1(i, i, 0);
        int curh = 0;
        for(int j = 1; ; j++){
            if(d[j] == 0){
                curh = j;
                break;
            }
        }
        int leaves = 1;
        for(int j = 1; j < curh; j++){
            leaves *= d[j];
        }
        if(curh < an1){
            an1 = curh;
            an2 = leaves;
        }
        else if(curh == an1) an2 = min(an2, leaves);
    }
    for(int i = 0; i < n; i++){
        int k = g[i].size();
        for(int j = 0; j < k; j++){
            memset(d, 0, sizeof(d));
            int u = g[i][j];
            a = i, b = u;
            g[n].push_back(a);
            g[n].push_back(b);
            dfs1(n, n, 0);
            g[n].clear();
            int curh = 0;
            for(int j = 1; ; j++){
                if(d[j] == 0){
                    curh = j;
                    break;
                }
            }
            int leaves = 1;
            for(int j = 1; j < curh; j++){
                leaves *= d[j];
            }
            if(curh-1 < an1){
                an1 = curh-1;
                an2 = leaves;
            }
            else if(curh-1 == an1) an2 = min(an2, leaves);
        }
    }
    cout << an1 << ' ' << an2 << endl;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin>>N;
	cout<<180*(N-2)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstring>

using namespace std;
const int Max_N(305);
const int Max_D(200050);
typedef pair<int, int> pil;
#define fi first
#define se second
#define mp make_pair

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

int N, D1, D2, Sqrt[Max_D], C1[Max_N << 1][Max_N << 1], C2[Max_N << 1][Max_N << 1];
const int kx[] = {+1, -1, +1, -1};
const int ky[] = {+1, +1, -1, -1};
vector<pil> G1[Max_N << 1][Max_N << 1], G2[Max_N << 1][Max_N << 1];
vector<pil> All[4];

void dfs1(int x, int y)
{
	for (int i = 0, _x, _y;i < G1[x][y].size();++i)
		if (!C1[_x = G1[x][y][i].fi][_y = G1[x][y][i].se])
			C1[_x][_y] = 3 - C1[x][y], dfs1(_x, _y);
}

void dfs2(int x, int y)
{
	for (int i = 0, _x, _y;i < G2[x][y].size();++i)
		if (!C2[_x = G2[x][y][i].fi][_y = G2[x][y][i].se])
			C2[_x][_y] = 3 - C2[x][y], dfs2(_x, _y);
}

int main()
{
	gi(N), gi(D1), gi(D2);
	memset(Sqrt, -1, sizeof(Sqrt));
	for (int x = 0;x * x <= D1 || x * x <= D2;++x)
		Sqrt[x * x] = x;
	for (int x = 0;x < N + N;++x)
		for (int y = 0;y < N + N;++y)
		{
			for (int dx = 0, dy;dx * dx <= D1;++dx)
				if ((dy = Sqrt[D1 - dx * dx]) != -1 && (dx != 0 || dy != 0))
					for (int k = 0, _x, _y;k < 4;++k)
					{
						_x = x + kx[k] * dx, _y = y + ky[k] * dy;
						if (0 <= _x && _x < N + N && 0 <= _y && _y < N + N)
							G1[x][y].push_back(mp(_x, _y));
					}
			for (int dx = 0, dy;dx * dx <= D2;++dx)
			{
				if ((dy = Sqrt[D2 - dx * dx]) != -1 && (dx != 0 || dy != 0))
					for (int k = 0, _x, _y;k < 4;++k)
					{
						_x = x + kx[k] * dx, _y = y + ky[k] * dy;
						if (0 <= _x && _x < N + N && 0 <= _y && _y < N + N)
							G2[x][y].push_back(mp(_x, _y));
					}
			}
		}
	for (int x = 0;x < N + N;++x)
		for (int y = 0;y < N + N;++y)
		{
			if (!C1[x][y])
				C1[x][y] = 1, dfs1(x, y);
			if (!C2[x][y])
				C2[x][y] = 1, dfs2(x, y);
			All[(C1[x][y] - 1) * 2 + (C2[x][y] - 1)].push_back(mp(x, y));
		}
	for (int d = 0;d < 4;++d)
		if (All[d].size() >= N * N)
		{
			for (int i = 0;i < N * N;++i)
				print(All[d][i].fi), putc(' '), print(All[d][i].se), putc('\n');
			break;
		}
	return 0;
}

Measured memory_bytes: 185984
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as UV

r2 [a,b]=(a,b)
main = do
    [n,w]<-map read.words<$>getLine::IO [Int]
    wvs<-replicateM n $ r2.unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f n w wvs

f n w = (UV.! w).foldl' p (UV.replicate (w+1) 0) where
    jv = UV.enumFromTo 0 w
    p v0 (wi,vi) = UV.map q jv where
        q j|j<wi = v0 UV.! j |j>=wi = max (v0 UV.! j) (vi + v0 UV.! (j-wi))

Measured memory_bytes: 6960
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
    long[] dp = new long[n+1];
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);

    dp[1] = 0;
    dp[2] = Math.Abs(nums[1]-nums[0]);

    for(int i = 3; i <= n; i++)
    {
      dp[i] = Math.Min(dp[i-2]+Math.Abs(nums[i-1]-nums[i-3]),
        dp[i-1]+Math.Abs(nums[i-1]-nums[i-2]));
    }
		
		Console.WriteLine(dp[n]);
	}
}

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

int main() {
    int count=0;
	string str;
	cin>>str;
	for(int i=0;i<str.size();i++){
	    if(str[i]!=str[(str.size()-1-i)]){
	        count++;
	    }
	}
	cout<<count/2;
	return 0;
}

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

using namespace std;


int main(int argc, char** argv) {
    int x = 0;
    int v[3] = {0};
    
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    
    for (int i = 0; i < 2; i++) {
        int j = i;
        for (int k = i+1; k < 3; k++) {
            if(v[j] > v[k]) {
                j = k;
            }
        }
        int temp = v[i];
        v[i] = v[j];
        v[j] = temp;
    }
    
    for (int i = 0; i < 2; i++) {
        cout << v[i] << " ";
    }
    
    cout << v[2] << endl;
    
    return 0;
}

Measured memory_bytes: 1160
from itertools import combinations
import math
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


N,M,K = map(int,input().split())
ans = 0
mod = 10**9 +7
by = cmb(N*M-2,K-2,mod)

#まずは、X軸の総和を求める。
for i in range(N):
    for j in range(M):
        cnt = M-j-1
        add = (((j+1)+(M-1))*cnt//2 - j*cnt)*N%mod
        ans += add*by%mod
        ans %= mod

for i in range(M):
    for j in range(N):
        cnt = N-j-1
        add = (((j+1)+(N-1))*cnt//2 - j*cnt)*M%mod
        ans += add*by%mod
        ans %= mod


print(ans)

Measured memory_bytes: 213388
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    int n;
    string s,t;
    cin >> n >> s >> t;
    rep(i,n) cout << s[i] << t[i];
    cout << endl;
}

Measured memory_bytes: 256
// ALDS1_4_B.cpp
// Binary Search

#include <iostream>
#include <vector>
using namespace std;

int is_in(vector<int>& S, int t)
{
    int lo = 0;
    int hi = S.size();
    int res = 0;
    while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        if (S[mid] == t) {
            res = 1;
            break;
        }
        else if (S[mid] < t) {
            lo = mid + 1;
        }
        else {
            hi = mid - 1;
        }
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> S(n);
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }

    int q;
    cin >> q;
    vector<int> T(q);
    for (int i = 0; i < q; i++) {
        cin >> T[i];
    }
    int C = 0;
    for (int i = 0; i < q; i++) {
        C += is_in(S, T[i]);
    }
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 21 + 5;
const int SZ = 2100000;

int n;
int a[N][N];
int dp[SZ];
int all_set;

int solve(int mask)
{
	if (mask == all_set)
		return 1;

	int &memo = dp[mask];
	if (memo != -1)
		return memo;

	int idx = 1;
	for (int i = 1; i <= mask; i *= 2)
		if (mask & i)
			idx++;

	memo = 0;
	for (int i = 1; i <= n; i++)
	{
		int temp = 1 << (i - 1);
		// cerr << "temp : " << bitset<32>(temp) << " mask : " << mask << "\n";
		if (a[idx][i] == 1 && (mask & temp) == 0)
		{
			// cerr << "entry\n";
			mask ^= temp;
			memo += solve(mask);
			memo %= mod;
			mask ^= temp;
		}
	}
	// cerr << "idx : " << idx << " memo : " << memo << "\n";
	return memo;
}

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	memset(dp, -1, sizeof dp);

	cin >> n;
	all_set = (1 << n) - 1;

	forl(i, 1, n + 1)
	{
		forl(j, 1, n + 1)
		{
			cin >> a[i][j];
		}
	}

	int mask = 0;
	int ans = solve(mask);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 8448
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;
#define lli long ling int;

int main()
{
    int N, M, sum=0;
    scanf("%d %d", &N, &M);

    int A[N];
    for (int i=0; i < N; i++) {
        scanf("%d", &A[i]);
        sum += A[i];
    }

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i]*4*M >= sum) {
            count+=1;
        }
    }
    if (count >= M)
        printf("Yes\n");
    else
    {
        printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
char D[1002][1002]={};
int main() {
	int M,N;
	int R=0;
	char E[2][2];
	char b[4]={'S','J','O','I'};
	cin>>M>>N;
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			cin>>D[i][j];
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			cin>>E[i][j];
		}
	}

	int a=0;
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			if(D[i][j]==E[0][0]&&D[i][j+1]==E[0][1]&&D[i+1][j]==E[1][0]&&D[i+1][j+1]==E[1][1]){
				a+=1;
			}
		}
	}

	int c[4];
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			b[0]=D[i][j];
			for(int k=0;k<4;k++){
				D[i][j]=b[k];
				c[k]=0;
				if(D[i][j]==E[0][0]&&D[i][j+1]==E[0][1]&&D[i+1][j]==E[1][0]&&D[i+1][j+1]==E[1][1])c[k]+=1;
				if(D[i][j-1]==E[0][0]&&D[i][j]==E[0][1]&&D[i+1][j-1]==E[1][0]&&D[i+1][j]==E[1][1])c[k]+=1;
				if(D[i-1][j]==E[0][0]&&D[i-1][j+1]==E[0][1]&&D[i][j]==E[1][0]&&D[i][j+1]==E[1][1])c[k]+=1;
				if(D[i-1][j-1]==E[0][0]&&D[i-1][j]==E[0][1]&&D[i][j-1]==E[1][0]&&D[i][j]==E[1][1])c[k]+=1;
			}
			D[i][j]=b[0];
			R=max(R,a+c[1]-c[0]);
			R=max(R,a+c[2]-c[0]);
			R=max(R,a+c[3]-c[0]);

		}
	}

	cout<<R<<endl;
	return 0;
}

Measured memory_bytes: 4072
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n, a;
  cin >> n >> a;
  cout << n*n - a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
const int MOD = 1000000007;

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

  rep(i, n){
    if((n+i) % 2 == 0 && a[i] != i+1){
      cout << 0 << endl;
      return 0;
    }
    else if((n+i) % 2 == 1 && a[i] != i){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i, n/2){
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
// Tenshi ni Fureta yo!

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef pair<int, int> pii;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline int chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline int chkmax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template<typename T> inline T sqr(const T &val) { return val * val; }

namespace fastIO
{
	const int MAX_BUFFER_SIZE = 1 << 16;

	char buffer[MAX_BUFFER_SIZE], *cur = buffer, *ed = buffer;

	inline char getc() { return *(cur == ed ? ed = buffer + fread(buffer, 1, MAX_BUFFER_SIZE, stdin), cur = buffer : cur)++; }
}
using fastIO::getc;

template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getc());
	for(; !isdigit(ch); ch = getc()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getc()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

// END tpl.

int A, B, L, R;

inline void input()
{
	A = read<int>(), B = read<int>(), L = read<int>(), R = read<int>();
}

inline void solve()
{
	if(A >= B)
	{
		if(A % (B + 1) == 0)
		{
			int N = A / (B + 1);
			for(int i = L; i <= R; ++i) putchar(i % (N + 1) == 0 ? 'B' : 'A');
			puts("");
		}
		else
		{
			int N = A / (B + 1) + 1, T = (A + B) / (N + 1);

			int M = N == 1 ? T : ((LL) N * A - B + N - 1) / ((LL) N * N - 1);
			int K = (B - M) / N;

			for(int i = L; i <= R; ++i)
			{
				if(i <= M * (N + 1)) putchar(i % (N + 1) == 0 ? 'B' : 'A');
				else if(A + B - i + 1 <= K * (N + 1)) putchar((A + B - i + 1) % (N + 1) == 0 ? 'A' : 'B');
				else
				{
					int t = i - M * (N + 1), A0 = A - M * N - K;
					putchar(t <= A0 ? 'A' : 'B');
				}
			}
			puts("");
		}
	}
	else
	{
		if(B % (A + 1) == 0)
		{
			int N = B / (A + 1);
			for(int i = L; i <= R; ++i) putchar(i % (N + 1) == 0 ? 'A' : 'B');
			puts("");
		}
		else
		{
			L = A + B - L + 1;
			R = A + B - R + 1;
			swap(A, B);

			int N = A / (B + 1) + 1, T = (A + B) / (N + 1);

			int M = N == 1 ? T : ((LL) N * A - B + N - 1) / ((LL) N * N - 1);
			int K = (B - M) / N;

			for(int i = L; i >= R; --i)
			{
				if(i <= M * (N + 1)) putchar(i % (N + 1) == 0 ? 'A' : 'B');
				else if(A + B - i + 1 <= K * (N + 1)) putchar((A + B - i + 1) % (N + 1) == 0 ? 'B' : 'A');
				else
				{
					int t = i - M * (N + 1), A0 = A - M * N - K;
					putchar(t <= A0 ? 'B' : 'A');
				}
			}
			puts("");
		}
	}
}

int main()
{
#ifdef K_ON
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	for(int T = read<int>(); T--; )
	{
		input();
		solve();
	}

	return 0;
}




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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    // 0:M 1:A 2:R 3:C 4:H
    ll march[5] = {};
    rep(i, n) {
        string s; cin >> s;
        if(s[0] == 'M') march[0]++;
        else if(s[0] == 'A') march[1]++;
        else if(s[0] == 'R') march[2]++;
        else if(s[0] == 'C') march[3]++;
        else if(s[0] == 'H') march[4]++;
    }
    ll ans = 0;
    rep(i, 5) {
        REP(j, i+1, 5) {
            REP(k, j+1, 5) {
                ll tmp = march[i]*march[j]*march[k];
                ans += tmp;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return (x * y) // gcd(x, y)

c = (A - 1) // C
d = (A - 1) // D
cd = (A - 1) // lcm(C, D)

tmp1 = c + d - cd

c = B // C
d = B // D
cd = B // lcm(C, D)

tmp2 = c + d -cd

print((B - A + 1) - (tmp2 - tmp1))

Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef pair<int,int> P;

const int INF = 1e9;


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

	int n;
	cin >> n;

	int f[n][10];
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin >> f[i][j];
		}
	}

	int p[n][11];
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++){
			cin >> p[i][j];
		}
	}

	int c[n]={};
	int ans=-2 * INF;
	int tmp;
	for(int i=1;i<(1<<10);i++){	//O(10^3)
		tmp = 0;
		for(int j=0;j<10;j++){	//O(10)
			if(((i>>j) & 1) == 1){
				for(int k=0;k<n;k++){
					if(f[k][j] == 1){
						c[k]++;
						if(c[k] > 10) cout <<"ERRO\n";
					}
				}
			}
		}
		for(int j=0;j<n;j++){
			tmp += p[j][c[j]];
			c[j] = 0;
		}
		ans = max(ans,tmp);
	}
						


	cout << ans << "\n";

	return 0;
}

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

using namespace std;

int n, m, x[55];
vector<pair<int, int>> v[55];
long long dp[1 << 20];

bool dfs1(int a, int b, int c, int d) {
	if (a == c)
		return 1;
	for (auto& i : v[a])
		if (i.first != b && dfs1(i.first, a, c, d)) {
			x[i.second] ^= 1 << d;
			return 1;
		}
	return 0;
}

void dfs2(int a, int b) {
	
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		v[ta].emplace_back(tb, i);
		v[tb].emplace_back(ta, i);
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int ta, tb;
		scanf("%d%d", &ta, &tb);
		dfs1(ta, 0, tb, i);
	}
	dp[0] = 1;
	// for (int i = 1; i < n; i++) printf("x[%d]=%d\n", i, x[i]);
	for (int i = 1; i < n; i++)
		for (int j = (1 << m) - 1; j >= 0; j--)
			dp[j | x[i]] += dp[j];
	printf("%lld\n", dp[(1 << m) - 1]);
}

Measured memory_bytes: 8448
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;
int a[200005];
int main()
{
	int n,k;
	cin>>n>>k;
	unsigned long long sum=0,maxnum;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	for(int i=1;i<=k;i++)
		sum+=a[i];
	maxnum = sum;
	for(int i=k+1;i<=n;i++){
		sum=sum+a[i]-a[i-k];
		if(sum>maxnum)
			maxnum=sum;
	}
	double count=(k+maxnum)/2.0;
	printf("%.10f",count);
 	return 0;
}



Measured memory_bytes: 1024
N, T = map(int, input().split())

min_cost = 1000000000000
for i in range(N):
    c, t = map(int, input().split())
    if t <= T and c < min_cost:
        min_cost = c
if min_cost == 1000000000000:
    print("TLE")
else:
    print(min_cost)

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

int a[100], b[100], c[100];

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

    int res = 0;
    for (int i = 0; i < n; ++i) {
        res += b[ a[i] - 1 ];
        if (i > 0 && a[i] - a[i - 1] == 1) res += c[ a[i-1] ];
    }

    cout << res << endl;
    return 0;
}

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

int main(void){
    char ch;
    int count[26] = {0};

    while(cin >> ch) {
        if(islower(ch)) count[ch - 'a']++;
        else if(isupper(ch)) count[ch - 'A']++;
    }
    for(int i = 0; i < 26; i++) cout << (char)('a' + i) << " : " << count[i] << endl;
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	int n,i;
	sc(n);
	int a[n+1],b[n+1],c[n];
	rep1(i,n)
	{
		sc(a[i]);
	}
	rep1(i,n)
	{
		sc(b[i]);
	}
	rep1(i,n-1)
	{
		sc(c[i]);
	}
	int tot=0;
	rep1(i,n)
	{
		tot+=b[a[i]];
		if(i!=1)
		{
			if(a[i]-a[i-1]==1)
			{
				tot+=c[a[i-1]];
			}
		}
	}
	cout << tot << endl;
    return 0;
}


Measured memory_bytes: 3752
n = int(input())
h = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::vector<int>> g(n);
    for (int i = 1; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int next[] { 1, 2, 3 }, cnt[] { 1, 0 };
    std::vector<int> ret(n), par(n, -1);
    std::deque<int> q { 0 };
    par[0] = 0;
    while (!q.empty()) {
        int v = q.front();
        q.pop_front();
        for (int to : g[v]) {
            if (par[to] >= 0) continue;
            par[to] = !par[v];
            cnt[par[to]]++;
            q.push_back(to);
        }
    }

    // std::cerr << cnt[0] << ' ' << cnt[1] << std::endl;

    if (std::min(cnt[0], cnt[1]) <= n / 3) {
        int t = cnt[0] < cnt[1] ? 0 : 1;
        for (int i = 0; i < n; i++) {
            if (par[i] == t) {
                ret[i] = next[2];
                next[2] += 3;
            } else {
                for (int j = 0; j < 3; j++) {
                    if (next[j] <= n) {
                        ret[i] = next[j];
                        next[j] += 3;
                        break;
                    }
                }
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            if (next[par[i]] > n) {
                ret[i] = next[2];
                next[2] += 3;
            } else {
                ret[i] = next[par[i]];
                next[par[i]] += 3;
            }
        }
    }

    for (auto e : ret) std::cout << e << ' ';
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 15220
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

map<int,int> mp;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    int ans = 0;
    each(it,mp){
        if(it.fi <= it.se){
            ans += it.se - it.fi;
        }else{
            ans += it.se;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll numc,numd,numcd;
    numc = (b/c) - ((a-1)/c);
    numd = (b/d) - ((a-1)/d);
    numcd = (b/(c/__gcd(c,d)*d)) - ((a-1)/(c/__gcd(c,d)*d));
    cout<<b-a+1-numc-numd+numcd<<endl;
    return 0;
}

Measured memory_bytes: 256
#include  <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
using namespace std;
map<ll,ll> m;
int main()
{
    IOS;
    ll n;
    cin>>n;
    if(n%2==0) cout<<n/2-1;
    else cout<<n/2;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        n: usize,
        l: [u64; n],
    }

    let mut ans = 0;

    for i in 0..n {
        for j in (i+1)..n {
            if l[i] == l[j] {
                continue;
            }
            for k in (j+1)..n {
                if l[i] == l[k] || l[j] == l[k] {
                    continue;
                }

                if l[k] < l[i] + l[j] && l[i] < l[j] + l[k] && l[j] <  l[k] + l[i] {
                    ans += 1;
                }
                // println!("{} {} {} = {} {} {}", i+1, j+1, k+1, l[i], l[j], l[k]);
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2212
from collections import deque

def bfs(sy,sx):
    m_dis=0
    
    move=[[1,0],[0,1],[-1,0],[0,-1]]
    visited=[[-1]*yoko for i in range(tate)]
    queue=deque()
    queue.append([sy,sx]) #queue=deque([[sy,sx]])でもよい
    visited[sy][sx]=0 #スタート地点の距離は0
    while queue:
        y,x=queue.popleft()
        for dy,dx in move:
            my,mx=y+dy,x+dx
            if not(0<=my<tate) or not(0<=mx<yoko):
                continue
            if maze[my][mx]=="." and visited[my][mx]==-1:
                queue.append([my,mx])
                visited[my][mx]=visited[y][x]+1 # visitedは距離も兼ねてる
                m_dis=visited[my][mx]
        
    return m_dis

tate,yoko=map(int,input().split())
maze=[]
for i in range(tate):
    line=list(input())
    maze.append(line)
ans=0
for y in range(tate):
    for x in range(yoko):
        if maze[y][x]==".":
            ans=max(ans,bfs(y,x))
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int r, c, q;
        cin >> r >> c >> q;
        if(r == 0)
            return 0;

        vector<int> a(q), b(q), order(q);
        for(int i=0; i<q; ++i)
            cin >> a[i] >> b[i] >> order[i];

        vector<bool> rCheck(r, false);
        vector<bool> cCheck(c, false);

        int ret = 0;
        for(int i=q-1; i>=0; --i){
            if(a[i] == 0){
                if(rCheck[b[i]])
                    continue;
                rCheck[b[i]] = true;
                if(order[i] == 1)
                    ret += c;
                -- r;
            }else{
                if(cCheck[b[i]])
                    continue;
                cCheck[b[i]] = true;
                if(order[i] == 1)
                    ret += r;
                -- c;
            }
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 1560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

struct Unionfind{
    vector<int> parents;
    int n;
    Unionfind(int n):n(n),parents(n,-1){ }

    int find(int x){
        if(parents[x] < 0) return x;
        else return parents[x] = find(parents[x]);
    }

    void unite(int x,int y){
        x = find(x);
        y =  find(y);

        if(x==y) return;
        if(parents[x] > parents[y]) swap(x,y);
        parents[x] += parents[y];
        parents[y] = x;
    }  

   int size(int x){
       return -parents[find(x)];
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }

   vector<int> members(int x){
       int root = find(x);
       vector<int> member;
       for(int i=0;i<n;i++){
           if(find(i)==root ){
               member.push_back(i);
           }
       }
      return member;
  }

  int group_cnt(){
      int c = 0;
      rep(i,n){
          if(parents[i] < 0) ++c;
      }
      return c;
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    Unionfind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a;--b;
        uf.unite(a,b);
    }
    cout << uf.group_cnt()-1 << endl;
    return 0;
}

Measured memory_bytes: 3784
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 1e5 + 10;
int n;
int x[MAX],y[MAX];

// bool spr(int m){
//   int a = 0,b = 0,c = 0,d = 0;
//   R(i,n){
//     if(x[i] <= m){
//       if(y[i] <= m){
//         d++;
//       }else{
//         a++;
//       }
//     }else{
//       if(y[i] <= m){
//         b++;
//       }else{
//         c++;
//       }
//     }
//   }
//   return a == n || b == n || (d > 0 && d >= c);
// }

int cz[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  vector<PII> in;
  int sx = 0,sy = 0;
  R(i,n){
    cin >> x[i] >> y[i];
    sx += x[i];
    sy += y[i];
    in.PB({x[i],i});
    in.PB({y[i],i});
  }
  int res = 0;
  sort(ALL(in));
  bool ok = 0;
  debug(in);
  R(i,n){
    if(cz[in[i].SE]) ok = 1;
    cz[in[i].SE] = 1;
    res += in[i].FI;
  }
  if(ok){
    cout << res << "\n";
    return 0;
  }
  int wyn = min(sx,sy);
  debug(wyn,res,sx,sy);
  R(i,n){
    int ak = res + max(x[i],y[i]);
    if(in[n-1].SE != i){
      ak -= in[n-1].FI;
    }else{
      ak -= in[n-2].FI;
    }
    mini(wyn,ak);
  }
  cout << wyn << "\n";
//   int po = -1, ko = 2e9;
//   while(po + 1 != ko){
//     int m = (po + ko) / 2;
//     if(spr(m)){
//       ko = m;
//     }else{
//       po = m;
//     }
//   }
//   cout << ko << "\n";
}


Measured memory_bytes: 7536
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X,string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<<lcs<<endl;
} 
  
/* Driver program to test above function */
int main() 
{ 
  string X,Y;
  cin>>X>>Y;
  int m = X.length();
  int n = Y.length();
  lcs(X, Y, m, n); 
  return 0; 
}

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

int main() {
  string a,b;
  cin >> a >>b;
  int c,d;
  if(a=="H"){
    c=1;
  }else{
    c=-1;
  }
  if(b=="H"){
    d=1;
  }else{
    d=-1;
  }
  if(c*d==1){
    cout << "H" << endl;
  }else{
    cout << "D" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

long long modpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = (ret * x) % MOD;  
        x = (x * x) % MOD;
        n >>= 1;  
    }
    return ret;
}

int count(string s){
    int res = 0;
    rep(i,s.size())  res += (s[i]=='?');
    return res;
}

int main(){
    vector<string> st = {"A","?","AB","A?","?B","??","ABC","A?C","?BC","??C","AB?","A??","?B?","???"};
    vector<int> p(st.size(),0);
    rep(i,st.size()) p[i] = count(st[i]);
    vector<ll> cnt(st.size(),0);

    string s;
    cin >> s;
    ll q = 0;

    rep(i,s.size()){
        q += (s[i]=='?');
        if(s[i]=='C'){
            for(int j=6;j<=9;j++){
                cnt[j] = (cnt[j-4]+cnt[j])%MOD;
            }
        }
        else if(s[i]=='?'){
            for(int j=10;j<=13;j++){
                cnt[j] = (cnt[j] + cnt[j-8])%MOD;
            }
        }

        if(s[i]=='A'){
            cnt[0] = (cnt[0] + 1)%MOD;
        }
        else if(s[i]=='?'){
            cnt[5] = (cnt[5] + cnt[1])%MOD;
            cnt[1] = (cnt[1] + 1)%MOD;
            cnt[3] = (cnt[3] + cnt[0])%MOD;
        }
        else if(s[i] == 'B'){
            cnt[2] = (cnt[2] + cnt[0])%MOD;
            cnt[4] = (cnt[4] + cnt[1])%MOD;
        }
    }
    ll ans = 0;
    vector<ll> three(4);
    rep(i,4) three[i] = modpow(3,q-i);
    for(int i=6;i<=13;i++){
        ans = (ans + (cnt[i] * three[p[i]])%MOD)%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512