akhauriyash/Code-Regression huggingface dataset:
import sys

N=int(input())
amat=[[-1]]
for i in range(N):
  alist=list(map(int,input().split()))
  amat.append(list(reversed(alist)))
  
#print(amat)
answer=0
matched_flag=[False]*(N+1)
for answer in range(1,N**3):
  if N>900 and answer>3000:
    print(N*(N-1)//2)
    sys.exit()
  
  matched_flag=[False]*(N+1)
  unchanged=True
  
  for i in range(1,N+1):
    if matched_flag[i] or len(amat[i]) == 0:
      continue
      
    ai_next = amat[i][-1]
    if amat[ai_next][-1]==i and not matched_flag[ai_next]:
      #print(i,ai_next,answer)
      matched_flag[amat[i].pop()]=True
      matched_flag[amat[ai_next].pop()]=True
      unchanged=False
  
  if unchanged:
    print(-1)
    sys.exit()
  else:
    for i in range(1,N+1):
      if len(amat[i])>0:
        break
    else:
      print(answer)
      sys.exit()


Measured memory_bytes: 36484
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 2000005;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[SIZE], finv[SIZE], inv[SIZE];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

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

long long lcm(long long a, long long b) {
	long long  g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

int main(){

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

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

    int count = 0;

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

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

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

    ll sum=0;
    for(int i=0;i<n;i++){
        if(count % 2 == 0){
            sum+=abs(a[i]);
        }
        else{
            if(i==0) sum-=a[i];
            else sum+=a[i];
        }
    }

    cout << sum << endl;
    
}

Measured memory_bytes: 1152
from operator import add, sub
a, b, c, d = [int(n) for n in input().rstrip("\n")]

for i in range(2**3):
    if [add, sub][(i // 4) % 2]([add, sub][(i // 2) % 2]([add, sub][i % 2](a, b), c), d) == 7:
        print(str(a) + "+-"[i % 2] + str(b) + "+-"[(i // 2) % 2] + str(c) + "+-"[(i // 4) % 2] + str(d) + "=7")
        break


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

int tower[1000];

int main() {

    for(int i=1; i<=1000; i++){
        tower[i] += tower[i-1] + i;
    }

    int a,b;

    cin >> a >> b;

    for(int i=1; i<1000; i++){
        if(tower[i] - a == tower[i+1] - b){
            cout << abs(tower[i] - a) << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define range(v)                v.begin(),v.end()
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

void ssolve(std::istream& in, std::ostream& out){
    int n;
    s(n);
    int k;
    s(k);
    vi h(n);
    f(i, 0, n){
        s(h[i]);
    }
    vi dp(n, 1e9+5);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j <= i + k && j < n; j++){
            dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
        }
    }
    p(dp[n - 1]);
    return;
}

class BFrog2 {
public:
void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(0);out.tie(0);
    int t;
    int READ = 0;
    if(READ) s(t);
    else t = 1;
    while(t--){
        ssolve(in, out);
    }
}
};

integer main() {
    BFrog2 solver;
    std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
}

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

multiset<int> edge[200005];
int memo[200005];

void dfs(int now)
{
	for (auto v:edge[now])
	{
		if (memo[v]==-1)
		{
			memo[v]=memo[now];
			dfs(v);
		}
	}
}

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int p[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>p[i];--p[i];
	}
	int x,y;
	for (int i = 0; i < m; ++i)
	{
		cin>>x>>y;--x;--y;
		edge[x].insert(y);
		edge[y].insert(x);
	}
	for (int i = 0; i < n; ++i)
	{
		memo[i]=-1;
	}
	for (int i = 0; i < n; ++i)
	{
		if (memo[i]==-1)
		{
			memo[i]=i;
			dfs(i);
		}
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		if (memo[i]==memo[p[i]])
		{
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 22784
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1000000000


int main()
{
    int n;
    cin>>n;
    lll Mod=n%500;
    lll div=n/500;
    lll ans=0;
    ans+=(div)*1000;
    ans+=(Mod/5)*5;
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef pair<int,int> pii;


// modint
const ll mod = 1e9+7;
template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
      return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
    
  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  
  static int get_mod() { return mod; }
};


using mint = ModInt<mod>;

int main() {
  ll N,M; cin >> N >> M;

  vector<mint> prod(M+1,1);

  for(ll i = 1; i <= M; i+=1){
    prod[i] = prod[i-1] * (mint)i;
  }


  mint mPn = prod[M] * prod[M-N].inv();
  mint ans = 1;
  ans *= mPn;
  ans *= mPn;
  
  mint minus = 0;
  for(ll K = 1; K <= N; K++){
    mint tmp = 1;

    // ll nCk = COM(N,K);
    mint nCk = prod[N] * prod[K].inv() * prod[N-K].inv();
    tmp *= nCk;

    mint mPk = prod[M] * prod[M-K].inv();
    tmp *= mPk;

    mint mkPnk = prod[M-K] * prod[M-N].inv();
    tmp *= mkPnk;
    tmp *= mkPnk;

    if(K%2==0){
      ans += tmp;
    } else { 
      ans -= tmp;
    }
  }
  cout << ans << endl;
}





Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    print(YES if any(
        S == T[i:] + T[:i]
        for i in range(len(T))
    ) else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN =


ll n, a, b;
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n >> a >> b;

    if (a % 2 == b % 2) {
        cout <<abs(a-b)/2 << endl;
    } else {
        cout << min(min(a-1,b-1)+abs(a-b)/2+1,min(n-a,n-b)+abs(a-b)/2+1) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def call(n):
    for i in range(3, n + 1):
        if i % 3 == 0:
            print(" " + str(i), end="")
        else:
            x = i
            while x:
                if x % 10 == 3:
                    print(" " + str(i), end="")
                    break
                else:
                    x = x // 10
    print()

n = int(input())
call(n)


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

int main(){
   int n;
   cin >> n;
   int x=n*800;
   int y=(n/15)*200;
   cout << x-y << endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
S = [input() for _ in range(N)]

dict = {"M" : 0, "A" : 0, "R" : 0, "C" : 0, "H" : 0}
for s in S :
    if s[0] in "MARCH" :
        dict[s[0]] += 1

counter = list(dict.values())
ret = 0
for i in range(len(counter)) :
    for j in range(i + 1, len(counter)) :
        for k in range(j + 1, len(counter)) :
            ret += counter[i] * counter[j] * counter[k]
print(ret)

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

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

    int n, d;
    cin >> n >> d;
    vector<vector<int>> ds(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> ds[i][j];
        }
    }
    auto ok = [&](int i, int j) {
        int sum = 0;
        for (int k = 0; k < d; k++) {
            sum += (ds[i][k] - ds[j][k]) * (ds[i][k] - ds[j][k]);
        }
        int a = sqrt(sum);
        return a * a == sum;
    };
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (ok(i, j)) cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define fi first
#define se second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef pair<int, ii>  iii;
typedef vector<int>     vi;

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
#define tam 1234567
vector<int> g[tam];
int valor[tam];
void add(int &iz,int &der)
{
    g[iz].pb(der);
    g[der].pb(iz);
}
int dfs(int num,int pa,int dia)
{
    if (dia<0)
        return 0;
    int res=valor[num];
    for(int v:g[num])
    {
        if (v==pa)continue;
        res+=dfs(v,num,dia-1);
    }
    return res;
}
int main()
{
    int  n,k;
    cin>>n>>k;
    forr(i,0,n+1)
    valor[i]=1;
    int auxx=n+1,iz,der;
    forr(i,0,n-1)
    {
        cin>>iz>>der;
        if (k&1)
        add(iz,auxx),add(auxx,der);
        else
        add(iz,der);
        auxx++;
    }
    int maxx=0;
    if (k&1)
    {
        forr(i,n+1,auxx)
        {
            maxx=max(maxx,dfs(i,i,k));
        }
    }
    else
    {
        forr(i,1,n+1)
        {
            maxx=max(maxx,dfs(i,i,k/2));
        }
    }
    cout<<n-maxx<<endl;
}
// PLUS ULTRA!

Measured memory_bytes: 30208
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(long long(a), long long(b), long long(c)) {
	return max(max(a,b), c);
}
int Min(long long(a), long long(b), long long(c)) {
	return min(min(a, b), c);
}

int cnt(ll N) {
	int digits = 0;

	while (N > 0) {
		N /= 10;
		digits++;
	}

	return digits;
}



int main() {
	ll X, an = 0, so = 100;
	cin >> X;
	while (so < X) {
		so *= 1.01;
		an++;
	}



	cout << an << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define md(a, b)		((a) % b + b) % b
#define mod(a)			md(a, MOD)
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define forn(i, n)			for(int i = 0; i < n; i++)
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
//int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef long double ld;	
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1); 
int ar[200020];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("asd.txt", "r", stdin);
	//freopen("qwe.txt", "w", stdout);
	int n, k;
	cin>>n>>k;
	fore(i, 0, n)
	{
		cin>>ar[i];
		if(i >= k)
		{
			if(ar[i] > ar[i-k])
				cout<<"Yes\n";
			else
				cout<<"No\n";
		}
	}
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2				

Measured memory_bytes: 4428
#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 300001;

/*
struct data{
  int l,r,c;
  data():l(0), r(0),c(0){};
  data(int w, int i, int c_) : l(w),r(i),c(c_){};
  bool operator < (data other) const {
	if(l==other.l)
		return r<other.r;
    return l < other.l;
  }
};
*/



int arr[MAX_N];
int alph[27];


int main()
{

        double n,k;
        cin>>n>>k;
        double ans = 0.0 ;
        ll num= 0;
        ll denum = 0;
        num = 1;
        denum = pow(2,ceil(log(k)/log(2)));
        rep(i,2,n+1){
                
                if(i>k)
                {
                    ans+=1;
                    continue;
                }
                num = num*pow(2,ceil(log(k/i)/log(2))) + denum;
                denum *= pow(2,ceil(log(k/i)/log(2)));
                int d; 
        		  d = __gcd(num, denum); 
  
    num = num / d; 
    denum = denum / d; 
        }
        ans += (1.0*num)/(1.0*denum);
        ans*=(1.0/(n*1.0));
        printf("%.10f",ans);



        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int ord2(int x){
    int ans = 0;
    while (x%2==0){
        x /= 2;
        ans++;
    }
    return ans;
}


int main() {
    int N, M;
    cin >> N >> M;
    vector<int>As(N);
    vector<int>Bs(N);
    for (int i=0; i<N; i++) cin >> As[i];
    for (int i=0;i<N; i++) Bs[i] = As[i] / 2;
    int ord = ord2(Bs[0]);

    for (int i=1; i<N; i++){
        if (ord != ord2(Bs[i])){
            cout << 0 << endl;
            return 0;
        }
    }

    ll l = 1;
    for (int i=0; i<N; i++){
        ll g = gcd(l, Bs[i]);
        l = l/g*Bs[i];

    }
    if (l > M){cout << 0 << endl;return 0;}

    cout << (M / l + 1) / 2  << endl;


}

Measured memory_bytes: 1024
#include<stdio.h>

struct dice{
    int d[6],tmp[6];
};
struct dice dice1;
struct dice dice2;

void init1(int n[6]){
    int i;
    for(i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for(i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void rooldice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}

int compare(){
    int i;
    for (i=0; i<6; i++) {
        if(dice1.d[i]!=dice2.d[i]){
            
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n[6];
    int i,j;
    int ok=0;
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init1(n);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init2(n);
    for(i=0;i<4;i++){
        for(j=0;j<4;j++){
            rooldice('N');
            rooldice('E');
            rooldice('S');
            if(compare()) ok=1;
        }
        rooldice('N');
    }
    rooldice('E');
    for(i=0;i<2;i++){
        for(j=0;j<4;j++){
            rooldice('N');
            rooldice('E');
            rooldice('S');
            if(compare()) ok=1;
        }
        rooldice('W');
        rooldice('W');
    }
    if(ok) printf("Yes\n");
    else puts("No");
    return 0;
}

Measured memory_bytes: 580
s = str(input())
k = int(input())
ch = []
for i in range(1, min(k+1, len(s)+1)):
  for j in range(len(s)-i+1):
    ch.append(s[j:j+i])
ch = list(set(ch))
ch = sorted(ch)
print(ch[k-1])  

Measured memory_bytes: 5068
import java.util.*;
public class Main{
  public static void main(String[] args){
	    Scanner sc=new Scanner(System.in);
	   	int a=sc.nextInt();
	    int b=sc.nextInt();
	    int c=a*b;
	    if(c%2==1) {
	    	System.out.println("Odd");
	    }else {
	    	System.out.println("Even");
	    }
    
  }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 305;
char s[maxn][maxn];
int n, m;

ll d[maxn][maxn];
ll forDiff[maxn * 2];
ll calc(int col) {
    forn (i, maxn)
        forn (j, maxn)
            d[i][j] = infl;
    forn (i, n + 1)
        d[i][0] = d[0][i] = 0;
    forn (i, maxn * 2)
        forDiff[i] = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            ll &score = forDiff[i - j + maxn];
            if (s[i - 1][col] == s[j - 1][col + 1])
                ++score;
            d[i][j] = score + min(d[i - 1][j], d[i][j - 1]);
        }
    return d[n][n];
}

int main() {
    #ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
    #else
    #endif
    cin >> n >> m;
    forn (i, n) {
        scanf("%s", s[i]);
    }
    ll res = 0;
    forn (i, m - 1)
        res += calc(i);
    cout << res << '\n';
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;


// #include <iostream>

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr std::ostream& operator << (std::ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 998244353;

int main() {
    int nn, mm, kk;
    cin >> nn >> mm >> kk;
    Fp<MOD> N(nn);
    Fp<MOD> M(mm);
    Fp<MOD> K(kk);

    vector<Fp<MOD>> factorial(nn + 1);
    factorial[0] = 1;
    rep(i, nn) {
        
        factorial[i+1] = (Fp<MOD>(i)+1) * factorial[i];
    }

    Fp<MOD> sum(0);
    // rep()
    rep(i, kk+1){
        Fp<MOD> ii(i);
        sum += M * modpow(M - 1, nn-i-1) * factorial[nn-1]/factorial[i]/factorial[nn-1-i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 4800
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],b[N],c[N],d[N],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(int k=0;k<29;k++)
	{
		int m=(1<<k),s=0;
		for(int i=1;i<=n;i++)
			c[i]=a[i]%(m*2);
		for(int i=1;i<=n;i++)
			d[i]=b[i]%(m*2);
		sort(d+1,d+n+1);
		for(int i=1;i<=n;i++)
		{
			int l1=lower_bound(d+1,d+n+1,m-c[i])-d,r1=lower_bound(d+1,d+n+1,m*2-c[i])-d;
			int l2=lower_bound(d+1,d+n+1,m*3-c[i])-d,r2=lower_bound(d+1,d+n+1,m*4-c[i])-d;
			if((r1-l1+r2-l2)&1)
				s^=1;
		}
		if(s)
			ans+=m;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6860
#include<stdio.h>

int main() {
    int n;
    int a[1010];
    int i, j, minj;
    int tmp, cnt = 0;

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

    for(i = 0; i < n; i++) {
        minj = i;
        for(j = i + 1; j < n; j++) {
            if (a[j] < a[minj]) {
                minj = j;
            }
        }
        if (minj != i) cnt++;
        tmp = a[i];
        a[i] = a[minj];
        a[minj] = tmp;
    }

    for(j = 0; j < n; j++) {
        printf("%d%c", a[j], ((j == n - 1) ? '\n' : ' '));
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 1856
#include<iostream>

using namespace std;

int main( )
{	
    int n;
    
    cin>>n;
    
    int maxProfit = 1-1000000000;
    int Rj, Ri, t;
    
    cin>>Ri;
    for( int i=1; i<n; i++ ) {
    	cin>>Rj;
    	t = Rj - Ri;
    	if( maxProfit < t ) {
       		maxProfit = t;
       	}
       	if( Rj < Ri ) {
    		Ri = Rj;
    	}
    }
    cout<<maxProfit<<endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in k,t;
  cin>>k>>t;
  in mx=0;
  in a,b;
  forn(z,t){
    cin>>a;
    b=k-a;
    if(b+1<a)
      mx=max(mx,a-(b+1));
  }
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
	tmp = input.split("\n");
	var a = tmp[0].split(" ");
	var n = parseInt(a[0]);
	var k = parseInt(a[1])-1;
	var s = tmp[1];
	var r = "";
	for (var i = 0 ; i < n ; i++){
		if(i==k){
			if(s.charAt(i) == "A"){ r += "a"; }
			if(s.charAt(i) == "B"){ r += "b"; }
			if(s.charAt(i) == "C"){ r += "c"; }
		}else{
			r += s.charAt(i);
		}
	}
	console.log(r);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

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

int main() {
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.size();
	int ans=0;
	REP(i,n) {
		s.erase(s.size()-1);
		if(s.size()%2==0&&s.substr(0,s.size()/2)==s.substr(s.size()/2,s.size()/2)) {
			ans=s.size();
			break;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    input = input[1].split(" ");
    result = [];

    for (i in input) {
        input[i] = Number(input[i]);
    }

    input.sort(compareFunc);

    for (let i = 0; i < input.length - 2; i++) {
        for (let j = 0; j < input.length - 1 - i; j++) {
            for (let k = 0; k < input.length - i - j - 2; k++) {
                tmp = [input[i], input[j + i + 1], input[i + j + k + 2]];
                var set = new Set(tmp);
                if (set.size == 3 && tmp[2] < tmp[0] + tmp[1]) {
                    result.push(tmp);
                }
            }
        }
    }
    console.log(result.length);
}

function compareFunc(a, b) {
    return a - b;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int countB = 0;
	ll ans = 0;
	FOR(i,0,n){
		if(s[i] == 'B'){
			countB++;
		}else{
			ans += countB;
		}
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 640
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    String s = sc.next();

    for (int i = 1; i < s.length(); i++) {
      if (s.charAt(i) == s.charAt(i - 1)) {
        os.println("Bad");
        return;
      }
    }
    os.println("Good");
  }
}

Measured memory_bytes: 22996
#include <iostream>
 
int main()
{
    int n;
    std::cin >> n;
    int *sequence = new int[n];
    for (int i = 0; i < n; i++)
    {
        int num;
        std::cin >> num;
        sequence[i] = num;
    }
    for (int i = n -1; i >= 0; i--)
    {
        std::cout << sequence[i];
        if (i > 0)
        {
            std::cout << " ";
        }
        else
        {
            std::cout << '\n';
        }
    }
    delete[] sequence;
    return 0;
}

Measured memory_bytes: 3108
S = input()

AKIBA = "AKIHABARA"
A_index = [0,4,6,8]
AKIBA_list = []
for j in range(16):
    J = j
    temp = list(AKIBA)
    for i in range(4):
        if J%2==1:
            temp[A_index[i]] = "?"
        J //= 2
        if J==0:break
    temp = "".join(temp)
    AKIBA_list.append(temp.replace("?",""))
    
if S in AKIBA_list:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <climits>

#include <cfloat>

#include <map>

#include <utility>

#include <set>

#include <iostream>

#include <memory>

#include <string>

#include <vector>

#include <algorithm>

#include <functional>

#include <sstream>

#include <complex>

#include <stack>

#include <queue>

#include <numeric>

#include <cstring>



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

#define pb push_back



using namespace std;



typedef long long ll;

typedef pair<int, int> P;

typedef vector<int> vi;

typedef vector<vi> vvi;



const int INF = 1 << 29;

const double EPS = 1e-9;

const int MAX_N = 1000;

const int MAX_W = 1000;



int dp[MAX_N + 1][MAX_W + 1];

int dpw[MAX_N + 1][MAX_W + 1];



int main(){

	int n, cap, ans_c = 0;

	int v[MAX_N], w[MAX_N];

	

	while(1){

		memset(dp, 0 , sizeof(dp));

		memset(dpw, 0, sizeof(dpw));

		scanf("%d", &cap);

		if(cap == 0) break;

		scanf("%d", &n);



		rep(i, n){

			scanf("%d,%d\n",&v[i],&w[i]);

		}



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

			for(int j = 0; j <= cap; j++){

				if(j < w[i]){

					dp[i+1][j] = dp[i][j];

					dpw[i+1][j] = dpw[i][j];

				}else{

					dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);

					if(dp[i+1][j] == dp[i][j - w[i]] +v[i]){

						dpw[i+1][j] = dpw[i][j-w[i]] + w[i];

					}else{

						dpw[i+1][j] = dpw[i][j];

					}

				}

			}

		}

		ans_c++;

		printf("Case %d:\n%d\n%d\n", ans_c , dp[n][cap], dpw[n][cap]);

	}

}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int sum = 0;
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    sum += gcd(gcd(a, b), c);
                }
            }
        }
        System.out.println(sum);
    }
    
    static int gcd(int x, int y){
        if(x % y == 0) return y;
        return gcd(y, x % y);
    }
}

Measured memory_bytes: 27228
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string b;
  cin >> b;

  if(b[0] == 'A'){
    cout << "T" << endl;
  }else if(b[0] == 'C'){
    cout << "G" << endl;
  }else if(b[0] == 'G'){
    cout << "C" << endl;
  }else if(b[0] == 'T'){
    cout << "A" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int p = scanner.nextInt();
		String s = scanner.next();
		long count = 0;

		if (p == 2 || p == 5) {
			for (int i = 0; i < n; i++) {
				if ((s.charAt(i) - 48) % p == 0) {
					count += i + 1;
				}
			}
		} else {
			int[] place = new int[p - 1];//10^a mod p=10^(a%(p-1)) mod p
			place[0] = 1;
			for (int i = 1; i < p - 1; i++) {
				place[i] = place[i - 1] * 10 % p;
			}

			int[] r = new int[p];
			r[0] = 1;
			int remain = 0;
			for (int i = 0; i < n; i++) {
				remain += (s.charAt(n - 1 - i) - 48) * place[i % (p - 1)];
				remain %= p;
				r[remain]++;
			}

			for (int i = 0; i < p; i++)
				count += (long) r[i] * (r[i] - 1) / 2;

		}
		System.out.println(count);
	}

}


Measured memory_bytes: 26736
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
  get(n);
  get(m);
  get(sx);
  get(sy);
  get(ex);
  get(ey);
  --sx;
  --sy;
  --ey;
  --ex;
  vector<string> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  deque<pair<ll, ll>> dq;
  vector<vector<ll>> dis(n, vl(m, INT_MAX));
  dis[sx][sy] = 0;
  dq.push_front({sx, sy});
  vector<vector<bool>> vis(n, vector<bool>(m, false));
  vector<vl> r = {{1, -1, 0, 0}, {0, 0, 1, -1}};
  while (!dq.empty())
  {
    auto it = dq.front();
    int x(it.first), y(it.second);
    dq.pop_front();
    if (vis[x][y])
      continue;
    vis[x][y] = true;
    if (x == ex && y == ey)
    {
      p1(dis[x][y]);
      return;
    }
    for (int i = 0; i < 4; i++)
    {
      int nx = x + r[0][i];
      int ny = y + r[1][i];
      if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] && v[nx][ny] != '#')
      {
        dq.push_front({nx, ny});
        dis[nx][ny] = min(dis[nx][ny], dis[x][y]);
      }
    }
    for (int i = x - 2; i <= x + 2; i++)
    {
      for (int j = y - 2; j <= y + 2; j++)
      {
        if (i >= 0 && i < n && j >= 0 && j < m && !vis[i][j] && (abs(i - x) + abs(j - y) > 1) && v[i][j] != '#')
        {
          dq.push_back({i, j});
          dis[i][j] = min(dis[i][j], dis[x][y] + 1);
        }
      }
    }
  }
  p1(-1);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

const ll MAX_N = 200, MAX_X = 1e5;
ll n, x;
Vi S;

ll dp[MAX_N + 1][MAX_X + 1];
ll fact[MAX_N + 1] = {};
ll factorial(ll a){
   //a! mod 1e9 + 7
   if(fact[a] > 0) return fact[a];
   if (a ==0) {
      fact[0] = 1;
      return 1;
   }
   else{
      fact[a] = (factorial(a-1) * a) % MOD;
      return fact[a];
   }
}

ll func(ll i, ll t){
   //黒板にtが書かれており, S0, S1, ..., Siまでを用いるときの答え
   if(dp[i][t] >= 0) return dp[i][t];
   if(i == 0){
      dp[0][t] = t % S[0];
      return dp[0][t];
   }
   else{
      dp[i][t] = (func(i-1, t % S[i])  + func(i-1, t) * i) % MOD;
      return dp[i][t];
   }


}
int main(){
   cin >> n >> x;
   S.resize(n);
   REP(i, n) cin >> S[i];
   SORT(S);
   // init dp table
   REP(i, n + 1){
      REP(j, x + 1){
         dp[i][j] = -1;
      }
   }
   cout << func(n - 1, x) << endl;


}


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

int main() {
  int n;
  int p[100];
  int maxi = -1;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i];

  for (int i = 1; i <= 100; ++i) {
    int a = i, cnt = 0;
    for (int j = 0; j < n; ++j) {
      cnt += (p[j] >= a);
    }
    maxi = max(maxi, (cnt >= a ? a : -1));
  }
  cout << maxi << endl;
}

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

int main()
{
  int PN,FP,QN;
  cin>>PN>>FP>>QN;
  vector<int> Who(QN);
   vector<int> Point(PN);
   for(int i=0;i<PN;i++)
   {
    Point.at(i)=FP-QN;
   }
  for(int i=0;i<QN;i++)
  {
   cin>>Who.at(i);
    Point.at(Who.at(i)-1)=Point.at(Who.at(i)-1)+1;
  }
 
  
  for(int j=0;j<PN;j++)
  {
    if(Point.at(j)>0)
    {
     cout<<"Yes"<<endl;
    }
    else
    {
     cout<<"No"<<endl;
    }
  }
}


Measured memory_bytes: 1408
I, O, T, J, L, S, Z = map(int, input().split())
if I>0 and J>0 and L>0:
    print(O + max(2*(I//2+J//2+L//2), 3+2*((I-1)//2+(J-1)//2+(L-1)//2)))
else:
    print(O+2*(I//2+J//2+L//2))


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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 100007
#define DIMM 107
#define INF 1000000000007.0
#define X 31
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n,k;
ll ma;
ll a[DIMM],dp[DIM];

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

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

    for(int i=1;i<=k;i++){
     for(int j=1;j<=n;j++)
      if(i>=a[j] && dp[i-a[j]]==0){
       dp[i]=1;
       break;
      }
    }
    if(dp[k]==1)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


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

int main(){
    int x, y500, y5;
    cin >> x;
    
    if (x == 0){
        cout << 0;
    }

    else{
        int happiness = 0;

        y500 = x / 500;
        happiness += y500 * 1000;
        x -= y500 * 500;

        y5 = x / 5;
        happiness += y5 * 5;

        cout << happiness;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct x
{
    int p,y,no,number;
}x;
int n,m;
bool cmp1(x tmp1,x tmp2)
{
    if (tmp1.p<tmp2.p) return true;
    else if (tmp1.p>tmp2.p) return false;
    else return tmp1.y<tmp2.y;
}
bool cmp2(x tmp1,x tmp2)
{
    return tmp1.number<tmp2.number;
}
void solve()
{
    int i;
    vector < x > a(m);
    for (i=0;i<m;i++)
    {
        cin>>a[i].p>>a[i].y;
        a[i].number=i+1;
    }
    sort(a.begin(),a.end(),cmp1);
    a[0].no=1;
    for (i=1;i<m;i++)
        if (a[i-1].p==a[i].p) a[i].no=a[i-1].no+1;
        else a[i].no=1;
    sort(a.begin(),a.end(),cmp2);
    for (i=0;i<m;i++)
        printf("%06d%06d\n",a[i].p,a[i].no);
}
int main()
{
    while(cin>>n>>m)
        solve();
}

Measured memory_bytes: 3072