akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
  n = int(input())
  s = input().strip()
  pc = defaultdict(lambda: 0)
  for i in range(pow(2, n)):
    rd = ""
    bl = ""
    for b in range(n):
      if (i // pow(2, b))%2 == 1:
        rd += s[b]
      else:
        bl += s[b]
    pc[(rd, bl)] += 1

  ans = 0
  s = s[::-1]
  for i in range(pow(2, n)):
    rd = ""
    bl = ""
    for b in range(n):
      if (i // pow(2, b)) % 2 == 1:
        bl += s[b]
      else:
        rd += s[b]
    ans += pc[(rd, bl)]

  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 168060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
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;
}

const ll INF = 1LL << 60;

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

  vector<int> h(n);
  rep(i, n) cin >> h[i];
  
  ll dp[n];
  rep(i, n) dp[i] = INF;
  dp[0] = 0;

  for (int i = 1; i < n; i++) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if (i >= 2) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }

  cout << dp[n - 1] << endl;
  return 0;
}


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

int n, T;
int store[200007];

int main()
{
    cin >> n >> T;

    for (int i = 1; i <= n; i++) scanf("%d", &store[i]);

    //ll cnt = T - store[1];
    ll cnt = 0;
    for (int i = 2; i <= n; i++) {
        if (store[i] - store[i-1] > T) cnt += T;
        else cnt += (store[i] - store[i-1]);
    }
    cnt += T;

    cout << cnt << endl;
}


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

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

    ll total = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 15 == 0) {
            // FizzBuzz
        } else if (i % 3 == 0) {
            // Fizz
        } else if (i % 5 == 0) {
            // Buzz
        } else {
            total += i;
        }
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3632
object Main extends App {
  import scala.io.StdIn.readLine
  
  def dot(arr1:List[Int],arr2:List[Int]):Int = {
  	if(arr1.isEmpty || arr2.isEmpty)return 0
    else return arr1.head * arr2.head + dot(arr1.tail,arr2.tail)
  }
  	val state = readLine.split(" ").map(_.toInt);
  	val bline = readLine.split(" ").map(_.toInt).toList;
  	var aline = (0 until state(0)).map(x => readLine.split(" ").map(_.toInt).toList)
  	println( aline.foldLeft(0)((x,y)=>if(dot(y,bline)> 0 - state(2)){x + 1}else x ).toString )
}

Measured memory_bytes: 54748
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var h = o.l();
  var ans = 0;
  for(var i = 0; i < n;){
    if(h[i] === 0){i++;continue;}
    ans++;
    var j = i;
    while(j < n && h[j])h[j++]--;
  }
  return ans;
}

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll d,i=1;
  while(1)
  {
    cin>>d;
    if(d==0)
    {
      deb(i)
      return 0;
    }
    i++;
  }
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string a, b;
  cin >> a >> b;
  string ans;
  rep(i, a.size()) {
    ans += a[i];
    if (i <= (ll)b.size() - 1) ans += b[i];
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
unordered_map<long long,long long >mp;
long long int ar[200005];
int main()
{
    long long  int n,m,a,b;
    long long int sum=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>ar[i];
        sum^=ar[i];
    }
    for(int i=1; i<=n; i++)
    {
        a=sum^ar[i];
        cout<<a<<' ';
    }
}


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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>

const int N = 1e6 + 1;
const ll mod = 1e9 + 7;

int n;
ll dp[2][2][N];

ll f(int i, int j, int k) {
    if (i == n)
        return j && k ? 1 : 0;
    if (dp[j][k][i] != -1)
        return dp[j][k][i];
    
    ll ans = 0;
    for (int d = 0; d < 10; d++) {
        ll F = f(i + 1, j | (d == 0), k | (d == 9)); 
        ans = (ans + F) % mod;
    }

    return dp[j][k][i] = ans;
}

void solve() {
    cin >> n;
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++)
            fill(dp[i][j], dp[i][j] + n, -1);
    cout << f(0, 0, 0) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 128500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define sz(x) int((x).size())
#define out(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;
typedef pair<ll, ll> p;
typedef map<string, ll> m;
typedef unordered_map<ll, ll> hm;
typedef set<ll> s;
typedef multiset<ll> ms;
typedef queue<ll> q;

int main(){
    string s; cin>>s;
    ll ans = 0;
    for(int bit=0; bit < (1<<(sz(s)-1)); bit++){
        ll tmp = s[0]-'0';
        for(int i=0; i<sz(s)-1; i++){
            if(bit & (1<<i)){
                ans += tmp;
                tmp = s[i+1] - '0';
            }
            else
                tmp = tmp*10 + (s[i+1]-'0');
        }
        ans += tmp;
    }
    out(ans);
}

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

int main(){
	int n;
	cin >> n;
	int even = 0;
	for(int i = 0; i < n; i++){
		int s;
		cin >> s;
		if(s % 2 == 0) even++;
	}
	cout << pow(3, n) - pow(2, even) << endl;
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  int ans;
  if(N<2)ans=1;
  else if(N<4)ans=2;
  else if(N<8)ans=4;
  else if(N<16)ans=8;
  else if(N<32)ans=16;
  else if(N<64)ans=32;
  else ans=64;
  
  cout << ans << endl;
  return 0;  
    

}


Measured memory_bytes: 256
#include <set>
#include <stdio.h>

using namespace std;


int main() {
    int X = 0;
    scanf("%d\n", &X);
    std::set<int> primes;

    if (X == 2) {
        printf("2\n");
        return 0;
    }
    if (X % 2 == 0) {
        X += 1;
    }

    for (int n = 3; n < X*2+1; n+=2) {
        auto end = primes.end();
        bool a = true;
        for (auto it = primes.begin(); it != end; it++) {
            int p = *it;
            if ((n % p) == 0) {
                a = false;
                break;
            }
        }
        if (a) {
            if (n >= X) {
                printf("%d\n", n);
                return 0;
            }
            primes.insert(n);
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  string a = "NSEW";
  int s[4];
  for (int i = 0; i < 4; i++) {
    s[i] = a[i] - 'A';
  }
  string t;
  cin >> t;
  int count[26];
  fill(count, count + 26, 0);
  for (int i = 0; i < t.size(); i++) {
    count[t[i] - 'A']++;
  } 
  if ((count[s[0]] && !count[s[1]]) || (!count[s[0]] && count[s[1]]) || (count[s[2]] && !count[s[3]]) || (!count[s[2]] && count[s[3]])){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*created by tanishk gupta*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define repl(i,a,n) for(long long int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef vector<int> VI;
typedef long long int ll;
typedef unsigned long long ull;
//typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll MOD=1e9+7;
const ll mod=1e9+7;
//const llint MOD;
const ll N=(ll)(1e6+1);
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll add(ll a,ll b){return ((a%MOD)+(b%MOD))%MOD;}
ll mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
ll sub(ll a,ll b){return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll binpow(ll x, ll y){ll z = 1;while(y){if(y & 1) z = mul(z, x);x = mul(x, x);y >>= 1;}return z;}
ll inv(int x){return binpow(x, MOD - 2);}
ll divide(ll x, ll y){return mul(x, inv(y));}
ll fact[N];
void precalc(){fact[0] = 1;for(ll i = 1; i < N; i++)fact[i] = mul(fact[i - 1], i);}
ll C(ll n, ll k){return divide(fact[n], mul(fact[k], fact[n - k]));}
//bool prime[N];
//void sieve() {for(int i=2;i<N;i++) {prime[i]=true;}for (int p=2; p*p<=N; p++){if (prime[p] == true){for (int i=p*p; i<=N; i += p)prime[i] = false;}}}
ll legendpow(ll n, ll p){ll total = 0;while (n){n /= p;total += n;}return total;}

//head==================================================================================



int main()
{
IOS;
precalc();
ll n;
cin>>n;
if (n==1)
{
    cout<<0;
}
else
{
   ll ans=0;
    ans=add(ans,powmod(10,n));
    ans=add(ans,powmod(8,n));
    ans=sub(ans,mul(2,powmod(9,n)));
    cout<<ans;
}

}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	cin >> n;
	int a[n];
	int count=1;
	FOR(i,n)cin >> a[i];
	bool lighted[n];
	lighted[0]=true;
	for(int i=1; i < n;i++)lighted[i]=false;
	int i=a[0]-1;
	while(lighted[i]==false && i!=1){
		lighted[i]=true;
		i=a[i]-1;
		count++;
	}
	if(i!=1) cout << -1;
	else cout << count;

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define per(i,x,y) for (int i=(x); i>=(y); i--)
#define ll long long
#define ld long double
#define inf 1000000000
#define INF 1000000000000000000ll
#define pii pair<int,int>
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sqr(x) ((x)*(x))
#define y1 y1_
#define cmin(x,y) (x)=(y)<(x)?(y):(x)
#define cmax(x,y) (x)=(y)>(x)?(y):(x)
#define mset(x,y) memset((x),(y),sizeof(x))
#define mcpy(x,y) memcpy((x),(y),sizeof(y))
using namespace std;
#define int ll
const ld pi=acos(-1);
const ld eps=1e-8;
//////////////////////// header files ////////////////////////
ll read(){
	char ch=getchar(); ll x=0; int op=1;
	for (; !isdigit(ch); ch=getchar()) if (ch=='-') op=-1;
	for (; isdigit(ch); ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
void write(ll a){
	if (a<0) putchar('-'),a=-a;
	if (a>=10) write(a/10); putchar(a%10+'0');
}
////////////////////////// fast i/o //////////////////////////
#ifdef mod
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x%mod) if (p&1) ret=ret*x%mod;
	return ret;
}
ll get_inv(ll x){
	return ksm(x,mod-2);
}
#else
ll ksm(ll x,ll p){
	ll ret=1;
	for (; p; p>>=1,x=x*x) if (p&1) ret=ret*x;
	return ret;
}
#endif
//////////////////////////// qpow ////////////////////////////
void solve(){
	ll a=read(),b=read(),c,ans;
	if (a>b) swap(a,b);
	if (a==1 && b==1){ cout<<0<<endl; return; }
	//if (a==2 && b==2){ cout<<1<<endl; return; }
	c=a*b-1; c=floor(sqrt(c)); if (c*c>=a*b) c--;
	ans=c*2; if (c*(c+1)>=a*b) ans--;
	if (c>=a) ans--;
	cout<<ans<<endl;
}
//#define local
signed main(){
#ifdef local
	freopen("test.in","r",stdin); freopen("test.out","w",stdout);
#endif
	int T=read(); while (T--) solve();
	return 0;
}
// sample data:
/*

*/

// rest:
/*

*/

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

int main() {

	int n, a[100];

	cin >> n;

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

		cin >> a[i];

	}
	for (int j = 0; j < n;j++) {

		if(j)cout << " ";
		cout << a[n - j - 1];

	}
	cout << endl;
	//cin >> /*変数他*/;
	//cout << /*文字列*/ << endl;
	return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;
bool debug = false;
const int NIL = -1;
const int INF = 1000000000;
const int NUM = 100010;
clock_t START, END;
int A[NUM], L[NUM], length, _j;

void binarysearch(int l, int r, int val) {
	int m = l + (r - l) / 2;
	if (L[0] >= val) {
		_j = 0;
		return;
	}
	if (r - l <= 1) {
		if (L[l] >= val)
			_j = l;
		else if (L[r] < val)
			_j = r + 1;
		else
			_j = r;
		return;
	}
	if (L[m] >= val) {
		binarysearch(l, m, val);
	}
	else {
		binarysearch(m + 1, r, val);
	}
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in29.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	};
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];
	L[0] = A[0];
	length = 0;
	for (int i = 1; i < n; i++) {
		if (L[length] < A[i]) 
			L[++length] = A[i];
		else {
			binarysearch(0, length, A[i]);
			L[_j] = A[i];
		}
	}
	cout << length + 1 << endl;
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
LL L;
string S[MC];
LL ans = 0;

int BS(int x , int y ,int d){
	if(y-x<2) return x;
	int z = (x+y)/2;
	return S[z][d] == '0' ? BS(z,y,d) : BS(x,z,d);
}

void dfs(int x , int y , LL d){
	if(x==y){
		LL z = L - d;
		ans ^= (z&-z);
		return;
	}
	if(x+1==y && S[x].size() == d+1) return;
	int z = BS(x-1,y,d+1);
	dfs(x,z+1,d+1);
	dfs(z+1,y,d+1);
}

int main(){
	cin >> N >> L;
	repp(i,0,N) cin >> S[i];
	sort(S,S+N);
	int z = BS(-1,N,0);
	dfs(0,z+1,0);
	dfs(z+1,N,0);
	cout << (ans ? "Alice" : "Bob") << endl;
	return 0;
}


Measured memory_bytes: 4352
h,w,d=map(int,input().split())
a=[]
box=[[] for i in range(h*w+1)]
wi=0
for i in range(h):
    ai=list(map(int,input().split()))
    for j in range(w):
        box[ai[j]]=[i,j]

p=[0]
for i in range(1,h*w+1):
    if(i-d>0):
        p.append(p[i-d]+abs(box[i][0]-box[i-d][0])+abs(box[i][1]-box[i-d][1]))
    else:
        p.append(0)

q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(p[r]-p[l])


Measured memory_bytes: 17268
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;


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

int main()
{
	int w,h;
	while(cin>>w>>h,w||h){
		vector<string> p(h);
		for(int i=0;i<h;i++) cin>>p[i];

		int resB=0,resW=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				bool black=false,white=false;
				if(p[i][j]=='.'){
					vector<vector<bool> > vis(h,vector<bool>(w,false));
					queue<pair<int,int> > q;
					q.push(make_pair(i,j));

					while(!q.empty()){
						int y=q.front().first,x=q.front().second;
						q.pop();
						if(vis[y][x]) continue;

						vis[y][x]=true;

						if(p[y][x]=='W'){ white=true; continue;}
						if(p[y][x]=='B'){ black=true; continue;}

						for(int k=0;k<4;k++){
							int ny=y+dy[k],nx=x+dx[k];
							if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
							q.push(make_pair(ny,nx));
						}
					}

				}
/*
				cout<<i<<" "<<j<<":";
				if(black) cout<<"B";
				if(white) cout<<"W";
				cout<<endl;
*/
				if(black && !white) resB++;
				if(!black && white) resW++;
			}
		}

		cout<<resB<<" "<<resW<<endl;

	}

	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define RFOR(i,s,e) for(int (i) = (s);(i) >= (e);(i)--)
#define rep(i,n) FOR(i,0,n-1)

signed main() {
    int a[3];cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);

    cout << a[2]*10+a[1]+a[0] << endl;



}


Measured memory_bytes: 764
#!/usr/bin/env python3
n = int(input())
ans = 0


def gcd(n, m):
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    return b


for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(k, gcd(i, j))
print(ans)


Measured memory_bytes: 79892
n,h,w = map(int,input().split())
a=[]
b=[]
for _ in range(n):
    aa,bb = map(int,input().split())
    a.append(aa)
    b.append(bb)
ans = 0
for i in range(n):
    ans += min(a[i]//h,b[i]//w)**2
print(ans)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: i64,
    }
    if n % 2 == 1 {
        puts!("0\n");
    } else {
        let mut sum = 0;
        let mut v = n / 10;
        while v > 0 {
            sum += v;
            v /= 5;
        }
        puts!("{}\n", sum);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
def e_golf(K, X, Y):
    # 参考: https://babcs2035.hateblo.jp/entry/2019/07/29/AtCoder_Beginner_Contest_135：E_-_Golf
    # 参考: https://atcoder.jp/contests/abc135/submissions/6607612

    # x >= y >= 0 となるようにどのような座標変換を行ったか
    is_xpos_negative = is_ypos_negative = is_swap = False
    x, y = X, Y
    if x < 0:
        x *= -1
        is_xpos_negative = True
    if y < 0:
        y *= -1
        is_ypos_negative = True
    if x < y:
        x, y = y, x
        is_swap = True

    if (x + y) % 2 == 1 and K % 2 == 0:
        return -1  # ゴールできない

    ans = []
    shot_min = max((x + y + K - 1) // K, 2)
    if (x + y) % 2 != (shot_min * K) % 2:
        shot_min += 1
    if x + y == K:
        ans.append((x, y))
    elif shot_min == 3 and x < K:
        mid = (K + x - y) // 2
        ans.extend(((x, x - K), (x + mid, y - K + mid), (x, y)))
    else:
        over = (shot_min * K - x - y) // 2
        for i in range(1, shot_min + 1):
            d = i * K
            if d <= y + over:
                ans.append((0, d))
            elif d <= y + over + x:
                ans.append((d - y - over, y + over))
            else:
                ans.append((x, y + (shot_min - i) * K))

    # 座標変換をしていた場合、元に戻す
    if is_swap:
        ans = [(second, first) for first, second in ans]
    if is_xpos_negative:
        ans = [(-first, second) for first, second in ans]
    if is_ypos_negative:
        ans = [(first, -second) for first, second in ans]
    return '\n'.join([str(len(ans))] + ['{} {}'.format(f, s) for f, s in ans])

K = int(input())
X, Y = [int(i) for i in input().split()]
print(e_golf(K, X, Y))

Measured memory_bytes: 42340
#include<stdio.h>

int main(){

  int A[100],i,j,n,cnt=0,minj,temp;


  scanf("%d",&n);

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

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j]<A[minj]){
	minj=j;

      }
    }
    if(i!=minj){
        temp=A[i];
	A[i]=A[minj];
	A[minj]=temp;
	cnt++;
    }
  }

  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",cnt);

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


signed main(){
	char X, Y;
	cin >> X >> Y;

	if(X == Y) cout << '=' << endl;
	else if(X < Y) cout << '<' << endl;
	else cout << '>' << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

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

    vector<int> H(N+1);
    for(int i = 1;i <= N;i++)
        cin>>H[i];

    int left = 1;
    int right = left+1;
    int ans = 0;
    while(left < N) {
        int temp = 0;
        while(H[left] >= H[right] && right <= N) {
            temp++;
            right++;
            left++;
        }
        ans = max(temp,ans);
        left++;
        right++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=s.size();
    if(s=="keyence"){
        coutY; return 0;
    }
    for(int i=0; i<n-1; i++){
        for(int j=i; j<n; j++){
            string t=s;
            t.erase(i,j-i+1);
            if(t=="keyence"){
                coutY; return 0;
            }
        }
    }
    coutN;
}

Measured memory_bytes: 3600
def comb(a,b):
    import math
    return math.factorial(a)//(math.factorial(a-b)*math.factorial(b))
N,M = map(int,input().split())
ans = 0
if N > 1:
    ans += comb(N,2)
if M > 1:
    ans += comb(M,2)

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define LL long long
using namespace std;
//int P=998244353;
//inline int ad(int x,int y){return (x+y>=P)?(x+y-P):(x+y);}
//inline int mt(int x,int y){LL rt=1ll*x*y; rt=(rt>=P)?(rt%P):rt; return rt;}
//inline void mo(int &x){x=(x>=P)?(x-P):x; x=(x<0)?(x+P):x;}
template<typename T>inline void ckmx(T &x,T &y){x=max(x,y);}
template<typename T>inline void ckmi(T &x,T &y){x=min(x,y);}
template<typename T>void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-48;
	x*=f;
}
int n,m,k;
vector<int>e[200010];
int hs[200010];
struct ha{int l,r;};
bool operator <(ha x,ha y){
	return x.l<y.l;
} 
set<ha>st;
set<ha>::iterator it,tt;
int main(){
	read(n);read(m);read(k);
	for(int i=1;i<=k;++i){
		int x,y;
		read(x);read(y);
		if(y<=x) e[x].push_back(y);
	}
	int la=1;
	st.insert((ha){1,1});
	for(int i=2;i<=n;++i){
		int si=e[i].size();
		if(si){
			int ad=i-la-1;
			la=i;
			if(ad)
			for(it=st.begin();it!=st.end();tt=it,++it){
				if(it!=st.begin()) if(tt->r>=it->l) {
					ha cg=(ha){tt->l,it->r};
					st.erase(it);
					st.erase(tt);
					st.insert(cg);
					it=st.find(cg);
				}
				ha cg=(ha){it->l,it->r+ad};
				st.erase(it);
				st.insert(cg);
				it=st.find(cg);
			}
			it=st.begin();
			for(int j=0;j<si;++j){
				int pos=e[i][j];
				while(it!=st.end()&&it->r<pos) ++it;
				if(it==st.end()) break;
				if(pos>=it->l) {cout<<i-1<<endl;return 0;}
			}
			for(int j=0;j<si;++j){
				int pos=e[i][j];
				++hs[pos];
			}
			for(it=st.begin();it!=st.end();tt=it,++it){
				if(it!=st.begin()) if(tt->r>=it->l) {
					ha cg=(ha){tt->l,it->r};
					st.erase(it);
					st.erase(tt);
					st.insert(cg);
					it=st.find(cg);
				}
				if(!hs[(it->r)+1]) {
					ha cg=(ha){it->l,it->r+1};
					st.erase(it);
					st.insert(cg);	
					it=st.find(cg);
				}
			}
			for(int j=0;j<si;++j){
				int pos=e[i][j];
				--hs[pos];
			}
		}
	}
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 10624
/* http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0500 */

import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args){
		try{
			Scanner s = new Scanner(System.in);
			
			while(true){
				int n = s.nextInt();
				if(n==0){ break; }
				
				int aScore = 0;
				int bScore = 0;
				
				for(int i=0;i<n;i++){
					int a = s.nextInt();
					int b = s.nextInt();
					
					if(a>b){
						aScore += a+b;
					}else if(a<b){
						bScore += a+b;
					}else{
						aScore += a;
						bScore += b;
					}
				}
				
				System.out.println(aScore + " " + bScore);
			}

		}catch(Exception e){
			e.printStackTrace(System.out);
		}
	}
}

Measured memory_bytes: 51704
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

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

int main(){
    int n;
    int ke[100009];
    int ko[100009];
    cin>>n;
    vector<int> v(n);
    rep(i,100009){
        ke[i]=0;
        ko[i]=0;
    }
    rep(i,n){
        cin>>v[i];
        if(i%2==0) ke[v[i]]++;
        else ko[v[i]]++;
    }
    vector<pair<int,int>> mo(1,make_pair(0,0));
    vector<pair<int,int>> me(1,make_pair(0,0));
    rep(i,100009){
        if(ke[i]>=1) me.push_back(make_pair(ke[i],i));
        if(ko[i]>=1) mo.push_back(make_pair(ko[i],i));
    }
    sort(me.begin(),me.end(),greater<pair<int,int>>());
    sort(mo.begin(),mo.end(),greater<pair<int,int>>());
    ll ans;
    if(me[0].second!=mo[0].second){
        ans = n - (me[0].first+mo[0].first);
    }else if((me[0].first-me[1].first)<=(mo[0].first-mo[1].first)){
        ans = n - (me[1].first+mo[0].first);
    }else if((me[0].first-me[1].first)>(mo[0].first-mo[1].first)){
        ans = n - (me[0].first+mo[1].first);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2428
n,e[28],sep[7];
connect(d){
	int i,x;
	sep[d]=0;
	for(i=0;i<n;i++){
		if(e[i]/10==d){
			x=e[i]%10;
			if(sep[x])
				connect(x);
		}
		if(e[i]%10==d){
			x=e[i]/10;
			if(sep[x])
				connect(x);
		}
	}
}
main(){
	int i,b,d,ng;
	for(;~scanf("%d",&n);){
		b=0;
		memset(sep,0,sizeof(sep));
		for(i=n;i--;){
			scanf("%d",&d);
			e[i]=d;
			b^=1<<d/10;
			b^=1<<d%10;
			sep[d/10]=sep[d%10]=1;
		}
		connect(e[0]/10);
		ng=0;
		for(i=0;i<7;i++)
			ng|=sep[i];
		for(d=0;b;d++)
			b&=b-1;
		puts(!ng&&(d==0||d==2)?"Yes":"No");
	}
}

Measured memory_bytes: 0
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
s = sum(a)
for i in range(n):
  if a[i] >= s * 1 / 4 / m:
    cnt += 1
if cnt >= m:
  print("Yes")
else:
  print("No")

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

using namespace std;

int main(){
    string S;
    cin >> S;
    bool ans = true;
    int count=0,count1=0;
    
    if(S.front()!='A') ans = false;
    for(int i=2;i<S.size()-1;i++){
        if(S.at(i)=='C') count++;
    }
    if(count!=1) ans = false;
    for(int i=0;i<S.size();i++){
        if(islower(S.at(i))==0) count1++;
    }
    if(count1!=2) ans = false;

    cout << (ans==true ? "AC" : "WA") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator<(const Puzzle &p) const{
    for (int i = 0; i < N2; i++){
      if (f[i] == p.f[i])
        continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p){
  for (int i = 0; i < N2; i++){
    if (p.f[i] != (i + 1)){
      return false;
    }
  }
  return true;
}

string bfs(Puzzle s){
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;

    while (!Q.empty()){
      u = Q.front();
      Q.pop();
        if (isTarget(u))
            return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for (int r = 0; r < 4; r++){
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if (tx < 0 || ty < 0 || tx >= N || ty >= N)
                continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if (!V[v]){
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    return "unsolvable";
}

int main(){
    Puzzle in;

    for (int i=0; i < N2; i++){
        cin >> in.f[i];
        if (in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    string ans = bfs(in);
    cout << ans.size() << endl;

    return 0;
}



Measured memory_bytes: 30524
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for (int i=0; i < (n); i++)
#define fi first
#define se second
typedef double D; 
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9; 
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1; 
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;
  return 0;
}
bool isecSP(P a1, P a2, P b) {
  return !ccw(a1, a2, b);
}
bool isecSS(P a1, P a2, P b1, P b2) {
  if(a1==b1&&!isecSP(a1,a2,b2)||a1==b2&&!isecSP(a1,a2,b1)||a2==b1&&!isecSP(a1,a2,b2)||a2==b2&&!isecSP(a1,a2,b1))return 0;
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
string s[101];
double x,y;
vector<int>a[101],aa[12];
int color[11],ans,n,used[101],yy;
void dfs(int p,int d){
  if(d+1>=ans)return ;
  if(p==n){
    ans=min(ans,d+1);
    return;
  }
  int y[12]={},pp=0,pe;
  r(j,aa[p].size())y[aa[p][j]]=1;
  for(int i=0;i<d+2;i++){
    int f=0;
    r(j,12)if(y[j]&&color[j]==i)f++;
    if(!f){
      color[p]=i;
      if(i==d+1)dfs(p+1,d+1);
      else dfs(p+1,d);
      color[p]=11;
    }
  }
}
int main(){
  while(cin>>n,n){
    ans=1e9;yy=n;
    r(i,11)color[i]=11;
    r(i,12)aa[i].clear();
    r(i,101)a[i].clear();
    VP v[n];
    for(int i=0;i<yy;i++){
      cin>>s[i];
        while(cin>>x,x!=-1){
          cin>>y;
          v[i].push_back(P(x,y));
        }
    }
    r(i,n)r(j,v[i].size())
      r(k,n)if(i!=k)r(l,v[k].size())
        if(isecSS(v[i][j],v[i][(j+1)%(int)v[i].size()],v[k][l],v[k][(l+1)%(int)v[k].size()]))
          a[i].push_back(k);
    r(i,n)sort(a[i].begin(),a[i].end());
    r(i,n)a[i].erase(unique(a[i].begin(),a[i].end()),a[i].end());
    //r(i,n)cout<<a[i].size()<<endl;
    int c=0;
    map<int,int>m;
    memset(used,0,sizeof(used));
    r(i,yy)if(!used[i]){
      used[i]=1;
      r(j,yy)if(!used[j]&&s[i]==s[j]){
        used[j]=1;
        m[j]=c;
        r(k,a[j].size())aa[c].push_back(a[j][k]);
        n--;
      }
      m[i]=c;
      r(k,a[i].size())aa[c].push_back(a[i][k]);
      c++;
    }
    r(i,n)r(j,aa[i].size())aa[i][j]=m[aa[i][j]];
    r(i,n)sort(aa[i].begin(),aa[i].end());
    r(i,n)aa[i].erase(unique(aa[i].begin(),aa[i].end()),aa[i].end());
    color[0]=0;
    //r(i,aa[0].size())cout<<"    "<<aa[0][i]<<endl;
    dfs(1,0);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3340
#include <iostream>
using namespace std;
int main()
{
    int n,a,b,c,d;
    cin>>n;
    a=n/1000;
    b=(n-a*1000)/100;
    d=n%10;
    c=(n-1000*a-100*b)/10;
    if(a+b+c+d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
    }
    else if(a+b+c-d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
    }
    else if(a+b-c+d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
    }
    else if(a+b-c-d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
    }
    else if(a-b+c+d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
    }
    else if(a-b+c-d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
    }
    else if(a-b-c+d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
    }
    else if(a-b-c-d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, a, b;
    cin >> n;
    vector<int> p(n), q(n);
    REP(i, n) cin >> p[i];
    REP(i, n) cin >> q[i];

    vector<int> t(n);
    REP(i, n) t[i] = i+1;
    int cnt = 1;
    do {
        bool ok_p = 1;
        bool ok_q = 1;
        REP(i, n) if (t[i] != p[i]) ok_p = 0;
        REP(i, n) if (t[i] != q[i]) ok_q = 0;
        if (ok_p) a = cnt;
        if (ok_q) b = cnt;
        cnt++; 
    } while(next_permutation(ALL(t)));

    cout << abs(a-b) << endl;
    

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FR first
#define SE second
using namespace std;
const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0,fg=1;char c=Get();
    while(!isdigit(c)&&c!='-') c=Get();
    if(c=='-') fg=-1,c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x*fg;
}
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const int N=200010;
int n,V,X[N],dep=0;
int L[20][N],R[20][N];
int exL[N<<4],exR[N<<4];
pii seg[N];
bool ans[N];
int main()
{
    n=read();V=read();
    for(int i=1;i<=n;i++) X[i]=read();
    X[0]=-INF-V-1;X[n+1]=INF+V+1;
    for(int v=V;v>=0;v>>=1,dep++)
    {
        R[dep][n+1]=n+1;
        for(int i=1;i<=n;i++) L[dep][i]=(X[i]-X[i-1]<=v)?L[dep][i-1]:i;
        for(int i=n;i>=1;i--) R[dep][i]=(X[i+1]-X[i]<=v)?R[dep][i+1]:i;
        if(v==0){dep++;break;}
    }
    for(int i=1;i<=n;i++) seg[i]=pii(L[0][i],R[0][i]);
    int cnt=unique(seg+1,seg+1+n)-(seg+1);
    for(int i=0;i<(1<<dep);i++) exR[i]=n+1;
    for(int s=0;s<(1<<dep);s+=2)
        for(int i=0;i<dep;i++)
        {
            if(!(s&(1<<i))) continue;
            exL[s]=max(exL[s],R[i][exL[s^(1<<i)]+1]);
            exR[s]=min(exR[s],L[i][exR[s^(1<<i)]-1]);
        }
    if(cnt>dep) goto output;
    for(int i=1;i<=cnt;i++)
        for(int s=0;s<(1<<dep);s+=2)
            if(exL[s]>=seg[i].FR-1&&exR[(1<<dep)-1-s-1]<=seg[i].SE+1)
            {
                for(int j=seg[i].FR;j<=seg[i].SE;j++) ans[j]=1;
                break;
            }
    output: for(int i=1;i<=n;i++) puts(ans[i]?"Possible":"Impossible");
    return 0;
}

Measured memory_bytes: 43648
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

const char table[5][7] = {"afkpuz", "bglqv.", "chmrw?", "dinsx!", "ejoty "};

bool indexcheck(char *s)
{
  int i;
  
  for (i = 0; s[i] != '\0'; i += 2){
    if (!('1' <= s[i] && s[i] <= '6' && '1' <= s[i + 1] && s[i + 1] <= '5')){
      return false;
    }
  }

  return true;
}

int main(void)
{
  char s[256];

  while (~scanf("%s", s)){
    int i;
    if (strlen(s) % 2 != 0 || !indexcheck(s)){
      puts("NA");
      continue;
    }
    
    for (i = 0; s[i] != '\0'; i += 2){
      printf("%c", table[s[i + 1] - '0' - 1][s[i] - '0' - 1]);
    }
    puts("");
  }

  return 0;
}

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

void fun(int,int,int);
void print(int);
int len[30];

int main()
{
	int n;

	while(cin >> n && n){
		for(int i = 0; i < 30; i++){
			len[i] = 0;
		}
		fun(0,n,0);
	}

	return 0;
}

void fun(int total,int n,int cnt){

	if(total == n){
		print(cnt-1);
	}
	
	for(int i = n; i > 0; i--){
		if(i <= n-total && (cnt == 0 || len[cnt-1] >= i) ){
			len[cnt] = i;
			fun(total+i,n,cnt+1);
		}
	}
}

void print(int c){
	for(int i = 0; i < c; i++){
		printf("%d ",len[i]);
	}
	printf("%d\n",len[c]);
}

Measured memory_bytes: 1148
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    T = LI()
    A = LI()
    B = LI()

    p1 = (A[0] - B[0]) * T[0]
    p2 = p1 + (A[1] - B[1]) * T[1]
    if p1 * p2 > 0:
        print(0)
        return
    elif p2 == 0:
        print('infinity')
        return

    ans = 1
    if p2 + p1 == 0:
        print(2)
        return
    p2 = abs(p2)
    p1 = abs(p1)
    if p2 > p1:
        print(1)
        return
    if p1 % p2 == 0:
        ans -= 1
    ans += (p1 // p2) * 2
    print(ans)

if __name__ == '__main__':
    main()

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

ans = 0
for i in range(1,n+1)[::-1]:
	head = str(i)[0]
	tail = str(i)[-1]
	length = len(str(i))
	if tail == '0':
		continue
	if head == tail:
		if length == 1:
			ans += 1
		elif length == 2:
			ans += 3
		else:
			ans += 3
			for j in range(3,length+1):
				if length > j:
					ans += 10**(j-2) * 2
				else:
					ans += 2 * (int(str(i)[1:length-1]) + 1)
	elif head < tail:
		if length > 2:
			ans += int('1' * (length-2)) * 2
	else:
		if length > 1:
			ans += int('1' * (length-1)) * 2
print(ans)


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

string s, t = "2019/04/30";


signed main()
{
    cin >> s;
    if(s <= t)printf("Heisei\n");
    else printf("TBD\n");


    return 0;
}


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

const int MAXN = 1e6 + 3;
int n, c, k;
int T[MAXN];

int main() {
  ios_base::sync_with_stdio(false);
  int res = 0;
  cin >> n >> c >> k;
  for(int i = 1; i <= n; i++) {
    cin >> T[i];
  }
  sort(T + 1, T + 1 + n);
  int last = -1e9, in_it = 0;
  for(int i = 1; i <= n; i++) {
    if(in_it == c || T[i] > last + k) {
      res++;
      in_it = 1;
      last = T[i];
    } else {
      in_it++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640