akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 

#include <bits/stdc++.h>
using namespace std;

int main(void)
{
    int n;
    std::cin >> n;
    string a[n];
    rep(i,n){
        std::cin >> a[i];
    }
    int m;
    std::cin >> m;
    string b[m];
    rep(i,m){
        std::cin >> b[i];
    }
    int ans=0;
    rep(i,n){
        int c=0;
        for(int j=0;j<n;j++){if(a[i]==a[j])c++;}
        //c--;
        for(int j=0;j<m;j++){if(a[i]==b[j])c--;}
        ans=max(ans,c);
    }
    std::cout <<max(ans,0)<< std::endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var TakahashiHP, TakahashiATK int
	var AokiHP, AokiATK int

	fmt.Scanf("%d %d %d %d", &TakahashiHP, &TakahashiATK, &AokiHP, &AokiATK)

	for {
		// 高橋くんが青木くんに攻撃
		AokiHP -= TakahashiATK
		if AokiHP <= 0 {
			fmt.Println("Yes")
			break
		}

		// 青木くんが高橋くんに攻撃
		TakahashiHP -= AokiATK
		if TakahashiHP <= 0 {
			fmt.Println("No")
			break
		}
	}
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  sort(A.begin(), A.end(), greater<ll>());
  cout << A.front() << " ";

  ll m = INF;
  ll ans = 0;
  for (ll i = 1; i < N; i++)
  {
    if (chmin(m, abs(A.front() - A.at(i) * 2)))
      ans = A.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
s = input()
n = len(s)

res = 0
ac = 0
i = 0
while i<n:
    if s[i]=="A":
        ac += 1
    elif s[i]=="B" and i+1<n and s[i+1]=="C":
        res += ac
        i += 1
    else:
        ac = 0
    i += 1
print(res)


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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[n] ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	sort(arr , arr + n) ;
	int ans = 1e9 ;
	for(int i = 0 ; i < n ; ++i)
	{
		ans = min(ans , arr[n-1] - arr[i] + (arr[i] - arr[0])) ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main () {
	int h,w,k=0;
	char *a;


	cin >> w >> h;
	a = new char[(h+2)*(w+2)];

	for(int i=0;i<w+2;i++){
		for(int j=0;j<h+2;j++){
			k++;
			if(i==0 || j==0 || i==w+1 || j==h+1){
				a[k] = '#';
			}else{
				cin >> a[k];
			}
		}
	}

	k=0;
	for(int i=0;i<w+2;i++){
		for(int j=0;j<h+2;j++){
			k++;
			cout << a[k];
		}
		cout << endl;
	}

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){

  str S;
  cin >> S;

  ll ans = 0;
  rep(i,0,sz(S)){
    if(S[i] == 'o'){
      ans++;
    }
  }

  if(ans + 15-sz(S) >= 8) print("YES");
  else print("NO");

 return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
s = [0] * n
t = [0] * n
s[0] = a[0]
t[-1] = a[-1]
for i in range(1,n):
    s[i] = s[i-1] + a[i]
    t[-i-1] = t[-i] + a[-i-1]

#print(s,t)

m = min([abs(s[i]-t[i+1]) for i in range(n-1)])

print(m)


Measured memory_bytes: 39020
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin>>c;
    PUTS((char)(c+1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  ll x, k, d;
  cin >> x >> k >> d;
  if (x < 0) x = -x;

  if (k < x / d) {
    x -= d * k;
    cout << x << endl;
    return 0;
  }

  k -= x / d;
  x %= d;

  ll ans;
  if (k % 2 == 0) {
    ans = x;
  } else {
    ans = d - x;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    vector<ll> a(3);
    std::cin >> a[0]>>a[1]>>a[2];
    
    sort(a.begin(),a.end());
    
    if(a[0]==a[1] && a[1]!=a[2]){
        std::cout << "Yes" << std::endl;
    }else if(a[1]==a[2] && a[0]!=a[1]){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


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

using namespace std;

struct edge{int u,v,cost;};

int par[101],rank[101];
edge es[200];
int V,E;

void init_union_find(int n){for(int i=0;i<n;i++)par[i]=i,rank[i]=0;}

int find(int x){
  if(par[x]==x)return x;
  else return par[x]=find(par[x]);
}

void unite(int x,int y){
  x=find(x),y=find(y);
  if(x==y)return;
  if(rank[x] < rank[y])par[x]=y;
  else par[y]=x,rank[x]+=(rank[x]==rank[y]);
}

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

bool comp(const edge& e1,const edge& e2){return e1.cost < e2.cost;}

int kruskal(){
  sort(es,es+E,comp);
  init_union_find(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v))unite(e.u,e.v),res+=e.cost;
  }
  return res;
}

int main(void){
  int a,b,c;

  while(cin >> V >> E && V){
    for(int i=0;i<E;i++){
      cin >> a >> b >> c;
      es[i].u=a,es[i].v=b,es[i].cost=c;
    }
    cout << kruskal() << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
N=int(input())
list=[]
for b in range(N):
    b=int(input())
    list.append(b)
number=1
c=list[0]
numbers=[]
numbers.append(c)
if c==2:
    print(number)
else:
    while True:
        number+=1
        d=list[numbers[number-2]-1]
        numbers.append(d)
        if d==2:
            print(number)
            break
        elif number==N+1:
            print(-1)
            break
        else:
            continue


Measured memory_bytes: 7888
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S1 = sc.next();
        String S2 = sc.next();
        String S3 = sc.next();
        String ans = f(S1)+f(S2)+f(S3);
        System.out.println(ans);
    }
    static String f(String S){
        char c = (char)(S.charAt(0)-'a'+'A');
        return String.valueOf(c);
    }
}


Measured memory_bytes: 21844
//packages
#include <bits/stdc++.h>//C++14 GCC mode!!!
//alias and namespaces
using namespace std;
//macros
#define rep(i,N) for (int i=0;i<N;i++)
//functions   


//solution
int solution(int H,int N,std::vector<int> A,vector<int>B){
    int inf = 1000000000;
    vector<int> dp(H+1,inf);//解説PDF通り、モンスターの体力を"i"減らすために必要な"最小魔力"とする
    //攻撃力kの攻撃ー＞i+K番目に魔力Bkを配るDPを考えていこう
    rep(i,H){
        dp[0]=0;
        rep(arts,N){
            int k,l;
            k=A[arts];
            l=B[arts];
            if ((i+k)<H) dp.at(i+k) = (dp.at(i+k)<(dp.at(i)+l))?dp.at(i+k):(dp.at(i)+l);
            else dp.at(H) = (dp.at(H)<(dp.at(i)+l))?dp.at(H):(dp.at(i)+l);
            
        }
    
    //cout<<"*"<<dp[i]<<endl;
    }
    return dp.at(H);
}

int main(void){
    //input
    int H=0;
    int N=0;
    cin >> H>>N;
    std::vector<int>A(N),B(N);
    rep(i,N){
        int a,b;
        cin >> a >> b;
        A.at(i) = a;
        B.at(i) = b;
    }
    //output
    //cout<<((solution(q)==1)?"Yes":"No")<<endl;//true to yes
    cout << solution(H,N,A,B);//value
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, m;
  cin >> n >> m;

  vll s(m), c(m);
  for (ll i = 0; i < m; i++) cin >> s[i] >> c[i];

  if (m == 0) {
    if (n == 1) cout << 0 << endl;
    else cout << (ll)pow(10, n - 1) << endl;
    return 0;
  }

  for (ll i = 0; i < 1000; i++) {
    string ans = to_string(i);
    if (ans.size() != n) continue;
    for (ll j = 0; j < m; j++) {
      if (ans[s[j] - 1] - '0' != c[j]) break;
      if (j == m - 1) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n,m,a[110];
void MAIN() {
	cin>>n>>m;
	ll tot=0;
	rep(i,n)cin>>a[i],tot+=a[i];
	sort(a,a+n);reverse(a,a+n);
	if(a[m-1]*m*4<tot)cout<<"No";
	else cout<<"Yes";
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

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

const int N=205;

int n,a[N][N],dep[N];
char str[N];
std::queue<int> que;

int solve(int x)
{
	memset(dep,0,sizeof(dep));
	while (!que.empty()) que.pop();
	dep[x]=1;que.push(x);
	int ls;
	while (!que.empty())
	{
		int t=que.front();ls=t;que.pop();
		for (int i=1;i<=n;i++)
		{
			if (!a[t][i]) continue;
			if (!dep[i]) dep[i]=dep[t]+1,que.push(i);
			else if (abs(dep[i]-dep[t])!=1) return -1;
		}
	}
	return dep[ls];
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",str+1);
		for (int j=1;j<=n;j++) a[i][j]=str[j]-'0';
	}
	int mx=-1;
	for (int i=1;i<=n;i++) mx=std::max(mx,solve(i));
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int height[] = new int[10];
        
        while(stdIn.hasNext()){
            int a = stdIn.nextInt();
            int b = stdIn.nextInt();
            
            int sum = a + b;
            
            for(int i = 1; ; i++){
            	if(sum < 10){
					System.out.println(i);
                    break;
                }
                sum /= 10;
            }
        }

        stdIn.close();
    }
}


Measured memory_bytes: 26464
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
Bs = list(mapint())

if sum(As)<sum(Bs):
    print(-1)
else:
    diff = [a-b for a, b in zip(As, Bs)]
    diff.sort()
    cnt = 0
    need = 0
    for d in diff:
        if d>=0:
            break
        need += d
        cnt += 1
    for d in diff[::-1]:
        if need>=0:
            break
        need += d
        cnt += 1
    print(cnt)

Measured memory_bytes: 76720
#include <stdio.h>

int main(){
	int n,x;
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		x = i;
		if(x % 3 == 0){  //3の倍数ごとに動く処理
			printf(" %d",x);
		}
		else {
			while(x){
				if(x % 10 == 3){//3+=10ごとに動く処理
					printf(" %d",i);
					break;
				}
				x /= 10;
			}
		}
	}printf("\n");
	return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const ll INF=1e18;

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

  vector<ll> A(2),B(2);
  cin>>A[0]>>A[1];
  cin>>B[0]>>B[1];

  ll ans=-INF;
  for(int i=0;i<2;i++) for(int j=0;j<2;j++) chmax(ans,A[i]*B[j]);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=3005;
const int mod=1e9+7;
inline void add(int &x,int y){
	x=((x+y)>=mod?(x+y-mod):(x+y));
}
int n,m,f[maxn][maxn][2];
int main(){
	read(n);read(m);
	rep(i,0,m)f[0][i][i==0]=1;
	rep(i,0,m-1)rep(j,0,n)rep(k,0,1)if(f[i][j][k]){
		int res=f[i][j][k];
		if(j)add(f[i+1][j-1][k|(j==1)],res);
		if(j)add(f[i+1][j][k|(j==1)],res);
		if (j<n)add(f[i+1][j+1][k],res);
		if (j<n)add(f[i+1][j][k],res);
	}
	int ans=0;
	rep(i,0,n)add(ans,f[m][i][1]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 70656
n, m = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(m)]
sc = sorted(sc, key=lambda x:x[0])

if m != 0 and n != 1 and sc[0][0] == 1 and sc[0][1] == 0:
    print(-1)
    exit()
if m == 0 and n == 1:
    print(0)
    exit()

ans = [0] * n
ans[0] = 1
prev = (0, 0)
if m != 0:
    prev = sc[0]
for i in range(m):
    if prev[0] == sc[i][0] and prev[1] != sc[i][1]:
        print(-1)
        exit()
    ans[sc[i][0]-1] = sc[i][1]
    prev = sc[i]
print(''.join(map(lambda x: str(x), ans)))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
 
typedef long long ll;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int mod2 = 998244353 ;
const int mod = 1e9 + 7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("output.txt", "w", stderr);
    #endif
}
const int N = 1e6 + 5;
pair<int, int> F[1 << 18];
int A[1 << 18], pre[1 << 18];

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

	for(int i = 0; i < (1<<N); ++i)
		F[i] = {A[i], 0};
	
	for(int i = 0; i < N; ++i) {
		for(int mask = 0; mask < (1<<N); ++mask){
			if(mask & (1<<i)) {
				vector<int> v;
				v.push_back(F[mask^(1<<i)].ff);
				v.push_back(F[mask^(1<<i)].ss);	
				v.push_back(F[mask].ff);
				v.push_back(F[mask].ss);	
				sort(v.begin(), v.end());
				F[mask] = {v[3], v[2]};
			}
		}
	}
	for(int i = 1; i < (1 << N); i++) {
		pre[i] = F[i].ff + F[i].ss;
		pre[i] = max(pre[i - 1], pre[i]);
		cout << pre[i] << "\n";
	}
}




Measured memory_bytes: 7168
#include<stdio.h>

int main(){
  int A,B,K;
  int i,j,k;
  scanf("%d %d %d",&A,&B,&K);
  if(B-A+1 <=K*2){
    for(i=A;i<=B;i++)
      printf("%d\n",i);
    return 0;
  }
  
  for(i=A;i<A+K;i++){
    printf("%d\n",i);
  }
  
  for(i=B-K+1;i<=B;i++)
    printf("%d\n",i);
  
  return 0;
}

Measured memory_bytes: 128
def Print(st,a,b):
    print(st[a:b])
    
def Reverse(st,a,b):
    rev = st[a:b]
    st = st[:a] + rev[::-1] + st[b:]
    
    return st

def Replace(st,a,b,p):
    rep = str(p)
    st = st[:a] + rep + st[b:]
    
    return st

st = input()
num = int(input())
while num > 0:
    com = input().split()
    a = int(com[1])
    b = int(com[2])
    
    if(com[0] == "print"):
        Print(st,a,b+1)
    elif(com[0] == 'reverse'):
        st = Reverse(st,a,b+1)

    elif(com[0] == 'replace'):
        p = str(com[3])
        st = Replace(st,a,b+1,p)
    num -= 1




Measured memory_bytes: 5612
K,N = map(int,input().split())
A = list(map(int,input().split()))
A.append(A[0]+K) ##円の最後に追加する．

#Maxの差
Ma=0
for i in range(N):
    if Ma < A[i+1]-A[i]:
        Ma = A[i+1]-A[i]
ans = K-Ma
print(ans)

Measured memory_bytes: 26060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x; cin>>x;
	if (x<=0) cout<<"1"<<endl;	
	else cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 3636
// include
#include <cstdint>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <array>

// ============================================
int main() {

  int x, y;
  std::cin >> x >> y;
  

  for (int kame = 0; kame <= 100; kame++) {
    for (int tsuru = 100 - kame; tsuru >= 0; tsuru--) {
      if ((kame * 4 + tsuru * 2) == y) {
        if (kame + tsuru == x) {
          std::cout << "Yes" << std::endl;
          return 0;
        }
      }
    }
  }
  
  std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 3620
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-22 22:15:50
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;
  vector<int> a(n); cin >> a;

  map<int, int64> mp;

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

  int64 sum = 0LL;

  for (auto x : mp) {
    sum += x.second * (x.second - 1LL) / 2LL;
  }

  for (int i = 0; i < n; ++i) {
    cout << sum - (mp[a[i]] - 1LL) << '\n';
  }

  return 0;
}

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

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

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n; cin >> n; vector<P> task(n);
  
  rep(i,n){
    ll a,b; cin >> a >> b;
    P p = make_pair(b,a);
    task[i] = p;
  }
  
  sort(all(task));
  
  ll timesum = 0; bool flag = true;

  for(auto p : task){
    timesum += p.second;
    if(timesum > p.first){
      flag = false; 
      break;
    }
  }
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3456
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
x, y, h = list(filter(lambda x: x[2], p))[0]

for i in range(101):
  for j in range(101):
    H = h + abs(x-i) + abs(y-j)
    if all(max(H-abs(t[0]-i)-abs(t[1]-j), 0) == t[2] for t in p):
      print(i,j,H)

Measured memory_bytes: 3188
range_num = int(input())

num_set = set(i for i in range(1, range_num+1))
# 除外する数字
ex_set = set(i for i in range(1, range_num+1) if i%3 == 0 or i%5==0)
ans_set = num_set - ex_set

print(sum(ans_set))

Measured memory_bytes: 137948
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
 
int main(){
    int a,b;
    char op;
    cin >> a >> op >> b;
    if(op=='+'){
        cout << a+b << endl;
    }
    if(op=='-'){
        cout << a-b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e5+5;

int n;
int a[105];
void ngk(){
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        if (a[i] > i){
            cout << -1;
            return;
        }
    }
    vector <int> ans;
    for(int _=0;_<n;_++){
        for(int i=n-_;i>=1;i--){
            if (a[i] == i){
                ans.push_back(i);
                for(int j=i;j<n-_;j++)
                    a[j] = a[j+1];
                break;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    for(auto v: ans)    cout << v << '\n';
} 

/*
    Verifying the algorithm
    Array limits;
    Corner cases;
*/

int main(){
    #ifdef NGKCP
        freopen("input.txt","r",stdin);
    #endif
    iostream::sync_with_stdio(0);
    ngk();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

const long long MOD = 2;

void solve(long long N, std::vector<long long> a){
    vector<bool> ans(N+1, false);
    for(ll i= N; i>0; i--){
        ans[i] = (bool) a[i-1];
        for(ll k=2*i; k<= N; k+= i){
            if(ans[k]) 
                ans[i] = !ans[i];
        }
    }
    ll sum = 0;
    for(ll i=1; i<= N; i++){
        if(ans[i])
            sum++;
    }
    cout << sum << endl;
    vll res;
    if(sum > 0){
        for(ll i=1; i<= N; i++){
            if(ans[i])
                res.push_back(i);
        }
    }
    rep(i, res.size()){
        if(i != res.size()-1)
            cout << res[i] << ' ';
        else
            cout << res[i] << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 3576
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}

void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}

#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

void solve() {
    cini(n);
    cini(k);
    cinai(a,n);
    vi lvl(n,-1);

    int pos=0;
    int plvl=-1;
    while(k && lvl[pos]<0) {
        lvl[pos]=plvl+1;
        plvl++;
        pos=a[pos]-1;
        k--;
    }

    int c=plvl-lvl[pos]+1;
    k%=c;
//cerr<<"pos="<<pos<<" c="<<c<<" k="<<k<<endl;
    for(int i=0; i<k; i++) 
        pos=a[pos]-1;
    cout<<pos+1<<endl;
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 6368
N = int(input())
A = list(map(int, input().split()))
A = [a-i-1 for i, a in enumerate(A)]
A.sort()
if N%2:
  med = A[(N-1)//2]
  A = [abs(a-med) for a in A]
  print(sum(A))
  exit()
else:
  med1 = (A[N//2-1]+A[N//2])//2
  med2 = med1 + 1
  A1 = [abs(a-med1) for a in A]
  A2 = [abs(a-med2) for a in A]
  print(min(sum(A1), sum(A2)))
  exit()

Measured memory_bytes: 32588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N,K,i;
    cin >> N >> K;
  
    ll A[N + 1];
    ll P[N + 1];
    A[0] = 1;
    P[0] = 1;
    for(i = 1;i <= N;i++){
        A[i] = 2 * A[i - 1] + 3;
        P[i] = 2 * P[i - 1] + 1;
    }
    ll count = 0;
    for(i = N; i > 0; i--){
        if(K == 0) break;
        K--;
        if(K <= A[i - 1]) continue;
        K -=A[i - 1] + 1;
        count += P[i - 1] + 1;
    }
    if(K) count++;
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 256
from math import sqrt

N, D = map(int, input().split())
X = []
for _ in range(N):
    x = list(map(int, input().split()))
    X.append(x)

ans = 0
for i in range(0, N):
    for j in range(i + 1, N):
        res = 0
        for x1, x2 in zip(X[i], X[j]):
            res += (x1 - x2) ** 2
        res = sqrt(res)
        if (res == round(res)):
            ans += 1

print(ans)


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0; i<(n); ++i)

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    while (cin >> n >> m, n || m) {
        int d[2][101][101];
        REP(i,2) REP(j,m+1) REP(k,m+1) {
            d[i][j][k] = (j == k ? 0 : 1e8);
        }
        int a, b, cost, time;
        REP(i,n) {
            cin >> a >> b >> cost >> time;
            d[0][a][b] = min(d[0][a][b], cost);
            d[0][b][a] = min(d[0][b][a], cost);
            d[1][a][b] = min(d[1][a][b], time);
            d[1][b][a] = min(d[1][b][a], time);
        }
        REP(k,m+1) REP(i,m+1) REP(j,m+1) {
            d[0][i][j] = min(d[0][i][j], d[0][i][k] + d[0][k][j]);
            d[0][j][i] = min(d[0][j][i], d[0][j][k] + d[0][k][i]);
            d[1][i][j] = min(d[1][i][j], d[1][i][k] + d[1][k][j]);
            d[1][j][i] = min(d[1][j][i], d[1][j][k] + d[1][k][i]);
        }
        int k, p, q, r;
        cin >> k;
        REP(i,k) {
            cin >> p >> q >> r;
            cout << d[r][p][q] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main()
{
  int a;
  long b,n;
  scanf("%d %ld %ld",&a,&b,&n);

  long min = 0;
  if(b-1 > n){
    min = n;
  }else{
    min = b-1;
  }

  printf("%lld",(a*min)/b);

}



Measured memory_bytes: 1712
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
        public static void main(String[] arg) throws IOException {
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                String[] ia; 

                while(true){
                        ia = in.readLine().split(" ");
                        int N = Integer.parseInt(ia[0]);
                        int K = Integer.parseInt(ia[1]);
                        if(N == 0 && K == 0){ 
                                break;
                        }   
                        int[] S = new int[K];
                        ia = in.readLine().split(" ");
                        for(int i = 0;i < K; ++i){
                                S[i] = Integer.parseInt(ia[i]);
                        }   
                        for(int i = 0;i < N; ++i){
                                ia = in.readLine().split(" ");
                                for(int j = 0;j < K; ++j){
                                        S[j] -= Integer.parseInt(ia[j]);
                                }   
                        }   
                        boolean yet = true;
                        for(int i = 0;i < K; ++i){
                                if(S[i] < 0){ 
                                        yet = false;
                                        break;
                                }   
                        }   
                        if(yet){
                                System.out.println("Yes");
                        } else {
                                System.out.println("No");
                        }   
                }   
        }   
}

Measured memory_bytes: 11000
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void times(alias fun)(int n) {
    foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = fun();
    return res;
}
// fold was added in D 2.071.0.
template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
        static if (S.length < 2) {
            return reduce!fun(seed, r);
        } else {
            return reduce!fun(tuple(seed), r);
        }
    }
}

void main() {
    int N;
    int[] M = new int[2];
    readf("%d %d %d\n", &N, &M[0], &M[1]);

    DisjointSet[] sets = 2.iota.map!(i =>
        DisjointSet(N).pipe!((set) {
            M[i].times!({
                int s, t;
                readf("%d %d\n", &s, &t);
                s--; t--;
                set.unite(s, t);
            });
            return set;
        })
    ).array;

    int[2][] ary = N.iota.map!(i =>
        sets.map!(a =>
            a.findSet(i).to!int
        ).array.to!(int[2])
    ).array;
    int[int[2]] aa;
    ary.each!(k => aa[k]++);
    ary.map!(k => aa[k].to!string).join(" ").writeln;
}

// 互いに素な集合
// UnionFindTreeによる実装
struct DisjointSet {

private:
    Vertex[] _vertices;

public:
    this(size_t size) {
        _vertices = new Vertex[size];
        foreach(i, ref v; _vertices) {
            v.index = i;
            v.parent = i;
        }
    }

    void makeSet(size_t[] indices...) {
        foreach(index; indices) {
            _vertices[index] = Vertex(index, index);
        }
    }

    void unite(size_t x, size_t y) {
        link(findSet(x), findSet(y));
    }

    void link(size_t x, size_t y) {
        if (x==y) return;
        if (_vertices[x].rank > _vertices[y].rank) {
            _vertices[y].parent = x;
        } else {
            _vertices[x].parent = y;
            if (_vertices[x].rank == _vertices[y].rank) {
                _vertices[y].rank++;
            }
        }
    }

    bool same(size_t x, size_t y) {
        return findSet(x) == findSet(y);
    }

    size_t findSet(size_t index) {
        if (_vertices[index].parent == index) {
            return index;
        } else {
            return _vertices[index].parent = findSet(_vertices[index].parent);
        }
    }

private:
    struct Vertex {
        size_t index;
        size_t parent;
        size_t rank = 1;
    }
}


Measured memory_bytes: 29052
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;


int main(){
	int n;
	cin>>n;
	int a;
	cin>>a;
	int mi = a, ma;
	for(int i = 1; i < n; i++){
		cin>>a;
		if(i == 1) ma = a - mi;
		else ma = max(ma, a -mi);
		mi = min(a, mi);
	}
	cout<<ma<<endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll X[60];
ll i, j, k;

int main(){
    fornum(i,0,5){
        scanf("%lld", &X[i]);
    }
    fornum(i,0,5){
        if(X[i]==0){
            printf("%lld\n", i + 1);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3824
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    ans += 1 if 0 < c+sum([a[j]*b[j] for j in range(m)]) else 0
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Solution
{
    static bool IsMatch(char c1, char c2)
    {
        return c1 == '?' || c2 == '?' || c1 == c2;
    }

    public static void Main()
    {
        var a = Console.ReadLine();
        var b = Console.ReadLine();
        var c = Console.ReadLine();

        const int Margin = 4000;
        const int Max = Margin * 2 + 1;
        var ab = Enumerable.Repeat(true, Max).ToArray();
        var ac = Enumerable.Repeat(true, Max).ToArray();
        var bc = Enumerable.Repeat(true, Max).ToArray();
        for (int i = 0; i < a.Length; i++)
        {
            for (int j = 0; j < b.Length; j++)
            {
                ab[i - j + Margin] &= IsMatch(a[i], b[j]);
            }
        }
        for (int i = 0; i < a.Length; i++)
        {
            for (int j = 0; j < c.Length; j++)
            {
                ac[i - j + Margin] &= IsMatch(a[i], c[j]);
            }
        }
        for (int i = 0; i < b.Length; i++)
        {
            for (int j = 0; j < c.Length; j++)
            {
                bc[i - j + Margin] &= IsMatch(b[i], c[j]);
            }
        }

        var min = int.MaxValue;
        for (int i = -Margin; i <= Margin; i++)
        {
            for (int j = -Margin; j <= Margin; j++)
            {
                var bcIndex = j - i + Margin;
                if (ab[i + Margin] && ac[j + Margin] && (bcIndex < 0 || bcIndex >= Max || bc[j - i + Margin]))
                {
                    var left = Math.Max(0, Math.Max(-i, -j));
                    var right = Math.Max(a.Length, Math.Max(b.Length + i, c.Length + j));
                    var len = left + right;
                    min = Math.Min(min, len);
                }
            }
        }

        Console.WriteLine(min);
    }
}

Measured memory_bytes: 13200
from collections import deque

def search(x):
    for a in A[1:]:
        if x == a: return 'A'
    for b in B[1:]:
        if x == b: return 'B'
    for c in C[1:]:
        if x == c: return 'C'

while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    s = ''
    for i in range(1, n+1):
        s += search(i) 
    d = {}
    d[s] = 0
    q = deque([s])
    cnt = 0
    while q:
        s = q.popleft()
        if d[s] > m:
            continue
        if s in ['A' * n, 'C' * n]:
            print(d[s])
            break
        lastA, lastB, lastC = -1, -1, -1
        for i in reversed(range(n)):
            if s[i] == 'A' and lastA < 0:
                lastA = i
            if s[i] == 'B' and lastB < 0:
                lastB = i
            if s[i] == 'C' and lastC < 0:
                lastC = i
        if lastA > lastB:
            news = s[:lastA] + 'B' + s[lastA+1:]
            if news not in d:
                d[news] = d[s] + 1
                q.append(news)
        if lastB > lastA:
            news = s[:lastB] + 'A' + s[lastB+1:]
            if news not in d:
                d[news] = d[s] + 1
                q.append(news)
        if lastB > lastC:
            news = s[:lastB] + 'C' + s[lastB+1:]
            if news not in d:
                d[news] = d[s] + 1
                q.append(news)
        if lastC > lastB:
            news = s[:lastC] + 'B' + s[lastC+1:]
            if news not in d:
                d[news] = d[s] + 1
                q.append(news)
    else:
        print(-1)



Measured memory_bytes: 326368
import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int ans=0;
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st1=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st1.nextToken());
int m=Integer.parseInt(br.readLine());
StringTokenizer st2=new StringTokenizer(br.readLine());
for(int i=0;i<m;i++){
int b=Integer.parseInt(st2.nextToken());
if(BinarySearch(a,b)>=0) ans++;
}
out.println(ans);
out.flush();
}
}

private static int BinarySearch(int[] a,int b){
int lb=0;
int ub=a.length;
while(ub>lb){
int mid=(lb+ub)/2;
if(a[mid]==b) return mid;
else if(a[mid]>b) ub=mid;
else lb=mid+1;
}
return -1;
}
}

Measured memory_bytes: 36036
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long N,D,count;cin>>N>>D;count=0;
    for(long long i=0;i<N;i++){
        long long X,Y;cin>>X>>Y;
        if(sqrt(pow(X,2)+pow(Y,2))<=D){
            count++;
        }
    }
    cout<<count<<endl;
}


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

void f(const string& s,int& a, int& b){
	a = count( s.begin() , s.end() , 'A' );
	b = count( s.begin() , s.end() , 'B' );
}

int main(){
	string s;
	while( cin >> s , s != "0" ){
		int a,b;
		f(s,a,b);
		a--;
		(a>b)? a++ : b++ ;
		cout << a << " " << b << endl;
		for(int i=0 ; i < 2 ; i++ ){
			cin >> s;
			f(s,a,b);
			(s[0]=='A')? a-- : b-- ;
			(a>b)? a++ : b++ ;
			cout << a << " " << b << endl;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 50
#define DB double
int n;
DB v[MAXN+1];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%lf",&v[i]);
	sort(v+1,v+n+1);
	for(int i=2;i<=n;i++)
	v[i]=(v[i-1]+v[i])/2.0;
	printf("%.8f",v[n]);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        long n = scan.nextLong();
        if(n == 1){
            System.out.println(0);
            return;
        }
        int out = 0;
        for(long i = 2; i <= Math.sqrt(n); i++){
            int e = 0;
            while(n % i == 0){
                n /= i;
                e++;
            }
            out += (Math.sqrt(8 * e + 1) - 1) / 2;
        }
        if(n > 1) out++;
        System.out.println(out);
    }

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


Measured memory_bytes: 35792
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
//typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
   
    vector<string> state(n);
    int ite = 0;
    int large=n-1;
    int small=0;
    bool yet = true;
    string f = "Female", m = "Male", v = "Vacant";
    cout << 0 << endl;
    string s;
    cin >> s;
    if (s == v)
    {
        yet = false;
    }
    else if (s == f)
    {
        rep(i, n)
        {
            if (i % 2 == 0)
            {
                state[i] = f;
            }
            else
            {
                state[i] = m;
            }
        }
    }
    else if (s == m)
    {
        rep(i, n)
        {
            if (i % 2 == 0)
            {
                state[i] = m;
            }
            else
            {
                state[i] = f;
            }
        }
    }
    if (yet)
    {
        cout << n - 1 << endl;
        string t;
        cin >> t;
        if (t == v)
        {
            yet = false;
        }
        else
        {
            ite = (small+large) / 2;
        }
    }
    if (yet)
    {
        rep(i, 18)
        {
            if (yet)
            {
                cout << ite << endl;
                cin >> s;
                if (s == state[ite])
                {
                    small=ite;
                    ite = (small + large) / 2;
                    
                }
                else if (s != v)
                {
                    large=ite;
                    ite = (small+large) / 2;
                }
                else
                {
                    yet = false;
                    break;
                }
            }
        }
    }
}

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

int main(){
	int k; cin>>k;
	if(k%2==0) {cout<<-1<<endl; return 0;}
	if(7%k==0) {cout<<1<<endl; return 0;}
	int ans=-1;
	int r=7%k;
	for(int i=2; i<=1000000; i++){
		r=(r*10+7)%k;
		if(r==0) {ans=i; break;}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3596