akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 307;

double f[N + 10][N + 10][N + 10];

int main() {
    int n;
    cin >> n;
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x == 1) {
            c1++;
        } else if (x == 2) {
            c2++;
        } else {
            c3++;
        }
    }

    for (int k = 0; k < N; k++) {
        for (int j = 0; j + k < N; j++) {
            for (int i = 0; i + j + k < N; i++) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }
                if (i + j + k > N) {
                    continue;
                }
                double wait = 1.0 * n / (i + j + k);
                double pi = 1.0 * i / (i + j + k);
                double pj = 1.0 * j / (i + j + k);
                double pk = 1.0 * k / (i + j + k);

                if (i) {
                    f[i][j][k] += pi * f[i - 1][j][k];
                }
                if (j) {
                    f[i][j][k] += pj * f[i + 1][j - 1][k];
                }
                if (k) {
                    f[i][j][k] += pk * f[i][j + 1][k - 1];
                }
                f[i][j][k] += wait;
            }
        }
    }
    printf ("%.9lf", f[c1][c2][c3]);
    return 0;
}



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

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == 5){
    if(b == 5){
      if(c == 7){
        cout << "YES" << '\n';
      }
      else{
        cout << "NO" << '\n';
      }
    }
    else if(b == 7){
      if(c == 5){
        cout << "YES" << '\n';
      }
      else{
        cout << "NO" << '\n';
      }
    }
    else{
      cout << "NO" << '\n';
    }
  }
  else if(a == 7){
    if(b == 5){
      if(c == 5){
        cout << "YES" << '\n';
      }
      else{
        cout << "NO" << '\n';
      }
    }
    else{
      cout << "NO" << '\n';
    }
  }
  else{
    cout << "NO" << '\n';
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma optimize("unroll-loops");
#pragma optimize("Ofast");
//#include "pch.h"    
using namespace std;
unordered_map<int, bool> here;
 
using ll = long long;
const int nax = 5e5 + 2;
const ll mod = 1e9 + 7;

int main() {
    
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n + 1, -1);
    
    while(k--) {
        int d;
        cin >> d;
        while(d--) {
            int snuke;
            cin >> snuke;
            a[snuke] = 1;
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        if(a[i] == -1) {
            ++ans;
        }
    }
    
    cout << ans << "\n";
}


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

int main(){
    int n;
    cin >> n;
    int a[n+1],b[n];
    for(int i=0; i<n+1; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    ll cnt=0;
    for(int i=n; i>0; i--){
        cnt+=min(b[i-1],a[i]);
        b[i-1]-=min(b[i-1],a[i]);
        cnt+=min(b[i-1],a[i-1]);
        a[i-1]-=min(b[i-1],a[i-1]);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_u32(void *base, const int count, const int size, const int index){
	typedef uint32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

int n;
int a[100001];
int b[100001];
int c[100001];
int d[200001];

int inc(int i){
	i+=100000;
	while(i<=200000){
		d[i]++;
		i+=i&-i;
	}
}

int sum(int i){
	i+=100000;
	int s=0;
	while(i>0){
		s+=d[i];
		i-=i&-i;
	}
	return s;
}

long f(int x){
	for(int i=1; i<=n; i++){
		c[i]=c[i-1]+(a[i]<=x?1:-1);
	}
	memset(d, 0, sizeof(d));
	long ans=0;
	inc(c[0]);
	for(int i=1; i<=n; i++){
		ans+=sum(c[i]-1);
		inc(c[i]);
	}
	return ans;
}

int main(void){
	n=nextint();
	for(int i=1; i<=n; i++){
		a[i]=b[i]=nextint();
	}
	rsorta_u32(b+1, n, 1, 0);
	int kl=1, kr=n;
	long m = (long)n*(n+1)/4+1;
	//printf("%d\n", m);
	while(kl<=kr){
		int km=(kl+kr)/2;
		//printf("%d %d %ld\n", km, b[km], f(b[km]));
		if(f(b[km])>=m) kr=km-1; else kl=km+1;
	}
	//printf("%d %d %ld\n", kl, b[kl], f(b[kl]));
	printf("%d\n", b[kl]);
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, d;
	cin >> n >> d;
	d  = 2 * d + 1;
	cout << (n + d - 1) / d;
	
	
	return 0;
}



Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main (String [] args){
//		String [][] boad = new String[4][4];
		int h1 = Integer.parseInt(sc.next());
		int w1 = Integer.parseInt(sc.next());
		int h2 = Integer.parseInt(sc.next());
		int w2 = Integer.parseInt(sc.next());
		int count = 0;
		if(h1==h2 && w1==w2){
			count =0;
		}else{
			count = h1*w1 -(h2*w2 + (h2*(w1-w2)) + (w2*(h1-h2)));
		}
		
	System.out.println(count);
	System.out.flush();
	sc.close();
	}
}

Measured memory_bytes: 22868
using System;
using System.Collections.Generic;
using System.Linq;

namespace Practice
{
    static class StrangeBank
    {
        static void Main()
        {
            int N;
            N = int.Parse(Console.ReadLine());
            int[] a = { 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049 };
            
            int[] MinCount = Enumerable.Range(0, N+1).ToArray();
            for(int i = 6; i <= N; i++)
            {
                // 各i <= Nについて「i-a[k]を作ってa[k]を1回加える」で最小を更新するか判定
                foreach(int val in a)
                {
                    if(val <= i)
                        MinCount[i] = Math.Min(MinCount[i - val] + 1, MinCount[i]);
                }
            }

            Console.WriteLine($"{MinCount[N]}");
        }
    }
}


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

int dp[2000][2000];

int main() {
  int n,x,y;
  cin >> n >> x >> y;
  for (int i=1; i<n; i++) {
    for (int j=i+1; j<=n; j++) {
      if(i<=x && j<=x) dp[i][j-i]++;
      else if(i<=x && j>x && j<y) {
        int mi=min(j-i,x-i+1+y-j);
        dp[i][mi]++;
      }
      else if(i<=x && j>=y) dp[i][j-i-y+x+1]++;
      else if(i>x && i<y && j<y) {
        int mi=min(j-i,i-x+1+y-j);
        dp[i][mi]++;
      }
      else if(i>x && i<y && j>=y) {
        int mi=min(j-i,i-x+1+j-y);
        dp[i][mi]++;
      }
      else dp[i][j-i]++;
    }
  }
  for (int k=1; k<n; k++) {
    int ans=0;
    for (int i=1; i<n; i++) {
      ans+=dp[i][k];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 15232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  if(a*b % 2 == 0){
    cout << "Even" << endl;
  }else if(a*b % 2 != 0){
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;
	ll t;



        ll i,j,k,x,y,z,m,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
        string s,s1,str;
        cin>>x;
        if(400<=x&&x<=599)
            cout<<8;
        if(600<=x&&x<=799)
            cout<<7;
         if(800<=x&&x<=999)
            cout<<6;
        if(1000<=x&&x<=1199)
            cout<<5;
        if(1200<=x&&x<=1399)
            cout<<4;
        if(1400<=x&&x<=1599)
            cout<<3;
        if(1600<=x&&x<=1799)
            cout<<2;
        if(1800<=x&&x<=1999)
            cout<<1;
            nl;



}


Measured memory_bytes: 3612
#include <stdio.h>

int main(void)
{
	int a, b;
	int sum;
	int keta;
	
	while (scanf("%d %d", &a, &b) != EOF){
		sum = a + b;
		
		keta = 0;
		while (sum){
			sum /= 10;
			keta++;
		}
		printf("%d\n", keta);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
	int n;

	cin >> n;

	vector<long long int> a(n);

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

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

	long long int m1 = 0, m2 = 0;

	for (int i = n-1; i > 0; i--){
		if (a[i] == a[i-1]){
			if (m1 == 0)
				m1 = a[i];
			else {
				if (a[i] == m1){
					if (i >= 2 && a[i-1] == a[i-2]){
						m2 = a[i-1];
						break;
					}
				}
				else {
					m2 = a[i];
					break;
				}
			}
		}
	}

	cout << m1 * m2 << endl;
}

Measured memory_bytes: 1024
n=int(input())
A=[]
for i in range(n):
    A.append([])
    for j in range(int(input())):
        A[i].append(list(map(int,input().split())))
for i in range(n,-1,-1):
    s=(1<<i)-1
    while s<1<<n:
        x=s&(-s)
        y=s+x
        flag=False
        for j in range(n):
            if s>>j & 1:
                for k in range(len(A[j])):
                    if (A[j][k][1]!=1 and (s>>(A[j][k][0]-1))&1==1) or (A[j][k][1]==1 and ((s>>(A[j][k][0]-1))&1)==0):
                        flag=True
                        break
            if flag:
                break
        if flag!=True:
            print(i)
            exit()
        s = ((s & ~y) // x) >> 1 | y

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
ll n;
vec arr;
ll dp[3001][3001][2];
ll func(ll l,ll r,bool turn) {
	if(l > r)
		return 0;
	if(dp[l][r][turn] != -1)
		return dp[l][r][turn];
	ll v1 = func(l + 1,r,!turn);
	ll v2 = func(l,r -1,!turn);
	if(turn) {
		dp[l][r][turn] = max(v1 + arr[l],v2 + arr[r]);
	}
	else
		dp[l][r][turn] = min(v1,v2);
	return dp[l][r][turn];
}	
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	arr.resize(n);
	ll i,j,k;
	for(i = 0 ; i <= n ; i++)
		for(j = 0 ; j <= n ; j++)
			for(k = 0; k < 2 ; k++)
				dp[i][j][k] = -1;
	for(i = 0 ; i < n ; i++)
		cin >> arr[i];
	ll x = func(0,n-1,true);
	ll y = func(0,n-1,false);
	cout << x - y;
	return 0;
}

Measured memory_bytes: 144588
#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;

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

  vector<bool> b(n, false);
  vector<int> c;
  int x = 0;
  int pos = 0;
  rep(i, n*2){
    if(!b[pos]){
      b[pos] = true;
      c.push_back(pos);
      pos = a[pos];
    }
    else{
      x = pos;
      break;
    }
  }

  vector<int> d;
  bool ok = false;
  rep(i, c.size()){
    if(c[i] == x) ok = true;
    if(ok) d.push_back(c[i]);
  }

  int l = d.size();
  int jama = c.size() - l;
  if(k < jama){
    cout << c[k] + 1 << endl;
  }
  else{
    cout << d[(k-jama)%l] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 6204
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf = 1e18;

int N, x;
int main() {

    cin >> N >> x;
    if (x == 1 || x == 2 * N - 1) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        int cnt = 2;
        for (int i = 1; i <= 2 * N - 1; i++) {
            if (i == N - 1) {
                puts("1");
            } else if (i == N) {
                printf("%d\n", x);
            } else if (i == N + 1) {
                printf("%d\n", 2 * N - 1);
            } else {
                if (cnt == x)cnt++;
                printf("%d\n", cnt++);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    string s;
    cin >> s;
    int ans = 0;
    int cnt = 0;
    int g = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] == 'g'){
            cnt += 1;
            g += 1;
        }else{
            if (cnt > 0) cnt -= 1;
            else ans -= 1;
        }
    }
    if (cnt / 2 < g) ans += cnt / 2;
    else ans += g;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 ll INF = 1e18;

int main(){
    int r,g,b;
    cin >> r >> g >> b;
    int now = g*10+b;
    if(now%4==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

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

  //corner case
  if(y == 0 && x > 0){
    cout << 1+x << endl;
    return 0;
  }

  if(x == 0 && y < 0){
    cout << 1-y << endl;
    return 0;
  }

  //y >= x
  if(y >= x){
    if(x >= 0 || y <= 0){
      cout << y-x << endl;
    }else if( -y <= x ){
      cout << 1+y+x << endl;
    }else{
      cout << -y-x+1 << endl;
    }
    return 0;
  }

  // y < x
  if(x>0 && y<0){
    if(-x<=y){
      cout << y+x+1 << endl;
    }else{
      cout <<  -y-x+1 << endl;
    }
  }else{
    cout << 2+x-y << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

#define PI 3.1415926535897932384

using namespace std;

int main() {
	double x = 0, y = 0;
	int t = 90;
	
	while (1) {
		int d, it;
		scanf("%d,%d", &d, &it);
		if (d==0 && it==0) break;
		
		x += d * cos((double)t * PI/180.);
		y += d * sin((double)t * PI/180.);
		
		t -= it;
	}
	
	cout << (int)x << endl << (int)y << endl;
	
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
using namespace std;
int main(){
    map<int,int> mp;

    REP(i,6){
     int x;
     cin >> x;
     mp[x]++;   
    }

    for(auto p:mp){
        if(p.second>=3){
            cout << "NO" <<endl;
            return 0;
    }
    }
    cout << "YES" <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N, D, X;
    cin >> N >> D >> X;
    int A[N];
    rep(i, N){
        cin >> A[i];
    }

    int eated = 0;
    for(int i = 0; i < D; i++){
        rep(j, N){
            if(i * A[j] + 1 <= D){
                eated++;
            }
        }
    }

    cout << eated + X << endl;

    return 0;
}

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

int n;
int a[1000];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	vector<int> vec;
	rep(i, n) {
		for (j = 1; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				vec.push_back(j);
				if (j != a[i] / j) vec.push_back(a[i] / j);
			}
		}
	}
	
	int ans = 0;
	rep(i, vec.size()) {
		int k = vec[i];
		if (k <= 1) continue;
		
		int ssum = 0;
		rep(j, n) {
			if (a[j] % k == 0) ssum += a[j];
		}
		ans = max(ans, ssum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3856
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	int INF = 1 << 28;
	double EPS = 1e-10;

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

	void run() {
		long M = sc.nextLong();
		long rd = sc.nextLong();
		long rr = sc.nextLong();
		long cd = sc.nextLong();
		long cr = sc.nextLong();
		long r = 0;
		long l = 1000L * 1000L * 1000L * 1000L + 1;
		for (int i = 0; i < 1000; i++) {
			long mid = (r + l) / 2;
			if (cd <= rd * mid / 100) {
				l = mid;
			} else {
				r = mid;
			}
		}
		long x = l;
		r = 0;
		l = M;
		for (int i = 0; i < 1000; i++) {
			long mid = (r + l) / 2;
			if (cr <= rr * mid / 100) {
				l = mid;
			} else {
				r = mid;
			}
		}
		long y = l;
		if (x + y > M) {
			System.out.println(-1);
		} else {
			long D = rd * x / 100;
			long R = rr * y / 100;
			long ans = M - x - y;
			if (D < cd || R < cr) {
				System.out.println(-1);
			} else {
				ans += 100 * (D - cd) / rd;
				ans += 100 * (R - cr) / rr;
				System.out.println(ans);
			}
		}
	}
}

Measured memory_bytes: 17240
import Control.Applicative ((<$>))
import Control.Monad (forM_)
import Data.Vector.Unboxed (Vector, (!), (//))
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = solve <$> map read <$> lines <$> getContents >>= mapM_ print

solve :: [Int] -> [Int]
solve = map (smv !)
  where smv = V.create $ do
          v1 <- VM.replicate 2001 0
          forM_ [0 .. 1000] $ \i -> do
            forM_ [0 .. 1000] $ \j -> do
              vij <- VM.read v1 (i+j)
              VM.write v1 (i+j) (vij+1)
          v2 <- VM.replicate 4001 0
          forM_ [0 .. 2000] $ \i -> do
            forM_ [0 .. 2000] $ \j -> do
              vi <- VM.read v1 i
              vj <- VM.read v1 j
              vij <- VM.read v2 (i+j)
              VM.write v2 (i+j) (vij + vi*vj)
          return v2



Measured memory_bytes: 6168
N = int(input())
x = 1
y = 1
z = 1
f = [0] * N
while True:
    y = x
    v = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if v > N:
        break
    while True:
        z = y
        v = x**2 + y**2 + z**2 + x*y + y*z + z*x
        if v > N:
            break
        while True:
            v = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if v > N:
                break
            else:
                if x == y:
                    if y==z:
                        f[v-1] += 1
                    else:
                        f[v-1] += 3
                else:
                    if y==z:
                        f[v-1] += 3
                    else:
                        f[v-1] += 6
            z += 1
        y += 1
    x += 1
for i in f:
    print(i)


Measured memory_bytes: 9284
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	string x;
	cin >> x;
	vi cnt(2);
	bool a=0, b=0;
	REP(i, 3) {
		a |= (x[i] == 'A');
		b |= (x[i] == 'B');
	}
	if (a && b) cout << "Yes\n";
	else {cout << "No\n";}
	
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        char[] n = fs.next().toCharArray();
        if (n[0] == n[1] && n[0] == n[2] || n[1] == n[2] && n[1] == n[3])
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 78416
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
#define ll long long
typedef unsigned long long ull;
typedef long double ld;

#define pii         pair<ll ,ll >
#define vi          vector<ll >
#define vii         vector<pii>
#define mi          map<ll ,ll >
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define pb          push_back
#define hell        1000000007
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        1000005


#define allr(c) (c).rbegin(),(c).rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}


void solve()
{
	ll x;
	cin>>x;
	if(x==0)
	{
		cout<<1<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
}

int main()
    {
    	ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
      
        ll t;
        
        t=1;
        
    
   // cin>>t;
        while(t--)
        solve();
    }

Measured memory_bytes: 3692
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define    endl        '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)     for(auto& a : x)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound

/*    For Debugging    */
#define DEBUG         cerr<<"/n>>>I'm Here<<</n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
    ll sum=0;
    rep(i,0,3)
    {
        ll x;
        cin>>x;
        sum+=x;
    }
    if(sum>=22)
    {
        cout<<"bust\n";
    }
    else
    {
        cout<<"win\n";
    }
    return;
}
int main()
{
    FAST
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    TIME
    return 0;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<int>> v(h, vector<int>(w));
  rep (i, h) {
    rep (j, w) {
      char c;
      cin >> c;
      if (c == '#') v[i][j] = 1;
    }
  }
  int ans = 0;
  rep (i, 1<<h) {
    rep (j, 1<<w) {
      int cnt = 0;
      rep(l, h) {
        if ((i>>l)&1 == 1) continue;
        rep (m, w) {
          if ((j>>m)&1 == 1) continue;
          if (v[l][m] == 1) cnt++;
        }
      }
      if (cnt == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>

using namespace std;

int binary_convert(long int n, int *n_ar){
  //int* n_ar;
  //n_ar = (int*)malloc(sizeof(int));
  int i = 0;
  while(n>0){
    n_ar[i++] = n%2;
    n /= 2;
  }
  return i;
}


int main(void){
  long int H;
  cin >> H;


  int *n_array;
  n_array = (int*)malloc(sizeof(int));
  int keta = binary_convert(H, n_array);
  // cout << "keta is "<< keta<<endl;

 long int count = 1;
  for(int i=0; i<keta; i++)
    count *= 2;
  
   cout << count-1 << endl;
  
      return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<vector<int>> dist(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> dist[i][j];
        }
    }
    vector<vector<int>> g = dist;
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    if (dist != g) {
        cout << "-1\n";
    } else {
        int64_t ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == j) {
                    continue;
                }
                bool ok = false;
                for (int k = 0; k < n; ++k) {
                    if (k == j || k == i) {
                        continue;
                    }
                    ok |= dist[i][j] == dist[i][k] + dist[k][j];
                }
                if (!ok) {
                    ans += dist[i][j];
                }
            }
        }
        cout << ans / 2 << '\n';
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string s,t;
  cin >> s;
  t = "CODEFESTIVAL2016";
  
  int ans = 0;
  
  for(int i=0;i<16;i++){
    if(s[i] != t[i])
      ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int H = in.nextInt();
		int W = in.nextInt();
		int h = in.nextInt();
		int w = in.nextInt();
		System.out.println((H-h)*(W-w));
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <unordered_map>
#include <cmath>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)

int main(int argc, char *argv[])
{
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> v;
    Rep(i, N) {
        int c, t;
        cin >> c >> t;
        v.emplace_back(c, t);
    }

    vector<pair<int, int>> a;
    copy_if(v.cbegin(), v.cend(), back_inserter(a), [T](pair<int, int> p){ return p.second <= T; });
    sort(a.begin(), a.end(), [](pair<int, int> l, pair<int, int> r){ return l.first <= r.first;});

    if (a.size() > 0) {
        cout << a[0].first << endl;
    } else {
        cout << "TLE" << endl;
    }

    return 0;
}

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

int n,b,m;

vector<vector<int> > vec;
vector<int> dp;	
	
int solve(int mask)
{
if(dp[mask]!=LLONG_MIN)
	return dp[mask];
// if all the rabbits in mask are 
// in the same group

int res=0;
for(int i=0; i<n; i++)
{
	for(int j=i+1; j<n; j++)
	{
		if((mask&(1LL<<i))&&(mask&(1LL<<j)))
			res+=vec[i][j];
	}
}

// iterate through all submasks now : O(3^n)

for(int i=mask&(mask-1); i; i=(i-1)&mask)
{
res=max(res,solve(i)+solve(i^mask));	
}

return dp[mask]=res;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	vec.assign(n,vector<int>(n));
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n;j++)
		{
			cin>>vec[i][j];
		}
	}
	dp.assign(1LL<<n,LLONG_MIN);
	cout<<solve((1LL<<n)-1);
	return 0;
}


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

N = int(input())
S = list(input())
mod = 10**9+7
from collections import Counter
c = Counter(S)
lis = []
ans = 1
for _, cnt in c.most_common():
    ans *= (cnt+1)
    ans %= mod
print((ans-1)%mod)

Measured memory_bytes: 78236
#include <bits/stdc++.h>
#include <atcoder/all> 
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MAX_A = 300010;

int a;

int op(int x, int y) {return max(x,y);}
int e() {return 0;}

int main() {
	int n, k;
	cin >> n >> k;

	segtree<int, op, e> dp(MAX_A);
	int ans = 0;
	rep(i,n) {
		cin >> a;
		int l = max(0, a-k);
		int r = min(a+k+1, MAX_A);
		int now = dp.prod(l,r) + 1;
		ans = max(ans, now);
		dp.set(a,now);
	}
	cout << dp.prod(0,MAX_A) << endl;
	//cout << n+k << endl;
	return 0;
}

Measured memory_bytes: 8556
#include <stdio.h>

int main(void) {
  int h, w;
  int i, j;

  while(1) {
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0)
      break;
    for(i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
	if (i == 0 || i == h - 1)
	  putchar('#');
	else if (i > 0 && i < h - 1) {
	  if (j == 0 || j == w - 1)
	    putchar('#');
	  else
	    putchar('.');
	    }
      }
      printf("\n");
    }
    printf("\n");
  }
	
	    
  return 0;
}



Measured memory_bytes: 1928
import heapq
import collections
N = int(input())
A = list(map(int, input().split()))

table = collections.defaultdict(int)
hq = [0, 0]
for x in A:
    table[x] += 1
    if table[x] == 2:
        heapq.heappush(hq, -x)
        table[x] = 0
print(heapq.heappop(hq) * heapq.heappop(hq))


Measured memory_bytes: 18592
results = []

while True:
    n = int(input())

    if n == 0:
        break

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

    mean = sum(l) / n

    res = 0
    for i in range(n):
        res += (mean - l[i]) ** 2

    results.append((res/n) ** (1/2))

for result in results:
    print(result)


Measured memory_bytes: 5668
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

ans = [[0] * w for _ in range(h)]
cnt, first = 1, -1
for i in range(h):
    tmp = 0
    if '#' in s[i]:
        if first == -1:
            first = i
        for j in range(w):
            if s[i][j] == '#':
                tmp += 1
                if tmp > 1:
                    cnt += 1
            ans[i][j] = cnt
        cnt += 1
    else:
        if i > 0:
            ans[i] = ans[i - 1][:]

for q in range(first):
    ans[q] = ans[first][:]

for i in range(h):
    print(*ans[i])


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

using namespace std;

#define MAX 16
#define INF 1e9

typedef pair<int,int> pii;
typedef pair<pii,int> piii;

int N,S,G;
int dp[1<<MAX][MAX];
char panels[MAX];

void solve(int s){
  priority_queue<piii,vector<piii>,greater<piii> > Q;
  Q.push(piii(pii(0,s),S));
  
  while(!Q.empty()){
    piii p = Q.top(); Q.pop();
    int cost = p.first.first, v = p.first.second;
    int bit = p.second;

    if(dp[bit][v] < cost) continue;
    for(int i = 0 ; i < N ; i++){
      if(i == v) continue;
      if(((bit >> v) & 1) == ((bit >> i) & 1)) continue;   
      int c = abs(i-v), nS = bit;
      if((nS >> v) & 1){
        nS -= (1<<v);
      }else{
        nS |= (1<<v);
      }
      if((nS >> i) & 1){
        nS -= (1<<i);
      }else{
        nS |= (1<<i);
      }
      if(dp[bit][v] + c < dp[nS][i]){
        dp[nS][i] = dp[bit][v] + c;
        Q.push(piii(pii(dp[nS][i],i),nS));
      }
    }
    for(int i = 0 ; i < N ; i++){
      if(i == v) continue;
      int c = abs(i-v);
      if(dp[bit][v] + c < dp[bit][i]){
        dp[bit][i] = dp[bit][v] + c;
        Q.push(piii(pii(dp[bit][i],i),bit));
      }
    }
  }
}

int main(){
  string in;
  while(cin >> N && N){
    S = G = 0;
    for(int i = 0 ; i < (1<<MAX) ; i++){
      for(int j = 0 ; j < MAX ; j++){
        dp[i][j] = INF;
      }
    }
    for(int i = 0 ; i < 2 ; i++){
      cin >> in;
      for(int j = 0 ; j < N ; j++){
        if(i == 0){
          panels[j] = in[j];
          if(panels[j] == 'W'){
            S |= (1<<j);
          }
        }else{
          if(in[j] == 'W'){
            G |= (1<<j);
          }
        }
      }
    }
   
    for(int i = 0 ; i < N ; i++){
      dp[S][i] = 0;
      solve(i);
    }

    int ans = INF;
    for(int i = 0 ; i < N ; i++){
      ans = min(ans,dp[G][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 8060
#include<stdio.h>
#define M 2000000

int n, A[M+1];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if ( l <= n && A[l] > A[i] ) {
    largest = l;
  }
  
  else largest = i;
  if ( r <= n && A[r] > A[largest] ) {
    largest = r;
  }
  
  if ( largest != i ){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    maxHeapify(largest);
  }
}

main(){
  scanf("%d", &n);
  int i;
  for ( i = 1; i <= n; i++ ){
    scanf("%d", &A[i]);
  }
  
  for ( i = n/2; i >= 1; i-- ) {
    maxHeapify(i);
  }
  
  for ( i = 1; i <= n; i++ ) {
    printf(" %d", A[i]);
  }
  printf("\n");
  

  
  return 0;
}



Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<climits>
#include<random>
using namespace std;
int D=366;
int K=26;
int main()
{
  int d,cc=0,i,j,r,rj,x,x1,x2,time,inf,infk,di,dik,th;
  int c[K],s[D][K],t[D],m[D],l[D][K],res[D],
  t2[D],m2[D],l2[D][K],res2[D];
  bool f;
  random_device seed_gen;
  mt19937 engine(seed_gen());
  uint32_t ra;
  cin >> d;
  for(i=0;i<K;i++){
    cin >> c[i];
    cc+=c[i];
  }
  for(i=1;i<=d;i++)
    for(j=0;j<K;j++)
      cin >> s[i][j];
  fill(l[0],l[0]+K,0);
  m[0]=0;
  res[0]=0;
  di=INT_MAX/(D-1);
  inf=di*(D-1);
  dik=INT_MAX/K;
  infk=dik*K;
  th=(int)(INT_MAX*0.7);
  for(i=1;i<=d;i++){
    r=0;
    rj=-1;
    copy(l[i-1],l[i-1]+K,l[i]);
    for(j=0;j<K;j++)
      if(s[i][j]+c[j]*(i-l[i][j])>r){
        r=s[i][j]+c[j]*(i-l[i][j]);
        rj=j;
      }
    m[i]=m[i-1]+cc-c[rj]*(i-l[i][rj]);
    t[i]=rj;
    l[i][rj]=i;
    res[i]=res[i-1]+s[i][rj]-m[i];
  }
  for(time=0;time<300000;time++){
    ra=engine();
    if(ra>th) f=0;
    else f=1;
    ra=engine();
    while(ra>=inf)
      ra=engine();
    x1=ra/di;
    if(f==1){
      ra=engine();
      while(ra>=inf)
        ra=engine();
      x2=ra/di;
      if(x1==x2)
        continue;
      x=min(x1,x2);
      copy(t,t+D,t2);
      t2[x1]=t[x2];
      t2[x2]=t[x1];
    }else{
      ra=engine();
      while(ra>=infk)
        ra=engine();
      x2=ra/dik;
      x=x1;
      copy(t,t+D,t2);
      t2[x1]=x2;
    }
    copy(m,m+D,m2);
    for(j=0;j<=d;j++)
      copy(l[j],l[j]+K,l2[j]);
    copy(res,res+D,res2);
    for(i=x;i<=d;i++){
      copy(l2[i-1],l2[i-1]+K,l2[i]);
      m2[i]=m2[i-1]+cc-c[t2[i]]*(i-l2[i][t2[i]]);
      l2[i][t2[i]]=i;
      res2[i]=res2[i-1]+s[i][t2[i]]-m2[i];
    }
    if(res2[d]>res[d]){
      copy(t2,t2+D,t);
      copy(m2,m2+D,m);
      for(j=0;j<=d;j++)
        copy(l2[j],l2[j]+K,l[j]);
      copy(res2,res2+D,res);
    }
  }
  for(i=1;i<=d;i++)
    cout << t[i]+1 << endl;
  return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=200000 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5 ;

void work(){
  string s,t;
  cin >> s >> t;
  ll l1=s.length(),l2=t.length();
  ll nx[l1+1][26];
  vl ls(26,-1);
  for(ll i=0;i<26;i++)
    nx[l1][i]=-1;
  for(ll i=l1-1;i>=0;--i){
    ls[s[i]-'a']=i+1;
    for(ll j=0;j<26;j++){
        nx[i][j]=ls[j];
    }
  }
  ll ind,cycle;
  ind=cycle=0;
  for(ll i=0;i<l2;i++){
    if(nx[ind][t[i]-'a']!=-1){
        ind=(nx[ind][t[i]-'a']);
    }
    else{
        cycle++;
        ind=0;
        if(nx[ind][t[i]-'a']!=-1){
            ind=(nx[ind][t[i]-'a']);
        }
        else{
            cout << -1;
            return ;
        }

    }
  }
  cout << l1*cycle+ind;
  return;
}
int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
    // cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 20944
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    double as1 = a/0.08;
    double as2 = b/0.1;
    int ans1 = ceil(as1);
    int ans2 = ceil(as2);
    int k = ans1*0.1;
    int l = ans1*0.08;
    int y = ans2*0.1;
    int z = ans2*0.08;
    int mn = 1000000;
    if(l == a && k == b)
        mn = min(ans1,mn);
    else if(z == a && y == b)
        mn = min(ans2,mn);
    else
        mn = -1;
    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())

a = []
xys = [[] for i in range(n)]

for j in range(n):
    a.append(int(input()))
    for i in range(a[j]):
        xys[j].append(list(map(int,input().split())))


ans = 0
for i in range(1,2**n):
    cont = True
    for j in range(n):
        if (i >> j) & 1 == 1:
            for x,y in xys[j]:
                if (i >> (x-1)) & 1 != y:
                    cont = False
                    break
        if not cont:
            break
    if cont:
        ans = max(ans,bin(i)[2:].count('1'))

print(ans)


Measured memory_bytes: 3064