akhauriyash/Code-Regression huggingface dataset:
def main()->None:
    # todo:1.入力に同じ値があった時にどうするかの考慮漏れをどうするか
    #      2.while と配列へのアクセスによって時間がかかってる。差が大きくなればなるほどアクセス回数増える。
    l = list(map(int, input().split()))
    l.sort()
    # 最大値l[2]からの差を考える。
    l[0] = l[2] - l[0]
    l[1] = l[2] - l[1]
    l[2] = 0
    
    # l[１]から見ていく
    count = 0
    while True:
        if l[1] - 2 < 0:
            if l[1] == 0:
                break
            else:
                l[1] -= 1
                l[0] -= 1
                count += 1
                break
        l[1] -= 2
        count += 1

    # l[0]について
    while True:
        if l[0] <= 0:
            if l[0] == 0:
                flag = True
                break
            if l[0] < 0:
                count += 1
                break
        l[0] -= 2
        count += 1
    print(count)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_C&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        H, W = map(int, input().split())
        if H == 0 and W == 0:
            break

        for y in range(H):
            if y % 2 == 0:
                row = '#.' * W
            else:
                row = '.#' * W

            row = row[:W]
            print(row)
        print()


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7768
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
dp=[float('inf') for _ in range(n)]
dp[0]=0

def chmin(a,b):
    if a>b:
        a=b
        return True
    return False

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


print(dp[n-1])

Measured memory_bytes: 56800
import sys
readline = sys.stdin.readline

A,B,C,D = readline().rstrip()

import itertools
for cal in itertools.product(["+","-"],repeat = 3):
  f = A + cal[0] + B + cal[1] + C + cal[2] + D
  if eval(f) == 7:
    print(f + "=7")
    break

Measured memory_bytes: 9124
#!/usr/bin/env python3


def solv(s):
    if s[0] == s[1]:
        return 'Bad'
    if s[1] == s[2]:
        return 'Bad'
    if s[2] == s[3]:
        return 'Bad'
    return 'Good'


if __name__ == '__main__':

    s = input()

    ans = solv(s)

    print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <vector>

#define size_t long

using namespace std;

long f(long x0, long x1, long X, long y0, long y1, long Y) {
  return abs(x1 - X) - abs(x0 - X) + abs(y1 - Y) - abs(y0 - Y);
}

int main(int argc, char const *argv[]) {
  long N;
  scanf("%ld", &N);
  long x[N];
  long y[N];
  long h[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%ld %ld %ld", &x[i], &y[i], &h[i]);
  }
  long Cx = -1;
  long Cy = -1;
  long H;
  int zzz;
  for (size_t i = 0; i < N; i++) {
    if (h[i] != 0) {
      zzz = i;
      break;
    }
  }
  for (size_t i = 0; i <= 100; i++) {
    for (size_t j = 0; j <= 100; j++) {
      std::vector<int> v;
      for (size_t n = N - 1; n >= 0; n--) {        // if (zzz) {
        if (n == zzz) {
          if (n == 0) {
            H = h[zzz] + abs(x[zzz] - Cx) + abs(y[zzz] - Cy);
            for (size_t q = 0; q < v.size(); q++) {
              if (H - abs(x[v[q]] - Cx) - abs(y[v[q]] - Cy) > 0) {
                goto X;
              }
            }
            // for (size_t q = 0; q < N; q++) {
            //   if (/* condition */) {
            //     /* code */
            //   }
            // }
            goto A;
            X:
            int defeg;
          }
          continue;
        }
        if (h[n] == 0) {
          v.push_back(n);
          if (n == 0) {
            H = h[zzz] + abs(x[zzz] - Cx) + abs(y[zzz] - Cy);
            for (size_t q = 0; q < v.size(); q++) {
              if (H - abs(x[v[q]] - Cx) - abs(y[v[q]] - Cy) > 0) {
                goto Y;
              }
            }
            goto A;
            Y:
            int dfea;
          }
          // printf("n = %ld\n", n);
        } else if (f(x[zzz], x[n], i, y[zzz], y[n], j) == h[zzz] - h[n]) {
          // prlongf("%d %d %d\n", i, j, n);
          Cx = i;
          Cy = j;
          // printf("%d %d\n", i, j);
          if (n == 0) {
            H = h[zzz] + abs(x[zzz] - Cx) + abs(y[zzz] - Cy);
            for (size_t q = 0; q < v.size(); q++) {
              if (H - abs(x[v[q]] - Cx) - abs(y[v[q]] - Cy) > 0) {
                goto B;
              }
            }
            // for (size_t q = 0; q < N; q++) {
            //   if (/* condition */) {
            //     /* code */
            //   }
            // }
            goto A;
            B:
            int defeg;
          }
        } else {
          break;
        }
      }
      // if (f(x[0], x[1], i, y[0], y[1], j) == h[0] - h[1]) {
      //   if (f(x[0], x[1], i, y[0], y[1], j) == h[0] - h[1]) {
      //     /* code */
      //   }
      //   prlongf("%d %d\n", i, j);
      //   Cx = i;
      //   Cy = j;
      //   goto A;
      // }
    }
  }
  A:
  if (Cx == -1 || Cy == -1) {
    Cx = x[zzz]; Cy = y[zzz];
  }
  H = h[zzz] + abs(x[zzz] - Cx) + abs(y[zzz] - Cy);
  printf("%ld %ld %ld\n", Cx, Cy, H);
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define NIL -1
typedef struct {
  int parent;
  int lchild;
  int rchild;
} Node;
Node t[25];
void preParse(int);
void inParse(int);
void postParse(int);

int main()
{
  int n,i,id,right,left;
  scanf("%d",&n);
  for(i=0; i<n; i++) t[i].parent=NIL;
  for(i=0; i<n; i++) {
    scanf("%d%d%d",&id,&left,&right);
    t[id].lchild=left; t[id].rchild=right;
    if(left!=NIL) t[left].parent=id;
    if(right!=NIL) t[right].parent=id;
  }

  for(i=0; ; i++) {
    if(t[i].parent==NIL) {
      printf("Preorder\n");
      preParse(i);
      printf("\nInorder\n");
      inParse(i);
      printf("\nPostorder\n");
      postParse(i);
      printf("\n");
      break;
    }
  }
  return 0;
}

void preParse(int u)
{
  if(u==NIL)  return;
  printf(" %d",u);
  preParse(t[u].lchild);
  preParse(t[u].rchild);
}

void inParse(int u)
{
  if(u==NIL) return;
  inParse(t[u].lchild);
  printf(" %d",u);
  inParse(t[u].rchild);
}

void postParse(int u)
{
  if(u==NIL) return;
  postParse(t[u].lchild);
  postParse(t[u].rchild);
  printf(" %d",u);
}

Measured memory_bytes: 616
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t  ll;
typedef uint64_t ull;

#define rep(i,n)   for (int i = 0; i < (n); i++)
#define rrep(i,n)  for (int i = (n)-1; i >= 0; i--)
#define rep1(i,n)  for (int i = 1; i <= (n); i++)
#define rrep1(i,n) for (int i = (n); i > 0; i--)

int main(void) {
    int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

int main(void){
	int N, K;
	cin >> N >> K;
	int A[N];
	for (int i = 0; i < N; i++) cin >> A[i];
	int B[N+1];
	
	int count = 0;
	while (count < K){
		for (int i = 0; i < N; i++) B[i] = 0;

		for (int i = 0; i < N; i++) {
			int xmin = max(i-A[i], 0);
			int xmax = min(i+A[i]+1, N);
			B[xmin]++;
			B[xmax]--;

		}

		for (int i = 0; i < N; i++) {
			B[i+1] += B[i];
		}
		
		int tot = 0;
		for (int i = 0; i < N; i++) {
			A[i] = B[i];
			tot += A[i];
		}
		if (tot == N*N) break;

		count++;
	}
	
	for (int i = 0; i < N; i++) cout << A[i] << " ";
	cout << endl;

return 0;
}

Measured memory_bytes: 5128
#include <iostream>
//#include <math.h>
#include <string>
//#include <time.h>
//#include <conio.h>
using namespace std;

int alpha[28];
int main()
{
	string str;
	cin >> str;
	for (int i = 0; i < str.size(); i++)
		alpha[(int)str[i] - 97]++;


	for (int i = 0; i < 26;i++)
		if (alpha[i] == 0)
		{
			cout << (char)(i + 97);
		
			return 0;
			break;
		}
	cout << "None";
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int n, q;
  string s;
  cin >> n >> q >> s;

  vector<int> sum(n + 1);
  for (int i = 2; i <= n; ++i) {
    if (s[i - 2] == 'A' and s[i - 1] == 'C') {
      sum[i] = 1;
    }

    sum[i] += sum[i - 1];
  }

  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << sum[r] - sum[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1488
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int n,m,u,v;
vector<int> ga[100100];
int deg[100100];
int dp[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		ga[u].push_back(v);
		deg[v]++;
	}
	queue<int> q;
	for(int i=1;i<=n;i++)
		if(deg[i]==0)
			q.push(i);
	while(q.size()){
		int c=q.front();
		q.pop();
		for(int i=0;i<ga[c].size();i++){
			int d=ga[c][i];
			deg[d]--;
			dp[d]=max(dp[d],dp[c]+1);
			if(deg[d]==0)
				q.push(d);
		}
	}
	cout<<*max_element(dp+1,dp+n+1)<<endl;
	return 0;
}


Measured memory_bytes: 6528
from collections import Counter
from itertools import combinations

N = int(input())
L = Counter(list(map(int, input().split())))
ans = 0
for a, b, c in combinations(L.keys(), 3):
    if a+b>c and b+c>a and c+a>b:
        ans += L[a]*L[b]*L[c]
print(ans)

Measured memory_bytes: 74064
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld",&n);
  int g=0;
  while(n!=0){
    n/=2;
    g++;
  }
  long long ans=0;
  long long b=1;
  for(int i=1;i<=g;i++){
    ans+=b;
    b*=2;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

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

vector<string> vec{};
rep(i, n){
	string s;
	cin>>s;
	vec.push_back(s);
}

sort(ALL(vec));
string ans="";
rrep(i, n){
	string y=vec[i];
	ans+=y;
}

cout<<ans<<endl;
return 0;




}




Measured memory_bytes: 256
def main():
  import sys
  input = sys.stdin.buffer.readline
  n,m=map(int,input().split())
  a,w,l,k=0,0,[0]*n,[0]*m
  for _ in k:
    p,s=input().split()
    p=int(p)-1
    if l[p]>=0:
      if s==b'AC':
        a+=1
        w+=l[p]
        l[p]=-1
      else:
        l[p]+=1
  print(a,w)
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 4596
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-29 16:19:39
 **/

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

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

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

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

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

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

#pragma endregion kyomukyomupurin

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

  int n; cin >> n;
  map<string, int> cnt;

  while (n--) {
    string s; cin >> s;
    ++cnt[s];
  }

  int mx = 0;

  for (auto e : cnt) mx = max(mx, e.second);
  for (auto e : cnt) {
    if (e.second == mx) {
      cout << e.first << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 23808
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int A = Integer.parseInt(S[0]);
    int B = Integer.parseInt(S[1]);
    String T = sc.nextLine();
    
    System.out.println(T.matches("[0-9]{"+A+"}-[0-9]{"+B+"}") ? "Yes" : "No");
  }
}

Measured memory_bytes: 21972
#include<cstdio>
#include<bitset>
#include<algorithm>
using namespace std;
const int MAXN=505,MAXM=100005;

int N,M;
bitset<MAXN> alive[MAXN];
bool dead[MAXN];
int x[MAXM],y[MAXM];

int main()
{
	scanf("%d%d",&N,&M);
	for(int i=1;i<=M;i++)
		scanf("%d%d",&x[i],&y[i]);
	for(int i=1;i<=N;i++)
	{
		alive[i][i]=1;
		for(int j=M;j>=1;j--)
			if(alive[i][x[j]]&&alive[i][y[j]])
			{
				dead[i]=true;
				break;
			}
			else if(alive[i][x[j]])
				alive[i][y[j]]=1;
			else if(alive[i][y[j]])
				alive[i][x[j]]=1;
	}
	int ans=0;
	for(int i=1;i<=N;i++)
		for(int j=i+1;j<=N;j++)
			if(!dead[i]&&!dead[j]&&(alive[i]&alive[j]).none())
				ans++;
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
using ll = long long;

int main() {
  int x;
  cin >> x;
  for (ll a = -200; a < 200; ++a)
    for (ll b = -200; b < 200; ++b)
      if (a * a * a * a * a - b * b * b * b * b==x) {
        cout << a << ' ' << b << endl;
        return 0;
      }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
int main()
{
  int x,y;
  sd(x);sd(y);
  if(x>y)
    cout<<"safe";
else
{
        cout<<"unsafe";
}

  nline;
  return 0;
}


Measured memory_bytes: 3764
n, m, x = map(int, input().split())

S = [list(map(int, input().split())) for i in range(n)]
 
ans = 10 ** 7
 
for i in range(2 ** n):

    total = 0
    cnt = [0] * m
 
    for j in range(n):
 
        if (i >> j) & 1:

            total += S[j][0]
            for l in range(m):
                cnt[l] += S[j][l+1]
 
        else:
            continue
    
    nums = [k for k in cnt if k >= x]
    if len(nums) == m:
        ans = min(ans, total)

if ans == 10 ** 7:
    print(-1)

else:
    print(ans)

Measured memory_bytes: 9228
def main():
    import sys
    import numpy as np
    import itertools
    N,M,X=list(map(int,sys.stdin.readline().split()))
    C=[]
    for i in range(N):
        C.append(list(map(int,sys.stdin.readline().split())))

    C=np.array(C)
    costs=C[:,0]
    C=C[:,1:]
    cost=10**12
    for a in list(itertools.product([0,1], repeat=N)):
        if all((np.sum(C.T*np.array(a),axis=1)>=X).tolist()):
            cost=min(cost,np.sum(costs*np.array(a)))
    if cost==10**12:
        print(-1)
    else:
        print(cost)
        


main()

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define se          second
#define fi          first

using LL  = long long;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    LL a[7];
    inc(i, 0, 7) cin >> a[i];
    LL ans = a[1];
    if(a[0] > 0 && a[3] > 0 && a[4] > 0){
        ans += max(a[0]/2*2+a[3]/2*2+a[4]/2*2, 
                   (a[0]-1)/2*2+(a[3]-1)/2*2+(a[4]-1)/2*2 + 3);
    }else{
        ans += a[0]/2*2+a[3]/2*2+a[4]/2*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long x = sc.nextLong();
		long y = sc.nextLong();
		int cnt = 0;
		while (x <= y) {
			cnt++;
			x = x * 2;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
vector<int> a(3);
cin>>a[0]>>a[1]>>a[2];

sort(a.begin(),a.end());
int ans=0;
a[1]=a[2]-a[1];
a[0]=a[2]-a[0];
if(a[0]%2==1||a[1]%2==1){
ans++;
if((a[0]*a[1])%2==1){
a[0]--;
a[1]--;

}else{
a[0]++;
a[1]++;
}
}
ans+=(a[0])/2+(a[1])/2;

cout<<ans<<endl;

	return 0;
}



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

int main(){

  int H, W;
  cin >> H >> W;
  vector<string> grid;
  for(int i=0; i<H; ++i){
    string t;
    cin >> t;
    grid.push_back(t);
  }

  int mv[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  for(int i=0; i<H; ++i){
    for(int j=0; j<W; ++j){
      if(grid[i][j] == '#'){

        bool flag = false;
        for(int k=0; k<4; ++k){
          int i1 = i+mv[k][0], j1 = j+mv[k][1];
          if(i1 >= 0 && i1 < H && j1 >=0 && j1 < W){
            if(grid[i1][j1] == '#'){
              flag = true;
              break;
            }
          }
        }

        if(!flag){
          cout << "No" << endl;
          exit(0);
        }

      }
    }
  }
  cout << "Yes" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
 
int main(){
    long long n;
    cin >> n;
    string s;
    cin >> s;

    long long ans = 1;
    char state = s[0];
    for(long long i = 1; i < n; i++) {
        if(state != s[i]) {
            state = s[i];
            ans ++;
        }
    }

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


Measured memory_bytes: 512
fn main() {
    let hn = read_vec::<usize>();
    let h = hn[0];
    let n = hn[1];
    let v = {
        let mut v: Vec<(usize, usize)> = Vec::new();
        for _ in 0..n {
            let ab = read_vec::<usize>();
            v.push((ab[0], ab[1]));
        }
        v
    };

    let mut dp: Vec<Vec<usize>> = vec![vec![usize::max_value(); h+1]; n+1];
    dp[0][0] = 0;

    for i in 0..n {
        let (a, b) = v[i];
        for j in 0..h+1 {
            dp[i+1][j] = std::cmp::min(dp[i+1][j], dp[i][j]);
            if dp[i+1][j] < usize::max_value() {
                dp[i+1][std::cmp::min(j+a, h)] = std::cmp::min(dp[i+1][std::cmp::min(j+a, h)], dp[i+1][j]+b);
            }
        }
    }

    println!("{}", dp[n][h]);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 92412
import Foundation

extension String {
    
    func toStrList() -> [String] {
        return self.map{String($0)}
    }
    
    func toIntList() -> [Int] {
        return self.map{Int(String($0))!}
    }
    
    func toSepDoubleList() -> [Double]{
        return self.split(separator: " ").map{Double($0)!}
    }

    func toSepIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }

    func toSepStrList() -> [String] {
        return self.split(separator: " ").map{String($0)}
    }
    
    func zFill(n:Int) -> String {
        return String(format: "%0\(n)d", Int(self)!)
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }

    func counter() -> Dictionary<Character, Int>{
        var result:[Character:Int] = [:]
        
        for c in self{
            guard let _ = result.index(forKey: c) else {
                result[c] = 1
                continue
            }
            result[c]! += 1
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toNBin(_ radix:Int) -> String{
        return String(self, radix: radix)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}

func pow(_ base:Int,_ exp:Int) -> Int{
    let d = pow(base.toD(), exp.toD())
    return Int(d)
}


func abc048b() -> Int{
    let abx = readLine()!.toSepIntList()
    let bx = abx[1] / abx[2]
    let ax = abx[0] / abx[2]
    if abx[0] % abx[2] == 0 {
        return bx - ax + 1
    } else {
        return bx - ax
    }
}

print(abc048b())



Measured memory_bytes: 13592
const main = (input: string) => {
  const [A, B, K] = input.split(" ").map(str => parseInt(str))
  let divisorList = [];

  for (let i = A; i > 0; i--) {
    if(A % i === 0 && B % i === 0) {
      divisorList.push(i)
    }
  }
  console.log(divisorList[K - 1])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,q,l,r,flag = 0,h,m,n,k;
    cin>>n;
    if(n == 1){
    	cout<<0;
    	return 0;
	}
    vector<ll> v;
    for(i = 2;i*i<= n;i++){
    	if(n%i == 0){
    		ll count = 0;
    		while(n%i == 0){
    			count++;
    			n/=i;
			}
			v.pb(count);
		}
	}
	if(n!=1){
		v.pb(1);
	}
	ll ans = 0;
	rep(i,0,v.size()-1){
		ld tmp = (ld)(sqrt(1+8*v[i]) -  1)/2;
		ans += (ll)tmp;
	}
	cout<<ans;
}

Measured memory_bytes: 3676
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

Int N, A, B, C, D;
map<Int, Int> memo;

template <typename T>
inline T Abs(T a) {
    if (0 <= a) {
        return a;
    } else {
        return -a;
    }
}

Int solve(Int n) {
    if (n == 0) {
        return 0;
    } else if (n == 1) {
        return D;
    }

    if (memo.count(n) == 1) {
        return memo[n];
    }

    Int a2 = (n / 2) * 2;
    Int b2 = ((n + 1) / 2) * 2;
    Int a3 = (n / 3) * 3;
    Int b3 = ((n + 2) / 3) * 3;
    Int a5 = (n / 5) * 5;
    Int b5 = ((n + 4) / 5) * 5;

    Int ret = 1000000000000000000;
    if (n < ret / D) {
        ret = n * D;
    }
    ret = min({ret, Abs(a2 - n) * D + A + solve(a2 / 2), Abs(b2 - n) * D + A + solve(b2 / 2)});
    ret = min({ret, Abs(a3 - n) * D + B + solve(a3 / 3), Abs(b3 - n) * D + B + solve(b3 / 3)});
    ret = min({ret, Abs(a5 - n) * D + C + solve(a5 / 5), Abs(b5 - n) * D + C + solve(b5 / 5)});

    memo[n] = ret;

    return ret;
}

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

    int T;
    cin >> T;

    for (int i = 0; i < T; i++) {
        cin >> N >> A >> B >> C >> D;
        memo.clear();

        cout << solve(N) << endl;
    }

    return 0;
}

Measured memory_bytes: 4396
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    A = [-1 * a for a in A]
    heapify(A)

    for _ in range(M):
        tmp = heappop(A)
        heappush(A, -(-tmp // 2))
    
    print(-sum(A))

if __name__ == '__main__':
    main()

Measured memory_bytes: 22132
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int a, b; cin >> a >> b;
  int ans;
  if (b <= 1) {
    ans = 0;
  }
  else {
    int inc = a-1;
    ans = (b-1 + inc-1) / inc;
  }
  cout << ans << endl;
  return 0;
}


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

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

  ll sum=0;
  vector<ll> count(1000001,0);
  for(ll i=0;i<N;i++){
    count.at(A.at(i))++;
    sum+=A.at(i);
  }

  for(ll i=0;i<Q;i++){
    ll x=count.at(B.at(i));
    sum-=x*B.at(i);
    count.at(B.at(i))=0;
    count.at(C.at(i))+=x;
    sum+=x*C.at(i);
    cout<<sum<<endl;
  }

}


Measured memory_bytes: 13552
import itertools

N = int(input())

l = [i for i in range(1, N+1)]

p = list(itertools.permutations(l, N))

P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

a = p.index(P)
b = p.index(Q)

print(abs(b-a))

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

using namespace std;
typedef long long ll;

int main() {
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S[i];
    }
    bool jg=true;
        jg=false;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                
                if(S[i][j]=='#') break;
                else if(j==W-1){
                    S.erase(S.begin()+i);
                    i--,H--;
                    jg=true;
                }
            }
        }

        for(int i=0;i<W;i++){
            for(int j=0;j<H;j++){
                if(S[j][i]=='#') break;
                else if(j==H-1){
                    for(int l=0;l<H;l++){
                        S[l]=S[l].substr(0,i)+S[l].substr(i+1,W-i-1);;
                    }
                    i--,W--;
                }
            }
        }
    cout << endl;
    for(int i=0;i<H;i++){
        cout << S[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n,m;cin>>n>>m;
    cout<<(100*(n-m)+m*1900)*pow(2,m)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int a, b, k;
  cin >> a >> b >>k;
  int cnt = 0;
  vector<int> d;
  REP2(i,1,101){
    if(a%i == 0 && b%i == 0){
      d.push_back(i);
    }
  }

  int x = d.size() - k;
  //REP(i,d.size()) cout << d[i] << endl;
  cout << d[x] << endl;
  return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] stones = new int[n];
		int[] dp = new int[n];
		dp[0] = 0;
		for (int i = 0; i < n; ++i) {
			stones[i] = sc.nextInt();
			if (i > 0) dp[i] = Math.abs(stones[i] - stones[i - 1]) + dp[i - 1];
			for (int j = 2; j < k + 1; ++j) {
				if (i - j < 0) break;
				dp[i] = Math.min(dp[i], Math.abs(stones[i] - stones[i - j]) + dp[i - j]);
			}
		}
		System.out.println(dp[n - 1]);
		
		sc.close();
	}

}


Measured memory_bytes: 52696
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const ll MOD = 1e9+7;

int A[25][25];
ll DP[25][1<<22];

int main(){
    int N;
    cin >> N;
    REP(i,N){
        REP(j,N){
            int a;
            cin >> a;
            A[i][j] = a;
        }
    }

    for(int i = 0; i < N; i++){
        if(A[0][i])
            DP[0][1<<i] = 1;
    }

    for(int j = 1; j < N; j++){
        //DP[j][0] = 1;
        for(int i = 0; i < (1<<N); i++){
            if(DP[j-1][i] == 0) continue;
            for(int k = 0; k < N; k++){
                if(!A[j][k]) continue;
                if(i & (1<<k)) continue;
                DP[j][i | (1<<k)] += DP[j-1][i] % MOD;
            }
        }
    }

    //REP(i,N){
    //    REP(j,1<<N){
    //        printf("%lld ", DP[i][j]);
    //    }
    //    printf("\n");
    //}

    printf("%lld\n", DP[N-1][(1<<N) - 1] % MOD);
    return 0;
}


Measured memory_bytes: 319744
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');
  var params = inputs[0].split(' ').map(Number);

  (function(a, b) {
    // ????????????????????????
    console.log(a * b, (a + b) * 2);


  })(params[0], params[1]);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

ll n;
void dfs(string s,char s2){
	if(s.size()==n){
		cout<<s<<endl;
		return;
	}

	for(char c='a';c<=s2;c++){//c==s2なら、存在する文字を調べ尽くしたので、次の文字を調べる(s2=a,b,cまで調べたら、次はs2+1=dも調べる)
		dfs(s+c,(c==s2)?(char)(s2+1):s2);
	}

	return;
}

int main(){
	cin>>n;
	dfs("",'a');
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++) A[i] = scanner.nextInt();
        int[] cnts = new int[200001];
        int max = -1;
        for(int i = 0; i < N; i++) {
            cnts[A[i]]++;
            max = Math.max(max, A[i]);
        }
        for(int i = 0; i < N; i++) {
            if (A[i] < max) out.println(max);
            if (A[i] == max) {
                if (cnts[A[i]] > 1)
                    out.println(max);
                else {
                    for(int j = max-1; j>= 0; j--) {
                        if (cnts[j] > 0) {
                            out.println(j);
                            break;
                        }
                    }
                }
            }
            
        }
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


Measured memory_bytes: 48308
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 1;

		for (int i=0; i<N; i++){
			if (ans < K){
				ans = ans * 2;
			} else {
				ans = ans + K;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans = min(b,d)-max(a,c);
  cout << max(ans,0) << endl;
}


Measured memory_bytes: 256
s = input()
moji = list(str(s))

left = moji[0]+moji[1]
right = moji[2]+moji[3]
left = int(left)
right = int(right)

if 0 < left < 13:
    if 0 < right < 13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 0 < right < 13:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
const int maxn = 105;
int a[maxn];
int main(int argc, char const *argv[])
{
	int n,m;
	scanf("%d%d",&n,&m);
	int sum = 0;
	for(int i = 1;i <= n; ++i)
	{
		scanf("%d",&a[i]);
		sum += a[i];
	}
	int l = 0;
	for(int i = 1;i <= n; ++i)
	{
		if(a[i] * 4 * m >= sum)
		{
			++l;
		}
	}
	printf("%s\n",l >= m ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  if(((N%1000)/100) == ((N%100)/10)){
    if((((N%1000)/100) == (N/1000)) || (((N%1000)/100) == N%10)){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

bool consume(map<int, int> &cnt, int pn, int pl) {
  bool selected;
  while (pn) {
    selected = false;
    rep(i, 26) {
      if (cnt[i] < pl) continue;
      pn--;
      cnt[i] -= pl;
      selected = true;
    }
    if (!selected)
      break;
  }
  return pn == 0;
}

void dump(map<int, int> cnt) {
  rep(i, 26) {
    if (cnt[i] == 0) continue;
    cout << (char)(i + 'a') << ": " << cnt[i] << ", ";
  }
  cout << endl;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int H, W;
  vector<string> a;

  cin >> H >> W;
  a.resize(H);

  rep(i, H) cin >> a[i];

  map<int, int> cnt;
  rep(i, H) rep(j, W) {
    cnt[a[i][j] - 'a']++;
  }

  if (!consume(cnt, (H / 2) * (W / 2), 4)) {
    cout << "No" << endl;
    return 0;
  }

  if (!consume(cnt, W / 2 * (H % 2) + H / 2 * (W % 2), 2)) {
    cout << "No" << endl;
    return 0;
  }

  if (H % 2 && W % 2) {
    bool found = false;
    rep(i, 26) {
      if (cnt[i] >= 1) found = true;
    }
    if (!found) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  char P[10], Q[10];
  cin >> N;

  rep(i,N) cin >> P[i];
  P[N] = '\0';
  rep(i,N) cin >> Q[i];
  Q[N] = '\0';

  char perm[10];
  strcpy(perm, P);
  sort(perm,perm+N);

  vector<string> v;
  do{
    v.push_back(perm);
  }while(next_permutation(perm,perm+N));

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

  int posP = distance(v.begin(),find(v.begin(),v.end(),P));
  int posQ = distance(v.begin(),find(v.begin(),v.end(),Q));
  int res = abs(posP - posQ);
  cout << res << endl;
}


Measured memory_bytes: 2424
<?php
  list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));

  if($a == '7' && $b == '5' && $c == '5'){
    echo "YES";
  }else if($a == '5' && $b == '7' && $c == '5'){
    echo "YES";
  }else if($a == '5' && $b == '5' && $c == '7'){
    echo "YES";
  }else{
    echo "NO";
  }


Measured memory_bytes: 16044
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    ll h,w;
    cin >> h >> w;
    if(h>=3&&w>=3){
        cout<<(h-2)*(w-2)<<endl;
    }else if(h==2||w==2){
        cout<<0<<endl;
    }else if(h==1&&w==1){
        cout<<1<<endl;
    }else{
        cout<<h+w-3<<endl;
    }
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll X;
    cin >> X;
    pt(ceil((-1+sqrt(1+8*X))/2));
    
    
    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 9;
const int MAXN = 100005;
 
int n;
lint a, b, c, d;
 
int main(){
	cin >> n >> a >> b >> c >> d;
	for(int i=0; i<n; i++){
		lint incr_min = c * i - d * (n - 1 - i);
		lint incr_max = d * i - c * (n - 1 - i);
		if(incr_min <= b - a && incr_max >= b - a){
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}


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

int main()
{
  int a, b;
  while (cin >> a >> b) {
    if ((a|b) == 0)
      break;

    int n;
    cin >> n;
    vector<vector<int> > work(b, vector<int>(a, 0));
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      work[y-1][x-1] = 1;
    }

    vector<vector<int> > dp(b, vector<int>(a, 0));
    dp[0][0] = 1;
    for (int i = 0; i < b; ++i) {
      for (int j = 0; j < a; ++j) {
	if (work[i][j])
	  continue;
	if (i != b-1)
	  dp[i+1][j] += dp[i][j];
	if (j != a-1)
	  dp[i][j+1] += dp[i][j];
      }
    }

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

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
  int n, m;
  cin >> n >> m;
  vector<bool>b(n+1,true);
  vector<int>dp(n+1, 0);
  rep(i, 0, m){
      int a;
      cin >> a;
      b[a]=false;
  }
  dp[0] = 1;
  if(b[1])dp[1]=1;
  rep(i, 2, n+1){
      if(b[i-1])dp[i] += dp[i-1];
      if(b[i-2])dp[i] += dp[i-2];
      dp[i] %= mod;
  }
  cout << dp[n] << endl;
}

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

int main() {
  int N;
  cin>>N;
  vector<int64_t> S(89);
  S.at(0)=2;
  S.at(1)=1;
  if(N>=2){
  for(int i=2;i<=N;++i){
  S.at(i)=S.at(i-1)+S.at(i-2);
  }
  }
  
  cout << S.at(N) <<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

template<typename T>
struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<long long> hash1, hash2, power1, power2;

	// construct
	RollingHash(const T& S) {
		int n = (int)S.size();
		hash1.assign(n + 1, 0);
		hash2.assign(n + 1, 0);
		power1.assign(n + 1, 1);
		power2.assign(n + 1, 1);
		for (int i = 0; i < n; ++i) {
			hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
			power1[i + 1] = (power1[i] * base1) % mod1;
			power2[i + 1] = (power2[i] * base2) % mod2;
		}
	}


	// get hash of S[left:right]
	inline pair<long long, long long> get(int l, int r) const {
		long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
		if (res1 < 0) res1 += mod1;
		long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
		if (res2 < 0) res2 += mod2;
		return { res1, res2 };
	}
};

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

	ll n;
	cin >> n;
	Array a(n, 0), b(n, 0);
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	
	Array c(n, 0), d(n, 0);
	REP(i, n) c[i] = a[i] ^ a[(i + 1) % n];
	REP(i, n) d[i] = b[i] ^ b[(i + 1) % n];

	RollingHash<Array> rh_a(c);
	RollingHash<Array> rh_b(d);


	REP(k, n) {
		if (rh_a.get(k, n) == rh_b.get(0, n - k)
			&& rh_a.get(0, k) == rh_b.get(n - k, n))
			cout << k << " " << (a[k] ^ b[0]) << endl;
		//else cout << "ng" << k << endl;
	}

	return 0;
}

Measured memory_bytes: 22272