akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
set<string> data;
ll N; cin >> N;
string str;
REP(i, N) {
  cin >> str;
  data.insert(str);
}
cout << data.size();
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int gcd(Int a, Int b) {
 return b != 0 ? gcd(b, a % b) : a;
}
int lcm(Int a, Int b) {
 return a / gcd(a, b)*b;
}
int main(){
  int n,k;
  cin >> n >> k;
  int ans = k;
  for(int i=0;i<n-1;i++){
    ans *= (k-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod=1e9+7;
#define endl '\n'
#define SIGMA 128
const ld PI=3.14159265358979;
#define fr(i,n) for(i=1;i<=n;i++)
#define rep(i,k,n) for(i=k;i<=n;i++)
#define w(x) int x;cin>>x;while(x--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ps(x,y) cout<<fixed<<setprecision(y)<<x<<endl
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define vvl vector<vll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define mset multiset
#define uset unordered_set
#define umap unordered_map
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll binpow(ll x, ll y, ll p){  ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}  
ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a % b); } 
bool parity(ll x,ll y){ bool f = ((x ^ y) < 0);return !f;}

ll dp[23][2100001];
ll mat[23][23];
ll n;
ll cal(ll curr,ll mask)
{
    if(curr==n+1)
    {
        if((mask+1)==(1<<curr))
            return 1;
        return 0;
    }

    if(curr>n)  
        return 0;
    
    
    ll &ret=dp[curr][mask];
    if(ret!=-1)
        return ret;

    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        if((1<<i)&mask)
            continue;
        if(mat[curr][i]==1)
        {
            cnt+=cal(curr+1,(mask|(1<<i)));
            cnt%=mod;
        }
    }
    return ret=cnt;
}

int main()
{
    IOS

    ll i,j;
    cin>>n;
    fr(i,n)
        fr(j,n)
            cin>>mat[i][j];
    rep(i,0,22)
        rep(j,0,2100000)
            dp[i][j]=-1;
    cout<<cal(1,1)<<endl;

    return 0;  
}



Measured memory_bytes: 380888
N,K = map(int, input().split())
A=list(map(int, input().split()))  
 
num = sum(A[0:K])
ind = 0
max_num =0
for i in range(N-K):
    num -= A[i]
    num += A[i+K]
    if num> max_num:
        ind = i+1
        max_num = num
 
ans = 0
for i in range(ind,ind+K):
    ans += (1+A[i])/2
    
print(ans)

Measured memory_bytes: 25060
N = int(input())

def nibu(l,r):
    if l > r:
        return ':('
    c = (l+r)//2
    if (c*1.08)//1 == N:
        return c
    if (c*1.08)//1 < N:
        return nibu(c+1,r)
    elif (c*1.08)//1 > N:
        return nibu(l,c-1)

print(nibu(0,100000))

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var N, M int

	fmt.Scanf("%d %d %d\n", &N, &M)
	sum := 0
	A := make([]int, N)
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		A[i] = a
		sum += a
	}
	cnt := 0
	for _, a := range A {
		if a*4*M < sum {
			continue
		}
		cnt++
	}
	if M > cnt {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main(void)
{
   int s, v, i=0;
   char a[102], b[102];

   scanf("%s%s",a,b);
   s=strlen(a);
   v=strlen(b);

   if(s>v)
      printf("GREATER\n");
   else if(s<v)
      printf("LESS\n");
   else{
      while(i<s){
         if(a[i]>b[i]){
            printf("GREATER\n");
            return 0;
         }
         else if(a[i]<b[i]){
            printf("LESS\n");
            return 0;
         }
         i++;
      }
      printf("EQUAL\n");
   }
   return 0;
}

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

  	string N;
  cin>>N;
  bool check=false;
	int a,b,c;
  rep(i,N.size()){
  	if(N[i]=='7'){
    	check=true;
    }
  }
    if(check){
    	cout<<"Yes";
    }else{
    	cout<<"No";
    }
    
}

Measured memory_bytes: 3620
N = int(input())

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

nl = [0] * 3

for a in A:
  if a % 4 == 0:
    nl[2] += 1
  elif a % 2 == 0:
    nl[1] += 1
  else:
    nl[0] += 1

# 2は2個以上あればとりあえず全部繋げとけば良い、1個だけなら１としてカウント同じ
if nl[1] == 1:
  nl[0] += 1

# 2が2個以上あれば、2.....2,4,1,4,1 num_4 >= num_1の形を満たせばOK
# ２が1,0個なら、1,4,1,4,...4,1 num_4 + 1 >= num_1の形を満たせばOK
if nl[1] >= 2 and nl[2] >= nl[0]:
  print("Yes")
elif nl[1] <= 1 and nl[2] >= nl[0] - 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

int main(){
    INT(a, b, c, k);
    while (a >= b && k > 0){
        b *= 2; k--;
    }
    while (b >= c && k > 0){
        c *= 2; k--;
    }
    print(Yes[(a < b && b < c)]);
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> dp(3, 0);
    for(int i = 0; i < n; i++){
        vector<int> new_dp(3, 0);
        int c[3];
        for(int j = 0; j < 3; j++) cin >> c[j];
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j != k){
                    new_dp[j] = max(new_dp[j], dp[k] + c[j]);
                }
            }
        }
        dp = new_dp;
    }
    cout << max(max(dp[0], dp[1]), dp[2]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 A;
  string B;
  cin >> A >> B;
  cout << A * stoi(B.substr(0, 1)) + A * stoi(B.substr(2, 2)) / 100 << endl;
  return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a,b) a = min(a,(decltype(a))(b))
#define MAXS(a,b) a = max(a,(decltype(a))(b))


int main() {
	int i;
	cin >> i;
	if (i == 0)PRI(1);
	else PRI(0);
	return 0;
}

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


    int main(){
        int n,m=0;
        cin >> n;
        int d[1000], a[1000] = {};
        for (int i = 0; i < n; i++) {
            cin >> d[i];
            a[d[i]] = 1;
        }
        for (int i = 0; i < 1000; i++) {
            if (a[i] == 1)m++;
        }
        cout << m << endl;
        return 0;
    }

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 305;
int N, K;
int H[MAX_N];
int dp[MAX_N][MAX_N];

signed main()
{
  cin >> N >> K;
  H[0] = 0;
  FOR(n,1,N+1) {
    cin >> H[n];
  }
  N++;

  REP(n,MAX_N) {
    REP(k,MAX_N) {
      dp[n][k] = INF_LL;
    }
  }

  dp[0][0] = 0;
  REP(i, N+1){
    REP(j, K+1){
      REP(k,j+1){
        int pos = i - k - 1;
        if(pos < 0) continue;
        dp[i][j] = min(dp[i][j], dp[pos][j - k] + max(0LL, H[i]-H[pos]));
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N;
VPII G[55];
int A[55], B[55];
int M;
int u[22], v[22];
LL route_idxes_mask[55][55]; // [u][v] := u -> v への edge の index
LL rest_mask[22];       // [i] := i 番目の制約の edge の index の bit 表現

void make_route_internal(const int cur, const int par, LL cur_route_idxes_mask, const int root) {

    route_idxes_mask[root][cur] = cur_route_idxes_mask;

    FORE(el, G[cur]) if (el.first != par) {
        cur_route_idxes_mask |= (1LL << el.second);
        make_route_internal(el.first, cur, cur_route_idxes_mask, root);
        cur_route_idxes_mask ^= (1LL << el.second);
    }
}

void make_route() {
    REP(i, N) {
        make_route_internal(i, -1, 0, i);
    }
}

int main(void) {
    cin >> N;
    REP(i, N - 1) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        G[A[i]].EB(B[i], i);
        G[B[i]].EB(A[i], i);
    }
    cin >> M;
    REP(i, M) {
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
    }

    make_route();
    REP(i, M) {
        rest_mask[i] = route_idxes_mask[u[i]][v[i]];
    }

    LL ans = 0;
    REP(bit, (1 << M)) {
        LL cur_mask = 0;
        REP(i, M) if (bit & (1 << i)) {
            cur_mask |= rest_mask[i];
        }

        const int bit_count = __builtin_popcountll(cur_mask);

        if (__builtin_parity(bit)) {
            ans -= 1LL << (N - 1 - bit_count);
        } else {
            ans += 1LL << (N - 1 - bit_count);
        }
        //DEBUG(ans)
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

const long long MOD = 1000000007;

template <typename T> class Factorial {
  public:
    vector<T> fact;
    vector<T> factinv;
    Factorial(long long N);
    static T bipow(T c, T n);
    static T square(T n);
    T conv(T n, T m) const;
    T perm(T n, T m) const;
};

template <typename T> Factorial<T>::Factorial(long long N) : fact(N+1), factinv(N+1) {
  fact[0] = 1;
  for (long long i = 1; i < N+1; i++) {
    fact[i] = fact[i-1]*static_cast<T>(i)%MOD;
  }
  factinv[N] = bipow(fact[N], MOD-2);
  for (int i = N; i > 0; i--) {
    factinv[i-1] = factinv[i]*static_cast<T>(i)%MOD;
  }
}

template <typename T> T Factorial<T>::bipow(T c, T n) {
  if (n == 0) {
    return 1;
  } else if(n == 1) {
    return c;
  } else if(n%2 == 0) {
    return square(bipow(c, n/2))%MOD;
  } else {
    return (static_cast<T>(c)*square(bipow(c, (n-1)/2)))%MOD;
  }
}

template <typename T> T Factorial<T>::square(T n) {
  return static_cast<long long>(n)*n%MOD;
}

template <typename T> T Factorial<T>::conv(T n, T m) const {
  if (n < m) {
    return 0;
  }
  return (((static_cast<long long>(fact[n])*factinv[m])%MOD)*factinv[n-m])%MOD;
}

template <typename T> T Factorial<T>::perm(T n, T m) const {
  if (n < m) {
    return 0;
  }
  return (static_cast<long long>(fact[n])*factinv[n-m])%MOD;
  }

void solve(std::vector<long long> r, std::vector<long long> c){
  Factorial<long long> F(r[1]+c[1]+2LL);

  long long ret = 0;

  ret += (F.conv(r[1]+c[1]+2, r[1]+1) - 1 + MOD) % MOD;
  ret -= (F.conv(r[1]+c[0]+1, r[1]+1) - 1 + MOD) % MOD;
  ret += MOD;
  ret %= MOD;
  ret -= (F.conv(r[0]+c[1]+1, r[0]) - 1 + MOD) % MOD;
  ret += MOD;
  ret %= MOD;
  ret += (F.conv(r[0]+c[0], r[0]) - 1 + MOD) % MOD;
  ret %= MOD;
  std::cout << ret << std::endl;
}

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


Measured memory_bytes: 31488
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        if (n == 1 && m == 1) {
            System.out.println(1);
            return;
        }
        if (n ==1||m==1) {
            System.out.println(n*m-2);
            return;
        }
        long res = (long) (n-2) * (m-2);
        System.out.println(res);

    }

}

Measured memory_bytes: 23252
N,T=map(int,input().split())
ans_list=[]
for i in range(N):
    c,t=map(int,input().split())
    if t>T:
        ans_list.append(1001)
    else:
        ans_list.append(c)
if min(ans_list)==1001:
    print("TLE")
else:
    print(min(ans_list))

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

using namespace std;

int
main(void){
	string s;
	string ans;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '0' || s[i] == '1') ans += s[i];
		else{
			if(ans.size() > 0) ans.pop_back();
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int min = 1;
		for (int i = 0; i < n; i++) {
			min = Math.min(min*2, min+k);
		}
		
		System.out.println(min);
	}
}

Measured memory_bytes: 21588
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#pragma GCC optimize(5)
#pragma GCC optimize(6)
#pragma GCC optimize(7)
#pragma GCC optimize(8)
#pragma GCC optimize(9)
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline int readint(){
    int x=0;
    int f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int ans=123456789;
int W[300005],E[300005];
int main(){
	int i,j,n;
	string s;
	cin>>n>>s;
	s=' '+s;
	for(i=1;i<=n;i++){
		E[i]=E[i-1]+(s[i]=='E');
	}
	for(i=n;i>=1;i--) W[i]=W[i+1]+(s[i]=='W');
	for(i=1;i<=n;i++){
		ans=min(ans,n-1-E[i-1]-W[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int a,b,c;cin>>a>>b>>c;

    if(a+b+c>21)cout<<"bust\n";
    else cout<<"win\n";

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int hand[13];
	int i;
	int a;
	int pair,three,str,four;
	char aa;
	
	for(;cin >> a;)
	{
		for(i=0;i<13;i++)
			hand[i]=0;
		
		hand[a-1]++;
		
		for(i=1;i<5;i++)
		{
			cin >> aa >> a;
			hand[a-1]++;
		}
		
		pair=str=three=four=0;
		
		for(i=0;i<13;i++)
		{
			if(hand[i]==4)
				four=1;
			else if(hand[i]==2)
				pair++;
			else if(hand[i]==3)
				three=1;
			if(i!=12 && hand[i]==1 && hand[i+1]==1)
				str++;
		}
		if(hand[12]==1 && hand[0]==1 && hand[1]!=1)
			str++;
		
		if(str==4)
			cout << "straight" << endl;
		else if(four==1)
			cout << "four card" << endl;
		else if(pair==1 && three==1)
			cout << "full house" << endl;
		else if(three==1)
			cout << "three card" << endl;
		else if(pair==2)
			cout << "two pair" << endl;
		else if(pair==1)
			cout << "one pair" << endl;
		else
		 cout << "null" << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
	
	int a,i,j,c=0,cc=0;
	
	scanf("%d",&a);
	
		for(j=1;j<=a;j=j+2){
			c=0;
			for(i=1;i<=j;i++){
			if(j%i==0)c++;
			}
			if(c==8)cc++;
		}
		printf("%d\n",cc);
	
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int d = parseInt(sc.next());
		int n = parseInt(sc.next());
		sc.close();
		if(n==100)n++;
		out.println((int)pow(100,d)*n);
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,b=1,c=0;
  cin>>n;
  for(int j=1;j<=n;j++)
  {b=1;
  while(j*b<n)
  {
    b++;
    c++;
  }
  }
  cout<<c<<"\n";
}

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

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

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353


ll N,K;
pll LR[100];
ll dp[404040], mk[404040];
ll i, j, k;

int main(){
    scanf("%lld%lld", &N, &K);
    rep(i,0,K){
        ll l, r;
        scanf("%lld%lld", &l, &r);
        LR[i] = {l, r};
    }

    dp[1] = 1;
    ll a = 0;
    rep(i,1,N+1){
        (a += mk[i]) %= MOD;
        (dp[i] += a) %= MOD;
        rep(j,0,K){
            (mk[i + LR[j].fi] += dp[i]) %= MOD;
            (mk[i + LR[j].se + 1] += MOD - dp[i]) %= MOD;
        }
    }
    printf("%lld\n", dp[N]);

    return 0;
}

Measured memory_bytes: 8400
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))

def count_bigger_x(x):
    cnt = 0
    piv = N-1
    for a in A:
        while piv >= 0 and a + A[piv] >= x:
            piv -= 1
        cnt += N - piv - 1
    return cnt


def is_ok(x):
    cnt = count_bigger_x(x)
    return cnt >= M


def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

x = bisect(2 * A[-1] + 1, 2 * A[0] - 1)
ans = 0
piv = N-1
for a in A:
    while piv >= 0 and a + A[piv] >= x:
        piv -= 1
    ans += (N - piv - 1) * a
ans *= 2
ans -= 1 * x * (count_bigger_x(x) - M)
print(ans)


Measured memory_bytes: 84004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, Q, A, B;
ll pos[200000  +10];

template <typename T>
class ST {
 public:
  vector<T> tree;
  int n;

  ST() = default;
  ST(const vector<T> &arr) : n(arr.size()) {
    tree = vector<T>(2 * n);
    for (int i = 0; i < n; ++i) {
      update(i, arr[i]);
    }
  }
  void update(int p, T val) {
    int i = n + p;
    tree[i] = val;
    i /= 2;
    while (i) {
      tree[i] = tree[i * 2];
      if (i * 2 + 1 < tree.size()) {
        tree[i] = min(tree[i], tree[i * 2 + 1]);
      }
      i /= 2;
    }
  }

  T query(int start, int end) {  // start index - end index
    int l = n + start;
    int r = n + end - 1;
    T ret = INT_MAX;
    while (l <= r) {
      if (l & 1) {
        ret = min(ret, tree[l]);
        l++;
      }

      if ((r & 1) == 0) {
        ret = min(ret, tree[r]);
        r--;
      }

      l /= 2;
      r /= 2;
    }

    return ret;
  }

};

ST<ll> st1, st2;

ll base = 0;

ll getAug(int x) {
  ll r1 = st1.query(x, N) - x;
  ll r2 = st2.query(0, x) + x;
  return min(r1, r2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> N >> Q >> A >> B;

  for (int i = 0; i < Q; ++i) {
    int x;
    cin >> x;
    pos[i] = x - 1;
  }

  ll p1 = A - 1;
  ll p2 = B - 1;

  vector<ll> dp(N, INT_MAX);

  ll lp = p1;
  dp[p2] = 0;
  st1 = ST<ll>(dp);
  for (int i = 0; i < N; ++i) {
    st1.update(i, dp[i] + i);
  }


  st2 = ST<ll>(dp);

  for (int i = 0; i < N; ++i) {
    st2.update(i, dp[i] - i);
  }

  for (int i = 0; i < Q; ++i) {
    auto cp = pos[i];
    auto aug = getAug(cp);

    ll real1 = dp[lp] + abs(cp - lp) + base;
    ll real2 = aug + base;
    ll rreal = min(real1, real2);

    dp[lp] = rreal - base - abs(cp -lp);

    st1.update(lp, dp[lp] + lp);
    st2.update(lp, dp[lp] - lp);
    base += abs(cp - lp);
    lp = cp;
  }

  ll ret = 1LL << 62;

  for (int i = 0; i < N; ++i) {
    ret = min(ret, dp[i] + base);
  }

  cout << ret << endl;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int x=sc.nextInt(),n=sc.nextInt();
		HashSet<Integer>set=new HashSet();
		while(n-->0)
			set.add(sc.nextInt());
		int ans=-1;
		int min=Integer.MAX_VALUE;
		for(int i=-1;i<105;i++) {
			int diff=Math.abs(x-i);
			if(!set.contains(i) && diff<min) {
				ans=i;
				min=diff;
			}
				
		}
		System.out.println(ans);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

		int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}

Measured memory_bytes: 32924
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;

int main() {
	int c;
	scanf("%c", &c);
	printf("%c", c + 1);
	//while (1)getchar();
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	int k;
	vector<int> v;
	float sum=0;
	for(int i=0;i<n;i++){
	    cin>>k;
	    v.push_back(k);
	    sum+=k;
	   // cout<<v[i]<<'\t';
	}
	sort(v.begin(),v.end(),greater<int>());
// 	cout<<sum<<'\n';
	sum/=4;
	sum/=m;
// 	cout<<sum<<'\n';
    if(v[m-1]>=sum)
	   cout<<"Yes";
	else
	    cout<<"No";
	   return 0;
	}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <cstring>
#include <stdio.h>

using namespace std;

int main() {
	int A, B;
	std::cin >> A >> B;

	int cnt = 0;
	int result;
	for (double i = 1; i <= 10000; i++) {
		if ((int)(i * 0.08) == A && (int)(i * 0.1) == B) {
			cnt++;
			if (cnt == 2) {
				cout << result << endl;
				return 0;
			}
			else {
				result = (int)i;
			}
		}
	}
	
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <pii, int> oc ; 
    int n; cin>>n; 
    ld a;
    while (n--){ 
        cin >> a ; 
        int x = (llround)(a*1e9) ; 
        int two=0,five=0; 
        while (x%2 == 0){ 
            two++; x /= 2; 
        } 
        while (x%5 == 0){ 
            five++; x /= 5; 
        } 
        oc[{two,five}]++ ; 
        // cout << two << " " << five << " = " << oc[{two,five}] << endl ; 
    } 
    int ans = 0 ; 
    for (auto  &it1: oc) { 
        for (auto  &it2: oc) { 
            if (it1.ff.ff+it2.ff.ff>=18 and it1.ff.ss+it2.ff.ss>=18) { 
                if(it1 < it2) { 
                    ans += it1.ss * it2.ss ; 
                } 
                else if(it1 == it2) { 
                    ans += it1.ss * (it1.ss-1)/2 ; 
                } 
            } 
        } 
    } 
    co ( ans ) ; 
} 

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3772
#include <stdio.h>

int main(void)
{
    int ans = 0;
    int i;
    char S[4];

    scanf("%s", S);
    
    for (i = 0; i < 4; i++) {
        if (S[i] == '+') {
            ans++;
        }
        else if (S[i] == '-') {
            ans--;
        }
    }
    printf("%d\n", ans);

    return (0);
}


Measured memory_bytes: 128
h,w,d=map(int,input().split())
box=[list(map(int,input().split())) for i in range(h)]
adress={}
for i in range(h):
    for j in range(w):
        adress[box[i][j]]=[i,j]
q=int(input())
order=[list(map(int,input().split())) for i in range(q)]
S=[0]*(h*w+1)
for k in range(d+1,h*w+1):
    x,y=adress[k]
    i,j=adress[k-d]
    S[k]=S[k-d]+abs(x-i)+abs(y-j)
for x,y in order:
    print(S[y]-S[x])

Measured memory_bytes: 87260
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct edge{
  int to,cost;
  edge(int a,int b):to(a),cost(b) {}
};
struct state{
  double t;
  int p, i;
  state(double t, int p, int i):t(t), p(p), i(i) {}
};
bool operator < (state s, state t){
  return s.t > t.t;
}

int main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    a--, b--;
    vector<int> ticket(n);
    vector<edge> E[30];
    REP(i,n)cin>>ticket[i];
    REP(i,p){
      int x,y,z; cin>>x>>y>>z;
      x--, y--;
      E[x].push_back(edge(y,z));
      E[y].push_back(edge(x,z));
    }
    sort(ticket.begin(), ticket.end());
    double ans = INF;
    do{
      bool used[8][30] = {};
      priority_queue<state> que;
      que.push(state(0, a, 0));
      while(!que.empty()){
        state s = que.top(); que.pop();
        if(s.p == b) {
          ans = min(ans, s.t);
          break;
        }
        if(s.i == n) continue;
        if(used[s.i][s.p]) continue;
        used[s.i][s.p] = true;
        REP(i,E[s.p].size()){
          edge e = E[s.p][i];
          que.push(state(s.t + (double)e.cost /ticket[s.i], e.to, s.i+1));
        }
      }
    }while(next_permutation(ticket.begin(), ticket.end()));
    if(ans != INF) printf("%.12lf\n",ans);
    else cout<<"Impossible"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int r[n];
  for(int i=0;i<n;i++)
    r[i]=0;
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    r[a-1]++;
    r[b-1]++;
  }
  for(int i=0;i<n;i++)
    cout << r[i] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll MOD=1e9+7 ;
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; }


// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
const int nmax = 500;
int edge[nmax][nmax];
void dfs(int indent_plus, int now_points, int tukatteiiLevel)
{
    if (now_points==1) return;
    rep(i,now_points/2)
    {
        rep(j,now_points/2+(now_points%2))
        {
            int x = indent_plus + i;
            int y = indent_plus + j + now_points/2;
            edge[x][y] = edge[y][x] = tukatteiiLevel;
        }
    }
    dfs(indent_plus, now_points/2, tukatteiiLevel+1);
    dfs(indent_plus+now_points/2, now_points/2 + (now_points%2), tukatteiiLevel+1);
    return;
}

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

    rep(i,n) rep(j,n) edge[i][j] = 0;
    dfs(0, n, 1);
    rep(i,n)
    {
        REP(j,i+1,n)
        {
            cout << edge[i][j];
            if (j!=n-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1408
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

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

signed main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> table(H, vector<int>(W));
    queue<P> que;
    for (int i = 0; i < H; i++) {
        string line;
        cin >> line;
        for (int j = 0; j < W; j++) {
            char c = line[j];
            if (c == '#') {
                table[i][j] = 0;
                que.push(P(i, j));
            } else {
                table[i][j] = INF;
            }
        }
    }

    while (!que.empty()) {
        P p = que.front(); que.pop();
        for (int i = 0; i < 4; i++) {
            int yy = p.first + dy[i];
            int xx = p.second + dx[i];
            if (xx < 0 || yy < 0 || xx >= W || yy >= H) continue;
            if (table[p.first][p.second] + 1 < table[yy][xx]) {
                table[yy][xx] = table[p.first][p.second] + 1;
                que.push(P(yy, xx));
            }
        }
    }

    int ret = -1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ret = max(ret, table[i][j]);
        }
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 24500
N,M=map(int,input().split())

from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)

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

def root(x):
    if par[x]==x:
        return x
    else:
        par[x]=root(par[x])
        return par[x]
def same(x,y):
    return root(x)==root(y)
def unite(x,y):
    x=root(x)
    y=root(y)
    if(x!=y):
        par[x]=y

A=[]
B=[]
for i in range(M):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

d=defaultdict(lambda:1)
ans=[-1 for i in range(M)]

ic=(N*(N-1))//2

for i in range(M):
    j=M-i-1
    ans[j]=ic
    a=A[j]
    b=B[j]
    if not same(a,b):
        anum=d[par[a]]
        bnum=d[par[b]]
        ic-=anum*bnum
        unite(a,b)
        d[par[b]]=anum+bnum
for i in range(M):
    print(ans[i])






Measured memory_bytes: 36696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
 
int main(){
  int INF = 1000000000;/*配列の上限*/
  int h, w;/*マスの大きさ*/
  int sy, sx;/*playerの位置*/
  int gy, gx;/*Goalの位置*/
  cin >> h >> w >> sy >> sx >> gy >> gx;
  sy--; sx--; gy--; gx--;
  vector<string> g(h);
  rep(i,h) cin >> g[i];
  vvi dist(h, vi(w, INF));
  deque<pair<int,int>> q;
  q.push_back({sy, sx});
  vi v = {1, 0, -1, 0, 1};
  dist[sy][sx] = 0;
  while(!q.empty()){
    int y = q.front().first;
    int x = q.front().second;
    q.pop_front();
    rep(i,4){
      int ny = y + v[i];
      int nx = x + v[i+1];   
      if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if(g[ny][nx] == '#') continue;
      if(dist[ny][nx] > dist[y][x]){
        dist[ny][nx] = dist[y][x];
        q.push_front({ny, nx});
      }
    }
    for(int i=-2; i<=2; i++){
      for(int j=-2; j<=2; j++){
        int ny = y + i;
        int nx = x + j;
        if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
        if(g[ny][nx] == '#') continue;
        if(dist[ny][nx] > dist[y][x] + 1){
          dist[ny][nx] = dist[y][x] + 1;
          q.push_back({ny, nx});
        }
      }
    }
  }
  if(dist[gy][gx] == INF) dist[gy][gx] = -1;
  cout << dist[gy][gx] << endl;
}


Measured memory_bytes: 9448
#include "bits/stdc++.h"
using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<string> S;
	string str;
	for (int i = 0; i < N; i++) {
		cin >> str;
		S.push_back(str);
	}
	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());
	cout << S.size() << endl;
	return 0;
}

Measured memory_bytes: 11660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
int main() {
  string s;
  cin >> s;
  int l = (s[0] - '0') * 10 + (s[1] - '0');
  int r = (s[2] - '0') * 10 + (s[3] - '0');
  if (l > 12 || l == 0) {
    if (r > 12 || r == 0) {
      cout << "NA" << endl;
      return 0;
    }
    cout << "YYMM" << endl;
    return 0;
  }
  if (r > 12 || r == 0) {
    cout << "MMYY" << endl;
    return 0;
  }
  cout << "AMBIGUOUS" << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int N;  cin>>N;
  vector<int> v(N);
  rep(i,0,N) cin>>v[i];
  sort(all(v));
  v.erase(unique(all(v)), v.end());
  if(N != v.size()){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
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;}
int32_t main() {
    IOS;

        int a[3];
        rep(i,0,2)cin>>a[i];
        int sum=0;
        rep(i,0,2)sum+=a[i];
        if(sum>=22)cout<<"bust";
        else cout<<"win";
        



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 256
/*It’s going to be hard,
but hard does not mean impossible.*/

#include <bits/stdc++.h>

// definitions
#define __Imperial_Lord__ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define acc(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"
#define p2(a, b) cout << a << " " << b << "\n"
#define p3(a, b, c) cout << a << " " << b << " " << c <<"\n"
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<"\n"
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<"\n"
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF = LONG_LONG_MAX;

template <class ...Args>
istream &read_args(Args &...args) {return (cin >> ... >> args);}
#define read(...)   __VA_ARGS__; read_args(__VA_ARGS__)

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v)
        is >> i;
    return is;
}
template<typename T>    ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v)
        os << i << ' ';
    return os;
}



// code beigns in main
int main()
{
    __Imperial_Lord__
    ll t = 1;
    // cin >> t;

    while(t--)
    {
        ll read(n);
        string read(s);

        ll cnt=0;
        set<ll> w,r;
        rep(i,0,n)
        {
            if(s[i]=='W') w.insert(i);
            else r.insert(i);
        }
        if(r.size()==0 || w.size()==0) p1(0);
        else
        {
            while((*w.begin())<*(--r.end()))
            {
                cnt++;
                ll i=*w.begin();
                ll j=*(--r.end());
                w.erase(w.begin()); w.insert(j);
                r.erase(--r.end()); r.insert(i);
            }
            p1(cnt);
        }
    }
    exec;
}

Measured memory_bytes: 13140
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 21:04:52 2019

@author: Riichi_Yokoyama
"""
import itertools
import copy
N,A,B,C = map(int, input().split())

l = []
for i in range(N):
    l.append(int(input()))
    

def toku(C,B,A,l):
    l2 = copy.deepcopy(l)
    ans = 0
    needtomake = 3
    plist = []
    for i in range(len(l2)-needtomake + 1):
        plist.extend(list(itertools.combinations(l2, i+1))) 
    one = []
    for i in range(len(plist)):
        one.append(abs(C - sum(plist[i])) + 10*(len(plist[i])-1))
    mindex = one.index(min(one))
    ans += min(one)
    needtomake -= 1
    for i in range(len(plist[mindex])):
        l2.remove(plist[mindex][i])
    
    ##2
    plist = []
    for i in range(len(l2)-needtomake + 1):
        plist.extend(list(itertools.combinations(l2, i+1)))
        
    one = []
    for i in range(len(plist)):
        one.append(abs(B - sum(plist[i])) + 10*(len(plist[i])-1))
        
    mindex = one.index(min(one))
    ans += min(one)
    needtomake -= 1
    for i in range(len(plist[mindex])):
        l2.remove(plist[mindex][i])

    ##3
    plist = []
    for i in range(len(l2)-needtomake + 1):
        plist.extend(list(itertools.combinations(l2, i+1)))
        
    one = []
    for i in range(len(plist)):
        one.append(abs(A - sum(plist[i])) + 10*(len(plist[i])-1))
        
    mindex = one.index(min(one))
    ans += min(one)
    needtomake -= 1
    for i in range(len(plist[mindex])):
        l2.remove(plist[mindex][i])
    return ans

an = [0,0,0,0,0,0]
an[0] = toku(C,B,A,l)
an[1] = toku(C,A,B,l)
an[2] = toku(B,A,C,l)
an[3] = toku(B,C,A,l)
an[4] = toku(A,B,C,l)
an[5] = toku(A,C,B,l)

print(min(an))

Measured memory_bytes: 3696