akhauriyash/Code-Regression huggingface dataset:
/**
 *
 * AtCoder Beginner Contest 107 - Problem D: Median of Medians (https://beta.atcoder.jp/contests/abc107/tasks/arc107_b)
 *
 * Find the median of the medians of all intervals of indexes [i, j].
 *
 * Divide and conquer solution: first find all possible answers in increasing order (unique values 
 * as[i]).  Binary search the answer: for each x, find all pairs (i, j) such the the median is
 * equals or greater then x. If the amount is greater than the half of all pairs 
 * (i.e., ceil(N * (N + 1)/2)), then x can be the answer. The answer is the greater x.
 *
 * To compute the number of pairs required, precompute the prefix sums S[i], where each element
 * less the x is -1, equals is zero and greater is 1. The the pair (i, j) has median greatear of
 * equals to x if S[j] - S[i - 1] >= 0. So count the 'inversions' in O(N log N) (an 'inversion'
 * is a pair (i, j) such as j >= i).
 */
#include <iostream>
#include <set>
#include <vector>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define REP(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)

const int MAX { 2000010 };

int as[MAX], xs[MAX], S[MAX], temp[MAX];

ll inversions(int a, int b)
{
    if (b - a == 1)
        return 0;

    int m = b + (a -  b)/2;

    auto sum = inversions(a, m) + inversions(m, b);

    int x = a, y = m, idx = 0;

    while (x < m and y < b)
    {
        if (S[x] <= S[y])
            temp[idx++] = S[x++];
        else
        {
            temp[idx++] = S[y++];
            sum += (x - a);
        }
    }    

    while (x < m)
    {
        temp[idx++] = S[x++];
    }

    while (y < b)
    {
        temp[idx++] = S[y++];
        sum += (m - a);
    }

    for (int i = a; i < b; ++i)
        S[i] = temp[i - a];

    return sum;
}

ll pairs_with_median_geq(int x, int N)
{
    S[0] = 0;

    REP(i, 1, N)
        S[i] = S[i - 1] + (as[i] >= x ? 1 : -1);

    return inversions(0, N + 1);    // (i, j) is a 'inversion' if j >= i
}

void solve(ll N)
{
    set<int> ns;

    REP(i, 1, N)
        ns.insert(as[i]);

    vector<int> ys(ns.begin(), ns.end());

    int a = 0, b = ys.size() - 1, ans = -1;
    auto pairs = N * (N + 1) / 2;

    while (a <= b)
    {
        auto m = a + (b - a)/2;

        if (pairs_with_median_geq(ys[m], N) >= (pairs + 1)/2)
        {
            ans = max(ans, ys[m]);
            a = m + 1;
        } else
            b = m - 1;
    }

    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    REP(i, 1, N)
        cin >> as[i];

    solve(N);

    return 0;
}


Measured memory_bytes: 11904
# https://atcoder.jp/contests/abc134/tasks/abc134_c

N = int(input())

max_a = 0
max_i = 0
max_a_2 = 0

for i in range(N):
    A = int(input())
    
    if A >= max_a:
        max_a_2 = max_a
        max_a = A
        max_i = i

    elif A >= max_a_2:
        max_a_2 = A

for i in range(N):
    if i != max_i:
        print(max_a)

    else:
        print(max_a_2)




Measured memory_bytes: 4540
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,
        a:[f64;n],
    }
    //    mut  a:[f64;n],

    let mut b = vec![0i128; n];
    for i in 0..n {
        b[i] = (a[i] * 1e9 + 0.5f64) as i128;
    }
    let mut c = vec![];
    let mut tfs = vec![vec![0i64; 37]; 37];
    for &x in b.iter() {
        let mut two = 0;
        let mut five = 0;
        let mut y = x;
        while y % 2 == 0 {
            y /= 2;
            two += 1;
        }
        while y % 5 == 0 {
            y /= 5;
            five += 1;
        }

        if two >= 18 {
            two = 18;
        }
        if five >= 18 {
            five = 18;
        }
        c.push((two, five));
        tfs[two][five] += 1i64;
    }
    let mut ans = 0i64;
    for &(two, five) in c.iter() {
        for i in (18 - two)..19 {
            for j in (18 - five)..19 {
                ans += tfs[i][j];
            }
        }
        if two >= 9 && five >= 9 {
            ans -= 1;
        }
    }
    println!("{}", ans >> 1);
}

const eps: f64 = 1e-10;


Measured memory_bytes: 12636
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, ans;
vector<Int> a;

Int solve(){
	if(a[0] != 0) return -1;
	for(size_t i=1; i<a.size(); ++i)
		if(a[i] > a[i-1] + 1)
			return -1;
	Int res = 0;
	for(size_t i=1; i<a.size(); ++i){
		if(a[i] == a[i-1] + 1) ++res;
		else res += a[i];
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for(auto &i:a) cin >> i;
	cout << solve() << "\n";
}

Measured memory_bytes: 1792
#include <iostream>

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

   int max = A;
   if(max<B) max = B;
   if(max<C) max = C;

   if(max==A) std::cout << 10*A + B + C << std::endl;
   else if(max==B) std::cout << A + 10*B + C << std::endl;
   else if(max==C) std::cout << A + B + 10*C << std::endl;

   return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var s ,t = "", ""
	fmt.Scan(&s, &t)

	x := 0
	for i := 0; i < len(s); i++{
		if s[i] != t[i] {
			x += 1
		}
	}

	fmt.Printf("%v", x)

}




Measured memory_bytes: 3484
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<bits/stdc++.h>
#define ll long double
using namespace std;
 
int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	ll r;
	cin>>r;
	
	ll c=2*3.141592653589793238*r;
	
	cout<<fixed<<setprecision(20)<<c<<endl;
    
    return 0;
 
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m, n) for(ll i = m; i <= n; i++)
#define per(i, m, n) for(ll i = m; i >= n; i--)
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll> 
#define vi vector<ll> 
#define vll vector<ll> 
#define sz(v) (ll) v.size()
const ll INF = 0x3f3f3f3f;

const ll maxn = 2e5 + 5;

ll N, a[maxn], dif[maxn]; 

int main() {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0); 
    ll sum = 0, ans = 1e18, num = -N; //num is the coefficient for b; 
    cin >> N;
    rep(i, 1, N) cin >> a[i], dif[i] = a[i] - i, sum += dif[i];
    sort(dif + 1, dif + N + 1);
    for (ll i = 0; i <= N; i++) {
    	// exactly 1 - i are negative and i + 1 - N are positive 
    	num = - N + 2 * i; 
    	sum -= 2 * dif[i]; //calculate the sum
    	// dif[i] <= b <= dif[i + 1]; 
		if (i == 0) ans = min(ans, sum + num * dif[1]); 
    	else if (i == N) ans = min(ans, sum + num * dif[N]); 
    	else ans = min(ans, min(sum + num * dif[i], sum + num * dif[i + 1])); 
    }
    cout << ans << "\n"; 
    return 0; 
}

Measured memory_bytes: 6768
#include <iostream>
#include <string>
#include <algorithm>
#include<cstdio>
#include<map>
#include<cstring>
using namespace std;
typedef long long ll;
const int man=200005;
int n,m;
int a[man];

int main()
{
   //freopen("in.txt","r",stdin);
   cin>>n;
   int ans=0;
   int base=1;
   while(n)
   {
       if(n%10==1)
         ans+=9*base;
       else if(n%10==9)
        ans+=1*base;
       else
        ans+=(n%10)*base;
       n/=10;
       base*=10;
   }
   cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=1111,M=111111;
int l,m,n,t,C;
int a[N];
ll dp[N];
int main(){
#ifdef LOCAL
	freopen("D.in","r",stdin);//freopen("D.out","w",stdout);
#endif
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]);
	dp[0]=1000;
	rep(i,1,n){
		dp[i]=dp[i-1];
		rep(j,1,i-1)MAX(dp[i],dp[j-1]/a[j]*a[i]+dp[j-1]%a[j]);
	}
	printf("%lld\n",dp[n]);
	return 0;
}


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


int main() {
    int N,M;
    cin >> N >> M;
    vector<int> X(N + 1);
    vector<int> Y(M + 1);
    cin >> X[0] >> Y[0];
    rep(i,N) {
        cin >> X[i + 1];
    }
    rep(j,M) {
        cin >> Y[j + 1];
    }
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    if (X[N] < Y[0]) {
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }

}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
int main(){
    string s;cin>>s;
    vector<vector<ll> >dp(s.size(),vector<ll>(13));
    if(s[0]=='?'){
        rep(i,10){
            dp[0][i]=1;
        }
    }else{
        dp[0][s[0]-'0']=1;
    }
    REP(i,1,s.size()){
        if(s[i]=='?'){
            rep(j,13){
                rep(k,10){
                    dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%inf;
                }
            }
        }else{
            ll k=s[i]-'0';
            rep(j,13){
                dp[i][(j*10+k)%13]=(dp[i][(j*10+k)%13]+dp[i-1][j])%inf;
            }
        }
    }
    cout<<dp[s.size()-1][5]<<endl;
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long k, x, a, b;
	cin >> k >> x;

	if(k == 1){
		cout << x;
		return 0;
	}

	a = (x - k) + 1;
	b = (x + k) - 1;
	if(a < -1000000){
		a = -1000000;
	} else if(b > 1000000){
		b = 1000000;
	}
	for(int i = a; i <= b; i++){
		cout << i << ' ';
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(c == b) cout << a << endl;
    else if(a == c) cout << b << endl;
    else if(a == b) cout << c << endl;
    
}

Measured memory_bytes: 256
using System;
class Program {
    static void Main(string[] args){
        string[] input = Console.ReadLine().Split(' ');
        int r = int.Parse(input[0]);
        int d = int.Parse(input[1]);
        int x = int.Parse(input[2]);
        for(int i = 0; i < 10; i++){
            x = r * x - d;
            Console.WriteLine(x);
        }
    }
}

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

#define AMAX 300005

int op(int a, int b){
	return max(a, b);
}

int e(){
	return 0;
}

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

	segtree<int, op, e> seg(AMAX);
	rep(i, n){
		int mx=seg.prod(max(0, a[i]-k), min(AMAX, a[i]+k+1));
		seg.set(a[i], mx+1);
	}

	int ans=seg.all_prod();
	cout<< ans <<endl;
	return 0;
}


Measured memory_bytes: 9628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    if(n<1000) cout<<"ABC"<<endl;
    else cout<<"ABD"<<endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 222;

vector<pair<int,int>> moves = { make_pair(0,1), make_pair(1,0),
				make_pair(0,-1), make_pair(-1,0) };

int n, m;
string g[maxn];
int dist[maxn][maxn];
struct node {
  int x,y,d;
};
int ans;
void bfs(int i, int j) {
  memset(dist, -1, sizeof dist);
  queue<node> q;
  q.push({i,j,0});
  dist[i][j]=0;
  while (q.size()) {
    node at = q.front(); q.pop();
    int d = at.d;
    for (auto mo: moves) {
      int x = at.x+mo.first;
      int y = at.y+mo.second;
      if (x<0 || x>=n || y<0 || y>=m || g[x][y]=='#' || dist[x][y]!=-1) continue;
      dist[x][y] = d+1;
      q.push({x,y,d+1});
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      ans = max(dist[i][j], ans);
    }
  }
}

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

  cin>>n>>m;
  for (int i=0; i<n; i++) {
    cin>>g[i];
  }
  
  for (int i=0; i<n; i++) {
    for (int j=0; j<m; j++) {
      if (g[i][j]=='#') continue;
      bfs(i,j);
    }
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int n;
double dp[3000];

int main(){
  scanf("%d", &n);
  dp[0] = 1;
  for(int i = 1; i <= n; i++){
    double p;
    scanf("%lf", &p);
    for(int j = i; j >= 0; j--){
      dp[j+1] += dp[j] * p;
      dp[j] *= 1-p;
    }
  }
  double ans = 0;
  for(int i = n/2+1; i <= n; i++) ans += dp[i];
  printf("%.16f\n", ans);

  return 0;
}


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


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    n = next_int()
    str = ["AC", "WA", "TLE", "RE"]
    awtr = [0] * 4
    for _ in range(n):
        s = next_line()
        if s == "AC":
            awtr[0] += 1
        elif s == "WA":
            awtr[1] += 1
        elif s == "TLE":
            awtr[2] += 1
        else:
            awtr[3] += 1
    for i in range(4):
        print(str[i] + " x ", end="")
        print(awtr[i])


if __name__ == '__main__':
    main()


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

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

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

ll Pow (ll a, ll b) {
	ll x = 1, y = a;
	while (b) {
		if (b % 2) x = x * y % MOD;
		y = y * y % MOD;
		b /= 2;
	}
	return x;
}

const int N = 410;

ll dp[N][N], pw[N][N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, c;
	cin >> n >> c;
	vector<ll> a(n), b(n);
	forn(i, 0, n) cin >> a[i];
	forn(i, 0, n) cin >> b[i];
	forn(i, 0, N) {
		pw[i][0] = 0;
		forn(j, 1, N) pw[i][j] = (pw[i][j - 1] + Pow(j, i)) % MOD;
	}
	dp[0][0] = 1;
	fore(i, 1, n) {
		fore(j, 0, c) {
			fore(k, 0, j) {
				ll add = pw[j - k][b[i - 1]] - pw[j - k][a[i - 1] - 1];
				if (add < 0) add += MOD;
				dp[i][j] += dp[i - 1][k] * add;
				dp[i][j] %= MOD;
			}
			//cerr << i << ' ' << j << ' ' << dp[i][j] << '\n';
		}
	}
	cout << dp[n][c] << '\n';
	return 0;
}


Measured memory_bytes: 2816
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

ll GCD(ll a, ll b) {
    return b ? GCD(b ,a%b) : a;     
}

int main() {
    ll a,b; cin >> a >> b;
    cout << a * b / GCD(a,b) << "\n";
}

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

#include <atcoder/all>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    auto g = atcoder::dsu(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t) {
            cout << (g.same(u, v) ? 1 : 0) << endl;
        } else {
            g.merge(u, v);
        }
    }
}

Measured memory_bytes: 3984
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=readln.split.to!(int[]);

  auto num=new int[](9);
  foreach(e; a){
    foreach(i; 0..8){
      if(i*400<=e && e<(i+1)*400){
        num[i]++; break;
      }
    }
    if(e>=3200){
      num[$-1]++;
    }
  }
  auto lb=reduce!((r, e)=>(r+(e>0 ? 1 : 0)))(0, num[0..$-1]);
  if(num[$-1]==0){
    writeln(lb, " ", lb);
  }else{
    if(lb==0){
      writeln(1, " ", num[$-1]);
    }else{
      writeln(lb, " ", lb+num[$-1]);
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = mod;

// constexpr long long INF = 1LL << 60;

// Ford-Fulkerson
template <typename T>
class MaxFlow {
  struct Edge {
    int to;
    T cap;
    int rev; // 逆辺のindex(G[to][rev]が逆辺)
  };

 private:
  vector<vector<Edge>> G;
  vector<bool> used;
  int sink;

  // f: 頂点vに流れてきている量
  T dfs(int v, T f) {
    if (v == sink) {
      return f;
    }

    used[v] = true;
    for (auto e = G[v].begin(); e != G[v].end(); e++) {
      if (used[e->to] || e->cap <= 0) {
        continue;
      }

      T d = dfs(e->to, min(f, e->cap));
      if (d > 0) {
        e->cap -= d;
        G[e->to][e->rev].cap += d;
        return d;
      }
    }

    return 0;
  }

 public:
  MaxFlow(int max_v) : G(max_v), used(max_v) {
  }

  void add_edge(int from, int to, T cap) {
    G[from].push_back((Edge){to, cap, (int)G[to].size()});
    G[to].push_back((Edge){from, 0, (int)G[from].size() - 1});
  }

  // source: Start
  // sink: Goal
  T solve(int source, int sink) {
    this->sink = sink;

    T flow = 0;
    for (;;) {
      fill(all(used), false);

      T f = dfs(source, INF);
      if (f == 0) {
        return flow;
      }
      flow += f;
    }
  }

  // 残余グラフ上で始点から到達できる頂点集合をX、それ以外をY
  // とすれば(X, Y)が最小カットの解である。
};

// 二部グラフの最大マッチング
template <typename T>
class BipartiteMatching : private MaxFlow<T> {
 private:
  int num_a;
  int num_b;
  int start;
  int goal;

 public:
  BipartiteMatching(int _num_a, int _num_b)
    : MaxFlow<T>::MaxFlow(_num_a + _num_b + 2),
      num_a(_num_a),
      num_b(_num_b),
      start(_num_a + _num_b),
      goal(_num_a + _num_b + 1) {
    // startからaに辺を引く
    rep(i, num_a) {
      MaxFlow<T>::add_edge(start, i, 1ll);
    }
    // bからgoalに辺を引く
    rep(i, num_b) {
      MaxFlow<T>::add_edge(num_a + i, goal, 1ll);
    }
  }

  void add_edge(int a, int b) {
    MaxFlow<T>::add_edge(a, num_a + b, 1ll);
  }
  T solve() {
    return MaxFlow<T>::solve(start, goal);
  }
};

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

  ll x, y, e;
  cin >> x >> y >> e;

  BipartiteMatching<ll> bm(x, y);

  rep(i, e) {
    ll a, b;
    cin >> a >> b;
    bm.add_edge(a, b);
  }

  cout << bm.solve() << endl;

  return 0;
}



Measured memory_bytes: 3732
X = int(input())

ans = 1
if X > 6 and X <= 11:
    ans = 2
elif X > 11:
    p, q = divmod(X, 11)
    ans = p*2
    if q > 0 and q <= 6:
        ans += 1
    if q > 6 and q <= 10:
        ans += 2

print(ans)

Measured memory_bytes: 3060
def solve():
    N,M = map(int, input().split())
    graph = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)
        
    ret = False
    for cod_1 in graph[1]:
        if N in graph[cod_1]:
            ret = True
            
    print('POSSIBLE' if ret else 'IMPOSSIBLE')
    
solve()

Measured memory_bytes: 38320
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    Solution sol;

    int n;
    cin >> n;
    vector<int> A(n);
    vector<int> B(n);
    vector<int> C(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> B[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> C[i];
    }

    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    long long res = 0;
    for (auto x : B) {
        auto it = lower_bound(A.begin(), A.end(), x);
        long long L = it - A.begin();
        auto it2 = upper_bound(C.begin(), C.end(), x);
        long long R = C.end() - it2;

        res += L * R;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 4524
def main():

    for i in range(1, K+1):
        for rm in cl:
            if rm > i:
                continue
            if dpt[i - rm] == 0:
                dpt[i] = 1
                break
        else:
            dpt[i] = 0

if __name__ == '__main__':
    N, K = map(int, input().split())
    cl = list(map(int, input().split()))
    dpt = [-1 for i in range(K+1)]
    dpt[0] = 0

    main()
    if dpt[K] == 0:
        print('Second')
    else:
        print('First')



Measured memory_bytes: 9892
# Your code here!

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

@count = 0

def merge(a, l, m, r)
  l_arr = a[l, m-l] << 10000000000000000000
  l_i = 0
  r_arr = a[m, r-m] << 10000000000000000000
  r_i = 0
  
  (l...r).each do |idx|
    # 小さい方から入れていく
    if l_arr[l_i] <= r_arr[r_i]
      a[idx] = l_arr[l_i]
      l_i+=1
    else
      a[idx] = r_arr[r_i]
      r_i+=1
    end
    @count += 1
  end
end

def merge_sort(a, left, right)
  if 1 < right-left
    mid = (right+left)/2
    merge_sort(a, left, mid)
    merge_sort(a, mid, right)
    merge(a, left, mid, right)
  end
end

merge_sort(a, 0, n)
puts a.map(&:to_s).join(' ')
p @count


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

template<typename T>
ostream& operator << (ostream &out, vector<T> &v) {
	for (auto ele : v) out << ele << " ";
	out << '\n';
	return out;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int x1, x2, x3, x4, x5;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if (!x1) cout << 1;
	else if (!x2) cout << 2;
	else if (!x3) cout << 3;
	else if (!x4) cout << 4;
	else cout << 5;
}

Measured memory_bytes: 3564
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

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

int main() {
  string a[3];
  cin >> a[0] >> a[1] >> a[2];
  int p[3]; p[0] = p[1] = p[2] = 0;
  int cur = 0;
  while (p[cur] < a[cur].size()) {
    if (a[cur][p[cur]] == 'a') {
      p[cur]++;
      cur = 0;

    } else if (a[cur][p[cur]] == 'b') {
      p[cur]++;
      cur = 1;

    } else {
      p[cur]++;
      cur = 2;

    }
  }
  if (cur == 0) {
    cout << "A\n";
  } else if (cur == 1) {
    cout << "B\n";
  } else {
    cout << "C\n";
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * https://abc055.contest.atcoder.jp/tasks/abc055_b
 */
public class Main {
	
	static final int MOD = 1000000007;

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		long n = 1;
		for(int i=1; i<=N; i++){
			n = n*i % MOD;
		}
		
		System.out.println(n);
	}
	
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll x[n+5];
    for(ll i=0;i<n;i++)
    {
        cin>>x[i];
    }
    sort(x,x+n);
    ll sum1=0,sum2=0;
    for(ll i=n-1;i>=0;i--)
    {
        if(i%2==0)
        {
            sum1+=x[i];
        }
        else
        {
            sum2+=x[i];
        }
    }
    cout<<abs(sum1-sum2)<<endl;
return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc116/tasks/abc116_c

N = int(input())
h = list(map(int, input().split()))

count = 0

while max(h) > 0:
    is_pouring = False
    for i in range(N):
        if h[i] > 0:
            h[i] -= 1
            if not is_pouring:
                count += 1
                is_pouring = True
        else:  # 0
            is_pouring = False
    # print(h)

print(count)


Measured memory_bytes: 3060
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	bool dig[10];
	int n, k;
	cin >> n >> k;

	rep(i, 0, 10) {
		dig[i] = true;
	}

	rep(i, 0, k) {
		int a;
		cin >> a;
		dig[a] = false;
	}

	for (int i = n;; i++) {
		int t = i; bool key = true;

		while (t >= 10) {
			if (!dig[t % 10]) {
				key = false;
				break;
			}
			t = t / 10;
		}
		if (t<10&&dig[t] && key) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int N,n,i,ans=0,count=0;
  scanf("%d",&N);

  for(n=1; n<=N; n+=2){
    count = 0;

    for(i=1; i<=n; i+=2){
      if(n%i == 0)
        count++;
    }

    if(count == 8)
      ans++;
  }

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 1708
n, k = map(int, input().split())
s = "#" + input()
B = []
L = []
for i in range(n):
  if s[i] != s[i+1]:
    B.append(int(s[i+1]))
    L.append(i+1)
ans = 0
for j, b in enumerate(B):
  if b == 0:
    if j+2*k >= len(L):
      ans = max(ans, n+1 - L[j])
    else:
      ans = max(ans, L[j+2*k] - L[j])
  else:
    if j+2*k+1 >= len(L):
      ans = max(ans, n+1 - L[j])
    else:
      ans = max(ans, L[j+2*k+1] - L[j])
print(ans)

Measured memory_bytes: 7980
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

const [k, x] = input[0].split(' ').map((x: string): number => +x);

if (k*500 >= x){
	console.log('Yes');
}else{
	console.log('No');
}


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

int main() {
    int x, y, ans;
    cin >> x >> y;

    while (true) {
        if (x > y) {
            if (x % y == 0) {
                ans = y;
                break;
            }
            else {
                x = x % y;
            }
        }
        else {
            if (y % x == 0) {
                ans = x;
                break;
            }
            else {
                y = y % x;
            }
        }
    }

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


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

int main(){
  int n;
  int S[]={60,80,100,120,140,160};
  int W[]={2,5,10,15,20,25};
  int M[]={600,800,1000,1200,1400,1600};
  while(cin >> n , n){
    int sum = 0;
    for(int i=0;i<n;i++){
      int x,y,h,w;
      cin >> x >> y >> h >> w;
      int size = x + y + h;
      if(size > 160 || w > 25) continue;
      for(int i=0;i<6;i++){
	if(size <= S[i] && w <= W[i]){
	  sum += M[i];
	  break;
	}
      }
    }
    cout << sum << endl;
  }
}

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

int main(){
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    auto getPositions = [&]() {
        vector<int> res;
        for ( int i = 0; i < n && res.size() < k;) {
            if ( s[i] == 'o') {
                res.push_back(i);
                i += c+1;
            }
            else {
                ++i;
            }
        }
        return res;    
    };
    vector<int> l, r;
    l = getPositions();
    reverse(s.begin(), s.end());
    r = getPositions();
    rep(i, k) r[i] = n-1-r[i];
    reverse(s.begin(), s.end());

    vector<int> lastL(n+1, -1);
    rep(i, k) lastL[l[i]+1] = i;
    rep(i, n) {
        if ( lastL[i+1] == -1 ) lastL[i+1] = lastL[i];
    }
    vector<int> lastR(n+1, -1);
    rep(i, k) lastR[r[i]] = i;
    for ( int i = n - 1; i >= 0; --i ) {
        if ( lastR[i] == -1 ) lastR[i] = lastR[i+1];
    }

    rep(i, n) {
        if ( s[i] == 'x' ) continue;
        int li = lastL[i];
        int ri = lastR[i+1];
        int cnt = 0;
        if ( li != -1 ) cnt += li+1;
        if ( ri != -1 ) cnt += ri+1;
        if ( li != -1 && ri != -1 && r[ri]-l[li] <= c ) {
            --cnt;
        }
        if ( cnt >= k ) continue;
        cout << i+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4984
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split())

if (N >= 2) and (M >= 2):
    C_e = combinations_count(N, 2)
    C_o = combinations_count(M, 2)
    print(C_e + C_o)
elif (N < 2) and (M >= 2):
    C_e = 0
    C_o = combinations_count(M, 2)
    print(C_e + C_o)
elif (N >= 2) and (M < 2):
    C_e = combinations_count(N, 2)
    C_o = 0
    print(C_e + C_o)
else:
    print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int N,K,ANS=0;
	cin >> N >> K;
	for(int i=0;i<N;i++){
		int t;
		cin >> t;
		ANS=ANS+min(t*2,abs(K-t)*2);
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    if (i == 0) h[i]--;
    else {
      if (h[i] - 1 >= h[i - 1]) h[i]--;
    }
  }
  for (int i = 1; i < n; i++) {
    if (h[i] < h[i - 1]) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

void solve() {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> ss(h);
    for (auto& s : ss) std::cin >> s;

    int ans = 0;

    auto costs = vec(h + 1, vec(h + 1, 0));
    auto dp = costs;
    for (int i = 0; i + 1 < w; ++i) {
        for (int x = 1; x <= h; ++x) {
            for (int y = 1; y <= h; ++y) {
                costs[x][y] = costs[x - 1][y - 1] +
                              (ss[x - 1][i] == ss[y - 1][i + 1]);
                dp[x][y] = std::min(dp[x - 1][y], dp[x][y - 1]) +
                           costs[x][y];
            }
        }
        ans += dp[h][h];
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


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

double abs(double a,double b){
	if(a-b>=0) return a-b;
	else return b-a;
}

int main(){
	int n;
	double t,a;
	cin>>n>>t>>a;
	
	double h[1001];
	for(int i=0;i<n;i++) cin>>h[i];
	
	
	int ans=1;
	double min=abs(a,t-0.006*h[0]);
	for(int i=1;i<n;i++){
		double tmp=abs(a,t-0.006*h[i]);
		if(min>tmp){
			min=tmp;
			ans=i+1;
		}
	}
	
	
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool dp[21][404000];
int main(){
    int n; cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) cin >> A[i];
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n*2000; j++) {
            if(j == 0) dp[i][j] = true;
            if(dp[i][j]){
                dp[i+1][j] = true;
                dp[i+1][j+A[i]] = true;
            }
        }
    }
    
    int q; cin >> q;
    
    for (int i = 0; i < q; i++) {
        int m; cin >> m;
        if(dp[n][m]) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3152
def solve():
    N = int(input())
    ac = re = tle = wa = 0
    for i in range(N):
        s = input()
        if s == "AC":
            ac += 1
        elif s == "RE":
            re += 1
        elif s == "TLE":
            tle += 1
        else:
            wa += 1
    print("AC x", ac)
    print("WA x", wa)
    print("TLE x", tle)
    print("RE x", re)


# AC x 3
# WA x 1
# TLE x 2
# RE x 0
if __name__ == '__main__':
    solve()


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

using ll = long long int;

constexpr int MAX_N = 1125;

vector<bool> IsPrime;
vector<int> primes;

void sieve(int max) {
    IsPrime.resize(max + 1, true);
    IsPrime[0] = IsPrime[1] = false;
    for (int i = 2; i * i <= max; ++i){
        if (IsPrime[i]){
            for (int j = i * i; j <= max; j += i) IsPrime[j] = false;
        }
    }
    for(int i = 0; i <= max; ++i) if(IsPrime[i]) primes.push_back(i);
}

ll memo[MAX_N][200][15];

ll rec(int n, int m, int k){
    if(k == 0) return n == 0;
    if(m < 0) return 0;
    if(memo[n][m][k] >= 0) return memo[n][m][k];
    ll res = 0;
    for(int i=m;i>=0;i--){
        if(primes[i] <= n){
            res += rec(n-primes[i],i-1,k-1);
        }
    }
    return memo[n][m][k] = res;
}

int solve(){
    int n, k;
    cin >> n >> k;
    if(n == 0) return 1;
    cout << rec(n, int(primes.size())-1, k) << endl;
    return 0;
}

int main(){
    sieve(MAX_N);
    for(int i=0;i<MAX_N;i++){
        for(int j=0;j<200;j++){
            fill(memo[i][j],memo[i][j]+15,-1LL);
        }
    }
    while(solve()==0);
    return 0;
}



Measured memory_bytes: 29540
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
int n;
int dp[114][4][4][4];//i番目は決まってて、i-2,i-1,iの文字
signed main(){
	
	cin>>n;
	//ACGT
	//GAC, ACG, A?GC, AG?C
	rep(i,4){
		rep(j,4){
			rep(k,4){
				if(i==0&&j==2&&k==1)continue;
				if(i==2&&j==0&&k==1)continue;
				if(i==0&&j==1&&k==2)continue;
				dp[3][i][j][k]=1;
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			for(int k=0;k<4;k++){
				for(int l=0;l<4;l++){
					rep(m,4){
						if(k==0&&l==2&&m==1)continue;
						if(k==2&&l==0&&m==1)continue;
						if(k==0&&l==1&&m==2)continue;
						if(j==0&&l==2&&m==1)continue;
						if(j==0&&k==2&&m==1)continue;
						dp[i+1][k][l][m]+=dp[i][j][k][l];
						dp[i+1][k][l][m]%=MOD;
					}
				}
			}
		}
	}
	rep(i,4)rep(j,4)rep(k,4){
		ans+=dp[n][i][j][k];
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<pair<double, double>> ord;
	forl(i, 0, n) {
		double a, b; cin >> a >> b;
		ord.push_back({a, b});
	}
	double tot = 0, cnt = 0;
	vector<int> things; forl(i, 0, n) things.push_back(i);
	while(true) {
		forl(j, 0, n-1) {
			int i = things[j], nx = things[j+1];
			tot += sqrt((ord[i].first-ord[nx].first)*(ord[i].first-ord[nx].first)+(ord[i].second-ord[nx].second)*(ord[i].second-ord[nx].second));
		}
		next_permutation(things.begin(), things.end());
		cnt += 1.0;
		if(is_sorted(things.begin(), things.end())) break;
	}
	cout << setprecision(100) << tot/cnt << endl;
}


Measured memory_bytes: 892
#include<iostream>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < int(n); ++i)
 
int mem[100][100];
string str;
 
void f(int s, int e, int turn) {
  //cout << s << " " << e << " " << turn << endl;
  if (mem[s][e] != 0) return;
  if (str.substr(s, e - s).find("o") == string::npos) {
    mem[s][e] = -1;
    return;
  }
  if (str.substr(s, e - s).find("x") == string::npos) {
    mem[s][e] = 1;
    return;
  }
  char c = str[s];
  bool can = false;
  if ((turn == 1 && c == 'x') || (turn == -1 && c == 'o')) {
    int i = s;
    while (str[i] == c) ++i;
    f(i, e, -turn);
    if (mem[i][e] == turn) {
      mem[s][e] = turn;
      return;
    }
    can = true;
  }
  c = str[e - 1];
  if ((turn == 1 && c == 'x') || (turn == -1 && c == 'o')) {
    int i = e - 1;
    while (str[i] == c) --i;
    f(s, i + 1, -turn);
    if (mem[s][i + 1] == turn) {
      mem[s][e] = turn;
      return;
    }
    can = true;
  }
  if (!can) {
    f(s, e, -turn);
  } else {
    mem[s][e] = -turn;
  }
}
 
int main() {
  cin >> str;
  f(0, str.size(), 1);
  if (mem[0][str.size()] == 1) cout << "o" << endl;
  else cout << "x" << endl;
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>

int main(void)
{
int w,h,x,y,r,f;


scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

f=0;
if(x+r>w)f=1;
if(y+r>h)f=1;
if(r>x)f=1;
if(r>y)f=1;

if(f==0)printf("Yes\n");
else printf("No\n");

return 0;
}


Measured memory_bytes: 2104
using System;
					
public class Program
{
	public static void Main()
	{
		var s = Console.ReadLine().Split(' ');
		
		var a = double.Parse(s[0]);
		var b = double.Parse(s[1]);
		var C = double.Parse(s[2]);
		
		var h = b * Math.Sin(Math.PI * C / 180.0);
		var c = Math.Sqrt(a*a + b*b - 2*a*b*Math.Cos(Math.PI * C / 180.0));
		
		var S = a*h/2.0;
		var L = a + b  + c;
		
		Console.WriteLine(S);
		Console.WriteLine(L);
		Console.WriteLine(h);
	}
}

Measured memory_bytes: 9204
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if(A > K) {
        A = A - K;
    } else {
        K = K - A;
        A = 0;
        if (B > K) {
            B = B - K;
        } else {
            B = 0;
        }
    }

    cout << A << " " << B << endl;

    return 0;
}


Measured memory_bytes: 3628
import java.util.Comparator;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Arrays;
	/* static int java.util.Arrays.binarySearch(int[] a, int key); */
import java.math.BigDecimal;
	



public class Main {
	Scanner sc = new Scanner(System.in);
	int a, b;
	public void run(){
		a = sc.nextInt();
		b = sc.nextInt();
		solve();
	}
	public void solve(){
		int ans1 = a+b;
		int ans2 = a-b;
		int ans3 = a*b;
		
		if(ans1 > ans2){
			if(ans1 > ans3){
				System.out.println(ans1);
			}
			else{
				System.out.println(ans3);
			}
		}
		else{
			if(ans2 > ans3){
				System.out.println(ans2);
			}
			else{
				System.out.println(ans3);
			}
		}
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }
	static class Edge{
		int to, cost;
		public Edge(int a, int b){
			this.to = a;
			this.cost = b;
		}
	}
	class MyComparator implements Comparator {
		@Override
		public int compare (Object arg0, Object arg1) {
			int x = ((Pair)arg0).first;
			int y = ((Pair)arg1).first;
			
			if (x < y) {
				return 1;
			} else if (x > y) {
				return -1;
			} else{
				return 0;
			}
		}
	}
	static class UnionFind{
		int par[];
		int rank[];
		
		//n要素で初期化
		public UnionFind(int maxn){
			par = new int[maxn];
			rank = new int[maxn];
			
			for(int i = 0; i < maxn; i++){
				par[i] = i;
				rank[i] = 0;
			}
		}
		
		//木の根を求める
		int find(int x){
			if(par[x] == x){
				return x;
			}
			else {
				return par[x] = find(par[x]);
			}
		}
		
		// xとyの属する集合を併合
		void unite (int x, int y){
			x = find(x);
			y = find(y);
			if(x == y){
				return;
			}
			
			if(rank[x] < rank[y]){
				par[x] = y;
			}
			else{
				par[y] = x;
				if(rank[x] == rank[y]) rank[x]++;
			}
		}
		
		// xとyが同じ集合に属するか否か
		boolean same(int x, int y){
			return find(x) == find(y);
		}
	}
	
}


Measured memory_bytes: 23380
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::string S;
std::vector<ll> a;

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

  rep( i, S.size()-1 )
    a.emplace_back( llabs(S[i+1]-'0'-(S[i]-'0')) );

  ll sum = 0;
  bool fl = false;

  rep( i, N-1 ) {
    if( a[i] == 1 ) {
      fl = true;
    }

    sum += (a[i]%2)*(((N-2)&i) == i)%2;
    sum %= 2;
  }

  if( sum == 1 ) {
    std::cout << 1 << endl;

    return 0;
  }

  if( fl ) {
    std::cout << 0 << endl;

    return 0;
  }

  sum = 0;

  rep( i, N-1 ) {
    a[i] /= 2;
    sum += (a[i]%2)*(((N-2)&i) == i)%2;
    sum %= 2;
  }

  std::cout << sum*2 << endl;

  return 0;
}

Measured memory_bytes: 13508
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		ll t;
		cin >> t;
		ll cnta=0,cntw=0,cntt=0,cntr=0;
		while(t--)
		{
			string s;
			cin >> s;
			if(s.length()==3) cntt++;
			else if (s[0]=='A') cnta++;
			else if (s[0]=='W') cntw++;
			else if (s[0]=='R') cntr++;
			//cerr << imie(cntt) imie(cnta) imie(cntw) imie(cntr);
		}
		cout << "AC x " << cnta << endl;
		cout << "WA x " << cntw << endl;
		cout << "TLE x " << cntt << endl;
		cout << "RE x " << cntr << endl;
		return 0;  
}  


Measured memory_bytes: 3660
import Control.Applicative ((<$>))

main :: IO ()
main = do
  [n, a, b, c, d] <- map read . words <$> getLine
  print $ solve n a b c d

solve :: Int -> Int -> Int -> Int -> Int -> Int
solve n a b c d = (solve' n a b) `min` (solve' n c d)

solve' :: Int -> Int -> Int -> Int
solve' n a b
  | r == 0
    = q * b
  | otherwise
    = (q + 1) * b
  where
    (q, r) = n `divMod` a


Measured memory_bytes: 3660