akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

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

    ll ans,ans3;
    ans=0;
    ans3=0;
    rep(j,k){
            ans+=p[j];
        }

    ans3=ans;
    rep(i,n-k){
        ans=ans-p[i]+p[i+k];
        
        ans3=max(ans,ans3);
    }

    double ans2;
    ans2=ans3/2.0+0.5*k;

    printf("%.10f",ans2);
    

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    public class IO
    {
        public static string ReadStr() => Console.ReadLine();
        public static string[] ReadStrArr() => ReadStr().Split(' ');

        public static int ReadInt() => int.Parse(ReadStr());
        public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

        public static double ReadDouble() => double.Parse(ReadStr());
        public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);

        public static long ReadLong() => long.Parse(ReadStr());
        public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
    }

    class Template
    {
        static void Main(string[] args)
        {
            int n = IO.ReadInt();
            Console.WriteLine((1 + n) * n / 2);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h> 
using namespace std;
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define pii pair<ll,ll>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
# define ll long long int
int main() 
{
	int w,n;
	cin>>n>>w;
	int w1[n],v[n];
	int i,k,j,s=0;
	for(i=0;i<n;i++)
{
		cin>>w1[i]>>v[i];
		s+=v[i];
}


	long long int dp[n+1][s+1];
	for(i=0;i<n+1;i++)
		for(k=0;k<s+1;k++)
			dp[i][k]=INT_MAX-1000;
		for(i=0;i<n;i++)
		{

		dp[i+1][v[i]]=w1[i];
		dp[i][0]=0;
	}

	for(i=2;i<=n;i++)
		for(j=0;j<=s;j++)
		{
			if(j==0)
				dp[i][j]=0;
		
			else if(j>=v[i-1])
			{
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+w1[i-1]);
			}
			else
				dp[i][j]=dp[i-1][j];



		}
		
		int ans=0;
		for(i=s;i>=0;i--)
		{
			if(dp[n][i]<=w)
			{
				cout<<i<<endl;
				break;
			}
		}
}



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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,k,tmp,asum,ok=200000000000000001,ng=-1;
vector<int> a,f;

signed main() {
    cin >> n >> k;
    rep(i,n) cin >> tmp, a.pb(tmp), asum += tmp;
    rep(i,n) cin >> tmp, f.pb(tmp);
    sort(all(a));
    sort(rall(f));

    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        int cnt=0;
        rep(i,n) cnt += min(a[i], mid/f[i]);
        if (asum-cnt <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;



}





Measured memory_bytes: 4848
N, M, X = map(int, input().split())
CA = []
for i in range(N):
    CA.append(list(map(int, input().split())))

import numpy as np
CA = np.array(CA)

import itertools
l = []
for i in range(1, N+1):
    for C in itertools.combinations(CA, i):
        if (sum(C)[1:N+1]>=X).all():
            l.append(sum(C)[0])

if l == []:
    print(-1)
else:
    print(min(l))

Measured memory_bytes: 27940
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define PB push_back
#define MP make_pair
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>())

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
using ll = long long;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


void Main() {
  ll W,H,x,y;
  cin >> W >> H >> x >> y;
  long double ans = W*H/2.0;
  if(x == W/2.0 && y == H/2.0) cout << ans << " 1" << endl;
  else cout << ans << " 0" << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
//  std::cout << std::fixed << std::setprecision(15);
  std::cout << std::fixed << std::setprecision(6);
  Main();

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int dp[110];
    int N, X;
    cin >> N >> X;
    int L[110];
    for(int i = 0; i < N; ++i) cin >> L[i];
    for(int i = 0; i <= N; ++i){
        if(i==0) dp[i] = 0; 
        else dp[i] = dp[i-1] + L[i-1];
    }
    int count = 0;
    for(int i = 0; i <= N; ++i){
        if(dp[i] <= X) count++;
        else break;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;

    std::vector<int> d(N);
    for (int i = 0; i < N; i++)
        std::cin >> d[i];

    std::sort(d.begin(), d.end());

    std::cout << d[N / 2] - d[N / 2 - 1] << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    ll N, D, cnt = 0; cin >> N >> D;
    for(int i = 0; i < N; i++){
        ll a, b; cin >> a >> b;
        if(a*a+b*b <= D*D) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>

#define long long long

using namespace std;

const int N = 1e3 + 2;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int Mul(long a, long b) { return a * b % MOD; }
int Pw2(int x) { return x == 0 ? 1 : Mul(Pw2(x - 1), 2); }

struct TEdge { int v, w; };
vector<TEdge> g[N];

int n, m;
long target, cost = 0;
int h[N], p[N], f[N];
pair<int, int> d[N];
bool vst[N];

bool BuildMST()
{
    fill(d + 1, d + 1 + n, make_pair(INF, 0));
    d[1] = {0, 0};
    for (int k = 0; k < n; ++k)
    {
        auto top = min_element(d + 1, d + 1 + n);
        if (top->first == INF) return false;

        int u = top - d;
        vst[u] = true;
        p[u] = top->second;
        h[u] = h[p[u]] + 1;
        f[u] = top->first;
        cost += top->first;

        for (auto e: g[u])
            if (!vst[e.v]) d[e.v] = min(d[e.v], {e.w, u});
        *top = {INF, 0};
    }
    return true;
}

int LCA(int u, int v)
{
    if (h[u] < h[v]) swap(u, v);
    int ret = 0;
    while (h[u] > h[v]) ret = max(ret, f[u]), u = p[u];
    while (u != v)
        ret = max({ret, f[u], f[v]}), u = p[u], v = p[v];
    return ret;
}

int main()
{
    cin >> n >> m >> target;
    for (int i = 0; i < m; ++i)
    {
        int u, v, w; cin >> u >> v >> w;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    if (!BuildMST() || cost > target)
    {
        cout << 0;
        return 0;
    }
    int eq = 1, fr = 1;
    for (int u = 1; u <= n; ++u)
        for (auto e: g[u])
        {
            int ef = e.w - LCA(u, e.v);                      // ef >= 0
            if (ef == target - cost) ++eq; else
            if (ef > target - cost) ++fr;
        }
    eq = Pw2(eq / 2), fr = Pw2(fr / 2);                      // each edge is counted twice, so we divide by 2
    if (cost == target) cout << Mul(eq - 2 + MOD, fr);
    else cout << Mul(eq - 1 + MOD, fr * 2);
    return 0;
}


Measured memory_bytes: 384
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int letters = 26;

string solve (string s)
{
	auto n = s.length.to !(int);
	if (n == letters)
	{
		auto t = s.dup;
		if (nextPermutation (t.representation))
		{
			auto r = t.idup;
			while (s < r[0..$ - 1])
			{
				r = r[0..$ - 1];
			}
			return r;
		}
		return "-1";
	}
	else
	{
		foreach (c; 'a'..'z' + 1)
		{
			if (!s.canFind (c))
			{
				return s ~ c.to !(char);
			}
		}
		assert (false);
	}
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		writeln (solve (s));
	}
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc087/tasks/abc087_b


A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

ans = 0
0.upto(A) do |a|
  0.upto(B) do |b|
    0.upto(C) do |c|
      ans += 1 if 500 * a + 100 * b + 50 * c == X
    end
  end
end
puts ans


Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a  = scan.nextInt();
        int x = scan.nextInt();
  
	if(a < x){
	System.out.println(0);
	}else{
  	System.out.println(10);
	}
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define ld long double
#define fr first
#define se second
#define pb push_back
using namespace std;
int a , b;
int main(){
    ios_base::sync_with_stdio( false );
    cin >> a >> b;
    if( a == b) 
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct edge{int v,nxt;}e[maxn<<1];
int head[maxn],ecnt=0;
void add(int u,int v)
{
	e[++ecnt]=(edge){v,head[u]},head[u]=ecnt;
	e[++ecnt]=(edge){u,head[v]},head[v]=ecnt;
}
int fa[maxn],n;
bool vis[maxn];
bool ans=1;
void dfs(int u,int pre)
{
	fa[u]=pre;
	for(int i=head[u];~i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==pre)continue;
		dfs(v,u);
	}
	if(u==1)
	{
		if(vis[u]==0)ans=0;
	}
	else 
	{
		if(!vis[u])
		{
			if(!vis[fa[u]])vis[fa[u]]=1,vis[u]=1;
			else ans=0;
		}	
	}
	
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
	}
	dfs(1,0);
	printf("%s\n",!ans?"First":"Second");
}

Measured memory_bytes: 2688
//include,using,define等
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>

// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ui = unsigned int;
using qul = queue<ll>;
using pql = priority_queue<ll>;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#pragma region header
//#define int long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define INF (ll)10000000000000000
#define mod (ll)1000000007
#define P pair<lint,lint>
template <class T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
template <class T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main(void) {
	lint n; cin >> n;
	lint ans = 0;
	vl a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0) {
			if (a[i] == a[i - 1]) {
				ans++;
				a[i] = 10000;
			}
		}
	}
	printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<stdio.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
int main()
{

    long long int t,n,k,i,arra[1000];
    string s="";
        cin>>n;
        while(n)
        {
            t=n/26;
            k=n%26;
            if(k==0)
            {
                t--;
                s=(char)'z'+s;
            }
            else
                s=(char)('a'+k-1)+s;
            n=t;
        }
        cout<<s<<endl;

    return 0;
}



Measured memory_bytes: 3632
# ABC0 C - 怪文書 / Dubious Document
from collections import defaultdict
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

N = ni()
S = [input() for _ in range(N)]
ABC = set()
t = set()

for i,s in enumerate(S):
    if i == 0:
        for ss in s:
            ABC.add(ss)
            t.add(ss)
    else:
        ABC = ABC & t
        t = set()
        for ss in s:
            t.add(ss)
if len(ABC)==0:
    print('')
    exit()

ABC = list(ABC)
D = defaultdict(lambda: 10000)
for s in S:
    for abc in ABC:
        t = s.count(abc)
        D[abc] = min(t,D[abc])

ANS = ''
for k in D:
    ANS += k*D[k]

L = []
for ans in ANS:
    L.append(ans)

L.sort()
print(''.join(L))


Measured memory_bytes: 3316
//
// author  : Abhishek
//
#include <bits/stdc++.h>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 200005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 == 1;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;

        




    }
}

int main() {


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;
    cin>>a>>p;
    
    cout<<(3*a+p)/2;

    return 0;
}




Measured memory_bytes: 3604
num = int(input())
lis = list(map(int,input().split()))
sum = 0
min = lis[0]
max = lis[0]
for i in range(num):
    if(min > lis[i]):min = lis[i]
    if(max < lis[i]):max = lis[i]
    sum = sum+lis[i]
    
print("%d %d %d" %(min,max,sum))


Measured memory_bytes: 6592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_N = 200100;
int P[MAX_N];
int low_element[MAX_N];
int N;

int main()
{
    scanf("%d", &N);
    for(int i = 1; i <= N; ++i) scanf("%d", &P[i]);
    low_element[0] = MAX_N;
    for(int i = 1; i <= N; ++i) low_element[i] = min(low_element[i-1], P[i]);
    int res = 0;
    for(int i = 1; i <= N; ++i) if(low_element[i] >= P[i]) ++res;
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
 
int main(){
  int i,t[101];
  int max,n;
 
  max = 0;
  for(i=0;i<=100;i++)t[i] = 0;
 
  while(scanf("%d",&n)!=EOF){
    t[n]++;
    if(max<t[n])max = t[n];
  }
 
  for(i=0;i<=100;i++)
    if(t[i]==max)printf("%d\n",i);
 
  return 0;
}


Measured memory_bytes: 2028
/**
*    author:  boutarou
*    created: 28.09.2020 18:15:31
**/

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

class UnionFind {
    private:
        vector<int>par;
    public:
        UnionFind(int n) {
            for (int i = 0; i < n; i++) par.push_back(-1);
        }
        int root(int x) {
            if (par[x] < 0) return x;
            else return par[x] = root(par[x]);
        }
        bool same(int x, int y) { return root(x) == root(y);}
        void unite(int x, int y) {
            x = root(x), y = root(y);
            if (x == y) return;
            if (par[x] > par[y]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return;
        }
        int size(int x) { return -par[root(x)];}
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int ans = n - 1;
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (!uf.same(a, b)) {
            uf.unite(a, b);
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3876
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int n;
int sx,sy,gx,gy;
int xa[SIZE],ya[SIZE],xb[SIZE],yb[SIZE],h[SIZE];

typedef double P_type;
typedef complex<P_type> P;
const P_type P_eps = 1e-8;

//??????
double dot(P a, P b) {
  return (a * conj(b)).real();
}

//??????
double cross(P a, P b) {
  return (a * conj(b)).imag();
}

double distance_ls_p(P a, P b, P c) {
  if ( dot(b-a, c-a) < P_eps ) return abs(c-a);
  if ( dot(a-b, c-b) < P_eps ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* ?????????????????? */
bool IntersectionSS(P a1, P a2, P b1, P b2){
    
  //??????a ??¨ ??´???b
  P_type a = cross(b1-b2,a1-b1);
  P_type b = cross(b1-b2,a2-b1);
  
  //??????b ??¨ ??´???a
  P_type c = cross(a1-a2,b1-a1);
  P_type d = cross(a1-a2,b2-a1);
  
  if(a*b < -P_eps && c*d < -P_eps) // T?????????????????? -P_eps
    return true;
  else
    return false;
}

bool check(double r){
  
  P l_s = P(sx,sy);
  P l_g = P(gx,gy);
  
  for(int i=0;i<n;i++){
    P p[4];
    p[0] = P(xa[i],ya[i]);
    p[1] = P(xa[i],yb[i]);
    p[2] = P(xb[i],yb[i]);
    p[3] = P(xb[i],ya[i]);
    double H = min((double)h[i],r);
    double R = sqrt(r*r - (r-H)*(r-H));

    for(int j=0;j<4;j++){
      double dis = distance_ls_p(l_s, l_g, p[j]);
      bool is = IntersectionSS(l_s,l_g,p[j],p[(j+1)%4]);
      bool in = (xa[i] <= sx && sx <= xb[i] && ya[i] <= sy && sy <= yb[i]) ||
        (xa[i] <= gx && gx <= xb[i] && ya[i] <= gy && gy <= yb[i]);
      
      if(dis < R || is || in){
        return false;
      }
    }
  }
  
  for(int i=0;i<n;i++){
    P p[4];
    p[0] = P(xa[i],ya[i]);
    p[1] = P(xa[i],yb[i]);
    p[2] = P(xb[i],yb[i]);
    p[3] = P(xb[i],ya[i]);
    double H = min((double)h[i],r);
    double R = sqrt(r*r - (r-H)*(r-H));

    for(int j=0;j<4;j++){
      double dis1 = distance_ls_p(p[j],p[(j+1)%4],l_s);
      double dis2 = distance_ls_p(p[j],p[(j+1)%4],l_g);
      
      if(dis1 < R || dis2 < R){
        return false;
      }
    }

  }
  
  return true;
}

bool solve(){
  
  
  scanf("%d",&n);

  if(n == 0) return false;

  scanf("%d%d%d%d",&sx,&sy,&gx,&gy);

  for(int i=0;i<n;i++){
    scanf("%d%d%d%d%d",xa+i, ya+i, xb+i, yb+i, h+i);
  }

  double l=0, r=1000;

  while(r-l > 1e-8){
    double mid = (l+r)/2;

    if(check(mid)){
      l = mid;
    }else{
      r = mid;
    }
  }

  printf("%.7lf\n",l);
  
  return true;
}

int main(){

  while(solve());
  
  return 0;
}

Measured memory_bytes: 3144
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
n,X=[int(i) for i in input().split()]
x=sorted([int(i) for i in input().split()])
ans=abs(X-x[0])
for i in range(1,n):
    if ans>gcd(ans,abs(X-x[i])):
        ans=gcd(ans,abs(X-x[i]))
print(ans)

Measured memory_bytes: 14224
// https://atcoder.jp/contests/abc049/tasks/arc065_a
"use strict"
function Main(input) {
  let s = input.split('\n')[0];
  const reverseS = s.split('').reverse().join('');
  const words = ['dream', 'dreamer', 'erase', 'eraser'].map(word => word.split('').reverse().join(''));
  let index = 0;

  while(true) {
    const findS = words.find((word) => {
      return reverseS.startsWith(word, index);
    })

    if (!findS) break;
    index += findS.length
  }

  if(index === reverseS.length) {
    console.log('YES');
  } else {
    console.log('NO');
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9628
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define PrintArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;
#define PrintPairs(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i].fi <<"," << cont[__i].se<<")";} cout<<endl;
#define Print(v) cout<<v<<endl;
#define PDBG() cout<<"Line:"<<__LINE__<<endl;
#define PrintArray2D(cont, fh, th, fw, tw) for(int __i=fh;__i<th;++__i){for(int __j=fw;__j<tw;++__j) {cout<<cont[__i][__j]<<" ";} cout<<endl;}cout<<endl;
#define Resize(cont,W,V) cont.resize(W,V);
#define Resize2D(cont,H,W,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W,V);
#define Resize3D(cont,H,W,D,V) cont.resize(H);for(int i=0;i<H;++i)cont[i].resize(W);for(int i=0;i<H;++i)for(int j=0;j<W;++j)cont[i][j].resize(D,V);
/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 * priority_queue<int,vector<int>, greater<int>> Q;
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
/*
struct PairComp{
    int operator()(P l, P r) const {
        return l.fi==r.fi?l.se<r.se:l.fi<r.fi;
    }
};*/
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;

int main() {
    cout.precision(15);
    cout << fixed;
    ll N;
    cin >> N;
    ll v[4]={0,0,0,0};
    string s[]={"AC","WA","TLE","RE"};
    REP(i,N) {
        string S;
        cin >> S;
        REP(j,4) {
            if (S[0]==s[j][0]) {
                v[j]++;
            }
        }
    }
    REP(i,4) {
        cout<<s[i]<<" x "<<v[i]<<endl;
    }
}


Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int min2 = Integer.MAX_VALUE;
        int n = sc.nextInt();
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            int cnt = 0;
            while(a % 2 == 0){
                cnt++;
                a /= 2;
            }
            min2 = Math.min(min2,cnt);
        }
        System.out.println(min2);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23380
#include "bits/stdc++.h" // {{{
#include <float.h>
using namespace std;
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define X           first
#define Y           second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      (int)(1e##p)
#define FILL(a,val) memset((a), (val), sizeof(a))
#define FAST()      ios::sync_with_stdio(false), cin.tie(nullptr)
#ifdef DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t= " << (x) << '\n'
#define line()      fputs("\n--------------------------------\n", stderr)
#else
#define debug(...)
#define show(x)
#define LN()
#endif
using ll  = long long;
using pii = pair<int,int>;
TMPLT(T,U) inline bool chmax(T &a, U b){return b>a ? a=b,1 : 0;}
TMPLT(T,U) inline bool chmin(T &a, U b){return b<a ? a=b,1 : 0;}
TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y) { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
inline bool inner(int val, int min, int max){ return min <= val && val < max; }
constexpr int INF   = 0x3f3f3f3f;
constexpr ll LINF   = 0x3f3f3f3f3f3f3f3fLL;

namespace ydk{ // }}}

constexpr int MXN = ten(5) + 10;

signed _vim_is_god_()
{
    int N, T, A;
    int pos = 0;
    double dif = DBL_MAX;

    cin >> N >> T >> A;
    rep(i, N) {
        int h;
        cin >> h;

        double t = T  - (double)h * 0.006;
        if (chmin(dif, fabs(t - A))) {
                pos = i;
        }
    }

    outl(pos + 1);
    return 0;
}

} // {{{

signed main(){cout << fixed << setprecision(9); ydk::_vim_is_god_(); return 0;} // }}}



Measured memory_bytes: 256
fun main(args: Array<String>) = yorukatsu13d()

fun yorukatsu13d() {
    val n = readLine()!!.toLong()

    val list = setOf('3', '5', '7')

    var answer = 0

    fun dfs(num: Long) {
        if (num > n) return
        if (num.toString().toSet() == list) answer++
        for (c in list) dfs(num * 10 + Character.getNumericValue(c))
    }

    dfs(0L)

    println(answer)
}


Measured memory_bytes: 46104
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<pair<ll, ll> >
#define vl vector<ll>
#define vi vector<int>
#define vii vector<pair<int, int> >
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
using namespace std;

ll power_mod(ll x, ll y, ll p)
{
	ll ans = 1;
	x = x%p;
	if(x==0)
	return p;

	while(y>0)
	{
		if(y&1)
		{
			ans = (ans*x)%p;
		}
		y = y>>1;
		x = (x*x)%p;
	}
	return ans;
} 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll i,j,k,l,m,n;
	ll a,b,c;
	cin>>a>>b;
	cout<<6-a-b;
	
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,sum=0,t;
	cin>>n;
	t=n;
	while(t!=0)
	{
		sum+=t%10;
		t/=10;
	}
	if(n%sum==0)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

def main():
    h, w = map(int, input().split())
    s = [input() for i in range(h)]

    inf = h * w
    dp = [[inf for j in range(w)] for i in range(h)]

    q = deque()
    for i, si in enumerate(s):
        for j, sij in enumerate(si):
            if sij == '#':
                q.append((i, j))
                dp[i][j] = 0

    dijs = list(zip([-1, 0, 1, 0], [0, -1, 0, 1]))
    while q:
        i, j = q.popleft()
        for di, dj in dijs:
            ni = i + di
            nj = j + dj
            if not (0 <= ni < h and 0 <= nj < w): continue
            if dp[ni][nj] <= dp[i][j] + 1: continue
            q.append((ni, nj))
            dp[ni][nj] = dp[i][j] + 1

    print(max(max(dpi) for dpi in dp))

main()

Measured memory_bytes: 88540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w;
    cin >> h >> w;
    
    rep(i, h) {
        rep(ii, w) {
            string s;
            cin >> s;
            
            if (s == "snuke") {
                cout << (char)(ii + 'A') << i + 1 << endl;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}

vector<ll> enum_div(ll n){//yakusu
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
      if(n%i == 0){
        ret.push_back(i);
        if(i*i!=n)ret.push_back(n/i);
      }
  }
  return ret;
}

int main(){

  ll n,m,ans=0;

  cin >> n >> m;
  for(auto x:enum_div(m)){
    ll k = m / x;
    if(k>=n)ans = max(ans,x);
  }

  cout << ans << endl;


}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.nextLine());
        Integer[] an = new Integer[N];
        for (int i = 0; i < N; i++) {
            an[i] = Integer.parseInt(sc.next());
        }

        // 効率よくカードを引くのでソートする
        Arrays.sort(an, Comparator.reverseOrder());

        int alice = 0;
        int bob = 0;
        for (int i = 0; i < N; i++) {
            if (i % 2 == 0) {
                alice += an[i];
            } else {
                bob += an[i];
            }

        }

        System.out.println(alice - bob);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void){
    char s[5], c;
    int len=0;
    int i=0, flg=0;

    while(isalnum(c = getchar()))
        s[len++] = c;

    while(i < len-1){
        if(s[i] == 'A' && s[i+1] == 'C')
            flg = 1;
        i++;
    }
    if(flg) printf("Yes\n");
    else printf("No\n");

    return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    bool D[10];
    rep(i, 10) D[i] = true;
    rep(i, K)
    {
        int tmp;
        cin >> tmp;
        D[tmp] = false;
    }
    for (int i = N; i <= 10 * N; i++)
    {
        string s = to_string(i);
        bool check = true;
        int M = s.size();
        for (int j = 0; j < M; j++)
        {
            if (D[s[j] - '0'] == false)
                check = false;
        }
        if (check == true)
        {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const _s = stdin.split('\n')[0]
const s = Number(_s)

function fx(n) {
  if (n % 2 === 0) {
    return n / 2
  } else {
    return 3 * n + 1
  }
}

let i = 0
let ai = [s]

while (true) {
  i++
  let r = 0

  if (i === 1) {
    r = fx(s)
  } else {
    r = fx(ai[i - 1])
  }

  if (ai.indexOf(r) > -1) {
    ai.push(r)
    break
  }
  ai.push(r)
}

console.log(ai.length)


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
  	for(int i=0;i<s.length();i++){
    	if(i&1){if(s[i]=='R'){cout<<"No";return 0;}}
      	else if(s[i]=='L'){cout<<"No";return 0;}
    }
  	cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int K = sc.nextInt();
        //String S = sc.next();

        int a;
        if(t+K<10){
            System.out.println(t+K);
        }else{
            System.out.println("error");
        }
        
                
            

        }
        
        

        
        
        }

Measured memory_bytes: 35580
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let n: usize = get_input().parse().unwrap();

    let mut v:Vec<i64> = Vec::new();
    let vline = get_input();
    for l in vline.split_whitespace() {
        v.push(l.parse().unwrap());
    }

    let mut c:Vec<i64> = Vec::new();
    let cline = get_input();
    for l in cline.split_whitespace() {
        c.push(l.parse().unwrap());
    }

    let pow:Vec<i64> = (0..(1 << n))
        .map(|i| (0..n)
             .filter(|j| i & (1 << j) > 0)
             .map(|i| v[i] - c[i])
             .sum())
        .collect();
    let ans = pow.iter().max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,a,b;
    while(~scanf("%d%d%d",&n,&a,&b))
    {
        if(n==1)
        printf("Hello World\n");
        else if(n==2)
            printf("%d\n",a+b);
    }
    return 0;
}


Measured memory_bytes: 128
from collections import deque

s=input()
q=int(input())
count=0 #何回反転があるか
ss=deque(s)
flag=True #通常状態
for i in range(q):
    info=input()
    if info[0]=="1":
        count+=1
        if flag:
            flag=False
        else:
            flag=True
    else:
        _,f,c=info.split()
        if flag:
            if f=="1":
                ss.appendleft(c)
            else:
                ss.append(c)
        else: #反転状態
            if f=="1":
                ss.append(c)
            else:
                ss.appendleft(c)
ans="".join(ss)
print(ans if count%2==0 else ans[::-1])

Measured memory_bytes: 8564
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#define rep(i,l,r) for(ll i=l;i<r;i++)
#define rew(i,l,r) for(ll i=r-1;i>=l;i--)

typedef long long ll;

ll min(ll a, ll b) { return a < b ? a : b; }

int main() {
    ll N, W;
    scanf("%lld%lld", &N,&W);
    ll v[101], w[101];
    rep(i, 0, N) {
        scanf("%lld%lld", &w[i], &v[i]);
    }
    ll dp[100001];
    rep(i, 0, 100001) dp[i] = 1000000000000;
  	dp[0]=0;
    rep(i, 0, N) {
        rew(j, v[i], 100001) {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
        }
    }
  	ll ans = 100000;
    while (dp[ans] > W) ans--;
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 2912
import java.util.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] s = new long[n];
        for(int i = 0; i < n; i++){
            s[i] = sc.nextLong();
        }
        int q = sc.nextInt();
        long t = 0;
        
        int ans = 0;
        for(int i = 0; i < q; i++){
            t = sc.nextLong();
            int left = 0;
            int right = n;
            while(left < right){
                int mid = (left + right)/2;
                if(s[mid] == t){
                    ans ++;
                    break;
                }else if(t < s[mid]){
                    right = mid;
                }else{
                    left = mid + 1;
                }
            }
        }
        
        
        System.out.println(ans);
    }
}



Measured memory_bytes: 69168
#include<cstdio>
const static int MAX_D = 365;
int c[26], s[MAX_D][26], S, last[26];

int main(){
    int D;
    scanf("%d", &D);
    for (int i = 0; i < 26; i++){
        scanf("%d", c + i);
    }
    for (int i = 0; i < D; i++){
        for (int j = 0; j < 26; j++){
            scanf("%d", &s[i][j]);
        }
    }
    int candidate, best_type;
    for (int i = 1; i <= D; i++){
        best_type = 0;
        candidate = S + s[i-1][0];
        for (int j = 1; j < 26; j++){
            candidate -= c[i]*(i - last[j]);
        }
        S = candidate;
        for (int j = 1; j < 26; j++){
            candidate = candidate + s[i-1][j] - s[i-1][j-1] + c[j]*(i - last[j]) - c[j-1]*(i - last[j-1]);
            if(S < candidate){
                S = candidate;
                best_type = j;
            }
        }
        last[best_type] = i;
        printf("%d\n", best_type+1);
    }
	return 0;
}

Measured memory_bytes: 1748
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main ()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int x,y,z;
	x = abs(a-b);
	y = abs(a - c);
	z = abs(b-c);
	int s;
	s = min(x+y,min(z+y,x+z));
	printf("%d\n",s);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
  int i;
  char s[1000000],t[1000000];
  scanf("%s %s",&s,&t);
  int a=0;
  for(i=0;s[i]!='\0';i++){if(s[i]!=t[i]){a++;}}
  printf("%d",a);
  return 0;
}


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

using namespace std;

#define ll long long

const int MAXN = 1001;
const int mod = 1000000007;

int n;
int m;
int a[MAXN + 1];
int b[MAXN + 1];
int Max[MAXN + 1][MAXN + 1];
int s[MAXN * MAXN + 1];
int A[MAXN * MAXN + 1];
int B[MAXN * MAXN + 1];
int S[MAXN * MAXN + 1];

int main() {
	memset(Max, 127, sizeof(Max));
	ll res = 1;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if(A[a[i]]) {
			puts("0");
			return 0;
		}
		A[a[i]] = i;
		for(int j = 1; j <= m; j++)
			Max[i][j] = min(Max[i][j], a[i]);
	}
	for(int j = 1; j <= m; j++) {
		scanf("%d", &b[j]);
		if(B[b[j]]) {
			puts("0");
			return 0;
		}
		B[b[j]] = j;
		for(int i = 1; i <= n; i++)
			Max[i][j] = min(Max[i][j], b[j]);
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			s[Max[i][j]]++;
			S[a[i]] += Max[i][j] == a[i];
			S[b[j]] += Max[i][j] == b[j];
		}
	for(int i = n * m; i >= 1; i--) if(A[i] && B[i]) S[i] = 1;
	for(int i = n * m; i >= 1; i--) {
		s[i] += s[i + 1];
		if(A[i] || B[i])
			res = res * S[i] % mod;
		else
			res = res * s[i] % mod;
		s[i]--;
	}
	printf("%lld\n", res);
  return 0;
}

Measured memory_bytes: 13696
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
power=1
for i in range(1,n+1):
    power=(power*i)%mod
print(power)


Measured memory_bytes: 3316
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n,k = list(map(int, input().split()))

# C,Pを求める前処理
m = 4*10**5
mod = 10**9 + 7


fact = [0]*(m+5)
fact_inv = [0]*(m+5)
inv = [0]*(m+5)

fact[0] = fact[1] = 1
fact_inv[0] = fact_inv[1] = 1
inv[1] = 1

for i in range(2,m+5):
    fact[i] = fact[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod

# nCkをmod（素数）で割った余りを求める．ただしn<10**7
# 前処理はm=n+5まで
def cmb(n,k,mod):
    return fact[n] * (fact_inv[k] * fact_inv[n-k] % mod) % mod

if k >= n-1:
    print(cmb(2*n-1, n-1, mod)%mod)
else:
    ans = 0
    for i in range(0,k+1):
        ans += cmb(n,i,mod)*cmb(n-1,n-i-1,mod)%mod
        ans %= mod
    print(ans)






Measured memory_bytes: 56836
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <stdio.h>

int main(){
	int n, k;
	std::cin >> n >> k;
	if(2*k-1<=n){
		std::cout << "YES" << std::endl;
	}else{
		std::cout << "NO" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split()))

all_xor = 0
for i in range(N):
    all_xor = all_xor^a[i]

answer = [a[i]^all_xor for i in range(N)]

print(' '.join(map(str, answer)))

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

int main(){
int x, a, b;
cin >> x >> a >> b;
if(b - a <= 0){
  cout << "delicious" << endl;
}else if(b - a <= x){
  cout << "safe" << endl;
}else{
  cout << "dangerous" << endl;
}
}

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

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

  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);

  rep( i, 0, N   ) {cin >> A.at(i); A.at(i)--;}
  rep( i, 0, N   )  cin >> B.at(i);
  rep( i, 0, N-1 )  cin >> C.at(i);

  int Ans = 0;
  rep( i, 0, N ) {
    Ans += B.at( A.at(i) );
    if ( 0<i && A.at(i)==A.at(i-1)+1 ) Ans += C.at( A.at(i-1) );
  }
  cout << Ans << endl;
}


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

string S;
long long x, y;

vector<long long> yoko;
vector<long long> tate;
#define OFFSET 10000
bool yokodp[20000];
bool yokodpnext[20000];
bool tatedp[20000];
bool tatedpnext[20000];

int main(){
	cin >> S;
	cin >> x >> y;

	long long firstmove = 0;
	long long move = 0;
	bool firstflag = true;
	bool yokoflag = false;

	for(long long i = 0; i < S.size(); i++){
		if(firstflag){
			if(S[i] == 'F'){
				firstmove++;
			}else{
				firstflag = false;
			}
		}else{
			if(yokoflag){
				if(S[i] == 'F'){
					move++;
				}else{
					yoko.push_back(move);
					move = 0;
					yokoflag = false;
				}
			}else{
				if(S[i] == 'F'){
					move++;
				}else{
					tate.push_back(move);
					move = 0;
					yokoflag = true;
				}
			}
		}
	}


	if(yokoflag){
		yoko.push_back(move);
	}else{
		tate.push_back(move);
	}

	yokodp[OFFSET + firstmove] = true;

	for(long long i = 0; i < yoko.size(); i++){
		//cout << "yoko[" << i << "]=" << yoko[i] << endl;
		for(long long j = 0; j < 20000; j++){
			if(yokodp[j]){
				yokodpnext[j + yoko[i]] = true;
				yokodpnext[j - yoko[i]] = true;
			}
		}
		for(long long j = 0; j < 20000; j++){
			yokodp[j] = yokodpnext[j];
			yokodpnext[j] = false;
		}
	}


	tatedp[OFFSET] = true;

	for(long long i = 0; i < tate.size(); i++){
		//cout << "tate[" << i << "]=" << tate[i] << endl;
		for(long long j = 0; j < 20000; j++){
			if(tatedp[j]){
				tatedpnext[j + tate[i]] = true;
				tatedpnext[j - tate[i]] = true;
			}
		}
		for(long long j = 0; j < 20000; j++){
			tatedp[j] = tatedpnext[j];
			tatedpnext[j] = false;
		}
	}

	if(yokodp[OFFSET + x] && tatedp[OFFSET + y]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
from collections import defaultdict

N = int(input())
arr = list(map(int, input().split()))
a_set = sorted(set(arr), reverse=True)
a_dict = defaultdict(int)
for num in arr:
    a_dict[num] += 1
a, b = 0, 0
for num in a_set:
    if a_dict[num] > 3 and a == 0:
        a, b = num, num
        break
    elif a_dict[num] > 1 and a == 0:
        a = num
    elif a_dict[num] > 1:
        b = num
        break

print(a * b)


Measured memory_bytes: 71444
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;


LL N;


int main() {
	cin >> N;
	if (N % 2 == 1) {
		cout << 0 << endl;
	}
	else {
		N /= 2;
		LL ans = 0;
		LL five = 5;
		while (N / five != 0) {
			ans += N / five;
			five *= 5;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 888