akhauriyash/Code-Regression huggingface dataset:
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 0, mod = (int) 0;
int findmx(int a, int b) {
	if (a + b == 0) return 0;
	int mx = 1;
	mx = max(mx, (a - 1) / (b + 1) + 1);
	mx = max(mx, (b - 1) / (a + 1) + 1);
	return mx;
}
int check(int a, int b, int lim) {
	int bm = lim;
	int mx = findmx(a, b);
	int needb = (bm - 1) / mx;
	int rema = a - bm, remb = b - needb;
	if (rema < 0 || remb < 0) return 0;
	int nxtmx = findmx(rema, remb);
	if (nxtmx <= mx) {
		return 1;	
	}
	return 0;
}
int main() {
	int q;
	cin >> q;
	while (q--) {
		int a, b, ql, qr;
		cin >> a >> b >> ql >> qr;
		--ql;
		int mx = findmx(a, b);
		int bl = 0, br = a + 1;
		while (bl < br - 1) {
			int bm = bl + br >> 1;
			if (check(a, b, bm)) {
				bl = bm;	
			} else {
				br = bm;
			}
		}
		int needb = (bl - 1) / mx;
		int use = bl + needb;
		for (int j = ql; j < min(qr, use); ++j) {
			if (j % (mx + 1) == mx) {
				cout << 'B';	
			} else {
				cout << 'A';
			}
		}
		vector<char> s;
		for (int j = qr - 1; j >= max(ql, use); --j) {
			if (((a + b) - j - 1) % (mx + 1) == mx) {
				s.pb('A');
			} else {
				s.pb('B');
			}
		}
		reverse(s.begin(), s.end());
		for (char c : s) cout << c;
		cout << '\n';
	}
}




Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int n,m;
vvi in;
int dx[6]={-1,-1,0,0,1,1};
int dy[2][6]={
	{-1,0,-1,1,-1,0},
	{0,1,-1,1,0,1}
};
void f(int x,int y){
	in[x][y]=2;
	rep(i,6){
		int nx=x+dx[i];
		int ny=y+dy[x%2][i];
		if(nx<0||ny<0||nx>=n+2||ny>=m+2)continue;
		if(in[nx][ny]==0)f(nx,ny);
	}
}
int main(){
	cin>>m>>n;
	in=vvi(n+2,vi(m+2));
	rep(i,n)rep(j,m)cin>>in[i+1][j+1];
	f(0,0);
	int co=0;
	rep(i,n+2)rep(j,m+2)if(in[i][j]==1){
		rep(k,6)if(in[i+dx[k]][j+dy[i%2][k]]==2)co++;
	}
//	rep(i,n+2){rep(j,m+2)cout<<" "<<in[i][j];cout<<endl;}
	cout<<co<<endl;
}

Measured memory_bytes: 1620
n = int(input())
a = list(map(int, input().split()))

b = [0 for _ in range(max(a))]
for i in a:
    b[i - 1] += 1
ans = 0
for i in b:
    ans += int(i * (i-1) / 2)

for i in a:
    print(ans - (b[i - 1] - 1))

Measured memory_bytes: 24748
N = gets.to_i
arr = gets.split.map(&:to_i)
ans = 1
safe = true
if arr.include?(0)
	p 0
else
	N.times do |i|
		ans *= arr[i]
		if ans > 1000000000000000000
			p -1
			safe = false
			break
		end
	end
	if safe
		p ans
	end
end

Measured memory_bytes: 21596
#include <fstream>
#include <vector>
#include <set>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 998244353
#define INF __LONG_LONG_MAX__
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define ll long long
#define pii pair<ll,int>
#define ppi pair<pii,int>
#define add(a,b) ((int) (((ll) (a) + (b))%MOD))
#define mul(a,b) ((int) (((ll) (a) * (b))%MOD))
#define PB emplace_back
#define MP make_pair
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N, M, S, u, v, a, b;
vector<ppi> graph [50];
int vals [50][2]; // time, coins
ll dp [50][2501];
// Helper Functions

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M >> S;
    S = min(2500,S);
    F0R(i,M) {
        cin >> u >> v >> a >> b;
        u--; v--;
        graph[u].PB(MP(MP(b,a),v));
        graph[v].PB(MP(MP(b,a),u));
    }
    F0R(i,N) cin >> vals[i][1] >> vals[i][0];
    F0R(i,N) F0R(j,2501) dp[i][j] = INF;
    set<ppi> queue;
    dp[0][S] = 0;
    queue.emplace(MP(MP(0,S),0));
    while (!queue.empty()) {
        ppi cur = *queue.begin(); queue.erase(queue.begin());
        for (auto neigh: graph[cur.S]) {
            if (neigh.F.S > cur.F.S) continue;
            ll nt = neigh.F.F + cur.F.F;
            int nm = cur.F.S - neigh.F.S;
            if (dp[neigh.S][nm] > nt) {
                dp[neigh.S][nm] = nt;
                queue.emplace(MP(MP(nt,nm), neigh.S));
            }
        }
        if (cur.F.S < 2500) {
            ll nt = cur.F.F + vals[cur.S][0];
            int m = min(2500, cur.F.S + vals[cur.S][1]);
            if (dp[cur.S][m] > nt) {
                dp[cur.S][m] = nt;
                queue.emplace(MP(MP(nt,m),cur.S));
            }
        }
    }
    FOR(i,1,N) {
        ll mn = INF;
        F0R(j,2500) mn = min(mn, dp[i][j]);
        cout << mn << '\n';
    }
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

string S, T;
set<string> A;

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

	cin >> S >> T;
	int j;
	string w;
	for(int i = S.size() - T.size(); i >= 0; i--) {
		w = S;
		for(j=0; j < T.size(); j++) {
			if(S[i + j] != '?' && S[i + j] != T[j]) break;
		}
		if(j == T.size()) {
			w = S;
//		    cout << "[" << w << "] i=" << i << "  T.size()=" << T.size() << endl;
			w.replace(i, T.size(), T);
//		    cout << " --> [" << w << "]" << endl;
			REP(j, 0, w.size())
				if(w[j] == '?')	w[j] = 'a';
			A.insert(w);
		}
	}
	if(A.size() == 0)	cout << "UNRESTORABLE" << endl;
	else				cout << *A.begin() << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    rep(i, n)rep(j, 10) cin >> f[i][j];
    vector<vector<int>> p(n, vector<int>(11));
    rep(i, n)rep(j, 11) cin >> p[i][j];

    ll ans = -20000000000;
    for(int i = 1; i < (1 << 10); ++i){
        vector<int> c(n, 0);
        rep(j, n){
            rep(k, 10){
                if((i & (1 << k)) && f[j][k]){
                    c[j]++;
                }
            }
        }
        ll sum = 0;
        rep(j, n){
            sum += p[j][c[j]];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := n - 1; i >= 0; i-- {
		fmt.Printf("%d", a[i])
		if i != 0 {
			fmt.Print(" ")
		}
	}
	fmt.Print("\n")
}



Measured memory_bytes: 1164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int n,a[500000]={},i,sum[500000]={};
    char token[10000000]={};
    fgets(token, sizeof(token), stdin);
    n=atoi(token);
    fgets(token, sizeof(token), stdin);
    a[0]=atoi(strtok(token, " "));
    for (i=1; i<n-1; i++) a[i]=atoi(strtok(NULL, " "));
    for (i=0; i<n-1; i++) sum[a[i]]++;
    for (i=1; i<=n; i++) printf("%d\n",sum[i]);
    return 0;
}



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

const ll mod = 1e9 + 7;
const ll MAXX = 1e18;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	ll n;
	cin >> n;
	ll res = MAXX;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res = min(res, i + (n / i) - 2);
		}
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 384
#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>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s;
	ll F=0;
	cin>>s;
	rep(i,s.size()){
		if(s[i]=='C')F=1;
		if(s[i]=='F'&&F==1)F=2;
	}
	if(F==2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    char S[15];
    scanf("%s", S);
    if(S[0]=='S') printf("Cloudy\n");
    else if(S[0]=='C') printf("Rainy\n");
    else printf("Sunny\n");
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll = long long;
using VL = vector<ll>;

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define rep(i, n) REP(i, 0, n)

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

int main(void) {
	ll n, k;
	bool ans;
	cin >> n >> k;
	VL a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n - k) {
		if(a[i] < a[i + k]) {
			ans = true;
		} else {
			ans = false;
		}
		Yes(ans);
	}
	return 0;
}

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

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

import bisect

count_B = {}
count_C = {}
count_sum = {}

count = 0
for idx, b in enumerate(reversed(B)):
    count_C[b] = N - bisect.bisect_right(C, b)
    count += count_C[b]
    count_sum[N-idx-1] = count
# print(count_sum)
count = 0
for a in A:
    index = bisect.bisect_right(B, a)
    if index in count_sum:
        count += count_sum[bisect.bisect_right(B, a)]
        # print(a, b)
print(count)

Measured memory_bytes: 120008
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct edge {
  int la,b;
} con[N << 1];
int tot,fir[N];
void add(int from,int to) {
  con[++tot] = (edge) {fir[from],to};
  fir[from] = tot;
}
int n,fa[N],ans,k;
int dfs(int pos) {
  int ret = 0;
  for (int i = fir[pos] ; i ; i = con[i].la) {
    if (con[i].b == fa[pos]) continue;
    ret = max(ret,dfs(con[i].b)+1);
  }
  if (ret >= k-1 && fa[pos] != 1)
    ++ ans, ret = -1;
  return ret;
}
int main() {
  scanf("%d%d",&n,&k);
  for (int i = 1 ; i <= n ; ++ i)
    scanf("%d",&fa[i]);
  if (fa[1] != 1) ++ ans, fa[1] = 1;
  for (int i = 2 ; i <= n ; ++ i)
    add(fa[i],i);
  dfs(1);
  printf("%d\n",ans);
  return 0;
}


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

int gcd(int a, int b) {
    if (a > b) {
        int tmp = b;
        b = a;
        a = tmp;
    }
    if (a == 0) return b;
    return gcd(a, b%a);
}

int64_t lcm(int64_t a, int64_t b) {
    return (int64_t)(a*b)/(gcd(a, b));
}


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

    int64_t a, b;
    int c, d;
    cin >> a >> b >> c >> d;
    int64_t x, y, z, l;
    l = lcm(c, d);
    x = b/c - (a-1)/c;
    y = b/d - (a-1)/d;
    z = b/l - (a-1)/l;
    cout << b-a+1-x-y+z << endl;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200050
#define M 200
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define clr(a) a.clear()
#define ll long long
#define SIZE N
#define MOD mod
using namespace std;
int mod = 1e9 + 7;
int n,ar[N];
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int rp = 0;
    int cur = 1000;
    int st = 1;
    while(st<n&&ar[st-1]>=ar[st]){
        st++;
    }
    st--;
    for(int i=st;i<n;i++){
        rp = i+1;
        while(rp<n&&ar[rp]>=ar[rp-1]){
            rp++;
        }
        int nu = cur/ar[i]; int lef = cur%ar[i];
        nu*= ar[rp-1]; cur = nu + lef;
        if(rp>=n)break;
        i = rp-1;
    }
    cout<<cur;
  	return 0;
}



Measured memory_bytes: 3584
s = input()
ans = []
for i in range(len(s)):
    if s[i] == "1":
        ans.append(1)
    elif s[i] == "0":
        ans.append(0)
    else:
        if ans :
            length = len(ans)
            ans = ans[:length-1]
a = ""
for i in range(len(ans)):
    a +=str(ans[i])
print(a)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<string.h>
#include<set>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
    int a;
    cin>>a;
    int b[110];
    rep(i,a)cin>>b[i];
    sort(b,b+a);
    cout<<b[a-1] - b[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for( int i = a; i < b ; i++ ) 
#define af(i,a,b) for( int i = a; i >= b ; i--)
#define rep(i,a,b,k) for(int i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( int i = a; i >= b ; i-= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846

typedef long double ld;
typedef long long int ll;
typedef vector<int> vi ;
typedef pair<int,int> ii ;
typedef vector<ii> vii 	;

int num[101];
int p[100010];
int main(){
	fastio;
	int n,k;
	cin>>n>>k;
	f(i,0,n) cin>>num[i];
	f(i,0,k+1){
		if(p[i]==0)
			f(j,0,n) if(num[j]+i<=k) p[num[j]+i]=1;
	}
	if(p[k]) cout<<"First";
	else cout<<"Second";
}

Measured memory_bytes: 640
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

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

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

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


S =  sys.stdin.readline().rstrip()
T =  sys.stdin.readline().rstrip()

S = sorted(S)
T= sorted(T, reverse=True)

if ''.join(S) < ''.join(T):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    vector<P> v(n);
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        v[i] = P(a, i+1);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++)
    {
        cout << v[i].second << " ";
    }
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

struct mint{
    static const long long MOD = 998244353;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

struct mintcomb{
    vector<mint> fact;
    vector<mint> ifact;
    mintcomb(ll n) : fact(n + 1, 1), ifact(n + 1, 1) {
        for(ll i = 2; i <= n; ++i){
            fact.at(i) = fact.at(i - 1) * i;
            ifact.at(i) = fact.at(i).inv();
        }
    }

    mint factorial(ll k) const { return fact.at(k); }
    mint combination(ll k, ll l) const {
        return fact.at(k) * ifact.at(l) * ifact.at(k - l);
    }
};


int main(){
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    mint ans = 0;
    mintcomb mc(n);
    REP(na, n + 1){
        const ll nb = (k - a * na) / b;
        if(nb < 0 || nb > n || a * na + b * nb != k){ continue; }
        const mint tmp = mc.combination(n, na) * mc.combination(n, nb);
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7988
n = int(input())
cards = []
for i in range(n):
    s, a = input().split()
    cards.append((s, int(a)))
l = [(s, a) for s in "SHCD" for a in range(1,14) if (s,a)not in cards]
for s, a in l:
    print(s + " " + str(a))

Measured memory_bytes: 7660
h, w, k = map(int, input().split())
c = []
for _ in range(h):
    c.append(list(input()))
ans = 0
for x in range(2**(h+w)):
    cnt = 0
    for i in range(h):
        for j in range(w):
            if x>>i&1 or x>>(h+j)&1 or c[i][j]=='.':
                continue
            cnt += 1
    if cnt==k:
        ans += 1
print(ans)

Measured memory_bytes: 74088
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,p;

	cin>>n>>p;

	ll o=1;
	ll d=0;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}

	for(ll i=1000000; i>=2; i--){
		d=1;
		for(ll j=1; j<n+1&&d<=p; j++){
			d*=i;
			if(p%d>0){
				break;
			}
		}
		if(p%d==0){
			o=i;
			cout<<o<<endl;
			return 0;
		}

	}
	cout<<"1"<<endl;
	return 0;
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

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

	vector<LL> a(n);

	for (auto &e : a) {
		cin >> e;
	}

	LL tot = accumulate(a.begin(), a.end(), 0LL);
	LL ans = 0;
	tot %= MOD;
	for (LL i = 0; i < n; ++i) {
		tot  = ((tot - a[i])%MOD + MOD) % MOD;
		ans = (ans + a[i]*tot) % MOD;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 4776
#include <limits.h>
#include <stdio.h>
int min(int x, int y) {
    return x <= y ? x : y;
}
void print_array_int(int *xs, int n) {
    int i;
    for (i = 0; i < n; ++i) {
        printf("%d, ", xs[i]);
    }
    putchar('\n');
}
static int n, t, a[100001];
static int maxes[100001], distance_max = INT_MIN;
int main(void) {
    int i, max, distance;
    int n_distance = 0;
    scanf("%d%d", &n, &t);
    for (i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    max = 0;
    for (i = n - 1; i >= 0; --i) {
        if (max < a[i]) {
            max = a[i];
        }
        maxes[i] = max;
    }
    for (i = 0; i < n; ++i) {
        distance = maxes[i] - a[i];
        if (distance > distance_max) {
            distance_max = distance;
        }
    }
//    print_array_int(maxes, n);
//    printf("distance_max = %d\n", distance_max);
    for (i = 0; i < n; ++i) {
        distance = maxes[i] - a[i];
        if (distance == distance_max) {
            ++n_distance;
        }
    }
//    printf("n_distance = %d\n", n_distance);
    printf("%d\n", n_distance);
    return 0;
}


Measured memory_bytes: 896
from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int,input().split()))
dp = [0]*(n+1)
for i in range(2,n+1):
    if i>2:
        dp[i] = min(dp[i-1]+abs(a[i-1]-a[i-2]),dp[i-2]+abs(a[i-1]-a[i-3]))
    else:
        dp[i] = dp[i-1]+abs(a[i-1]-a[i-2])
print(dp[n])

Measured memory_bytes: 14016
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int Width[100];
int M, N;


bool solve(int limit) {
	int nowWidth, nowSumShelf;

	nowWidth = 0;
	nowSumShelf = 1;
	for (int i = 0; i < N; ++i) {
		if (nowWidth + Width[i] <= limit) {
			nowWidth += Width[i];
			continue;
		}
		nowWidth = 0;
		--i;
		++nowSumShelf;
		if (nowSumShelf > M) {
			return false;
		}
	}
	return true;
}

int main() {
	int left, right, mid;

	while (cin >> M >> N, M) {
		for (int i = 0; i < N; ++i) {
			cin >> Width[i];
		}

		left = 0;
		right = 1500001;
		while (left < right) {
			mid = (left + right) / 2;
			//cout << "left:" << left << "  mid:"<<mid<<"  right:" << right << endl;
			if (solve(mid)) {
				right = mid;
			}
			else {
				left = mid + 1;
			}
		}
		cout <<left << endl;
	}

	return 0;
}




Measured memory_bytes: 3004
#[macro_use]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}



fn main() {
    input! {
        a: i32, b: i32, c: i32, x: i32, y: i32,
    }

    let mut ans = Vec::<i32>::new();
    // 直接A, Bのピザを買う
    ans.push(a*x + b*y);

    // Cのピザをフロアー買ってA,Bを足りない分買い足す
    ans.push(c* if x > y { y } else { x } * 2 + if x > y { (x - y)*a } else { (y - x)*b });

    // Cのピザを多めに買って間に合わせる
    ans.push(c* if x > y { x } else { y } * 2);

    let ans = ans.iter().min().unwrap();
    println!("{}", ans);
}


// ========== 以下使い捨て関数 ================================





// ========== 以下作り置き関数 ================================
pub use std::io::*;
pub use std::process::exit;
pub use std::str::FromStr;

pub const MOD: i64 = 1_000_000_007;

/// 標準入力から
/// 空白文字で囲まれた1つのトークンを
/// 指定の型に変換する
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

/// 標準入力から1行読み取り
/// 空白文字で区切って
/// 指定の型のVecに格納する
pub fn read_vec<T: FromStr>() -> Vec<T> {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text.RegularExpressions;

namespace ConsoleApp23
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var answer = new HashSet<int>();
            for (int i = 0; i < n; i++)
            {
                answer.Add(int.Parse(Console.ReadLine()));
            }

            Console.WriteLine(answer.Count.ToString());

        }
    }
}


Measured memory_bytes: 13396
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);
		Kouji[] arr = new Kouji[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			Kouji o = new Kouji();
			o.s = Integer.parseInt(sa[0]);
			o.t = Integer.parseInt(sa[1]);
			o.x = Integer.parseInt(sa[2]);
			o.s = Math.max(o.s - o.x, 0);
			o.t = Math.max(o.t - o.x, 0);
			arr[i] = o;
		}
		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
		for (int i = 0; i < q; i++) {
			map.put(Integer.parseInt(br.readLine()), i);
		}
		br.close();

		Arrays.parallelSort(arr);

		int[] ans = new int[q];
		Arrays.fill(ans, -1);

		for (int i = 0; i < n; i++) {
			Kouji o = arr[i];
			SortedMap<Integer, Integer> sm = map.subMap(o.s, o.t);
			Integer[] keys = sm.keySet().toArray(new Integer[0]);
			for (Integer k : keys) {
				ans[sm.get(k)] = o.x;
				map.remove(k);
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			pw.println(ans[i]);
		}
		pw.flush();
	}

	static class Kouji implements Comparable<Kouji> {
		int s, t, x;
		public String toString() {
			return "[" + s + "," + t + "," + x + "]";
		}

		public int compareTo(Kouji o) {
			return x - o.x;
		}
	}
}


Measured memory_bytes: 110484
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; ;)
		{
			int n = scanner.nextInt();
			if(n == 0)
			{
				break;
			}
			int[][] map = new int[n][n];
			
			int w = n/2;
			int h = n/2+1;
			map[h][w] = 1;
			for(int i=2; i<=n*n; i++)
			{
				h ++;
				w ++;
				for(; ;)
				{
					if(h >= n)
					{
						h = 0;
					}
					if(w < 0)
					{
						w = n-1;
					}
					else if(w >= n)
					{
						w = 0;
					}
					
					if(map[h][w] == 0)
					{
						map[h][w] = i;
						break;
					}
					else
					{
						w --;
						h ++;
					}
				}
			}
			for(int i=0; i<n; i++)
			{
				for(int j=0; j<n; j++)
				{
					System.out.printf("%1$4d%2$s", map[i][j], (j<n-1 ? "" : "\n"));
				}
			}
		}
	}
}

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

int main(){

    int n, m, k; cin >> n >> m >> k;

    bool flag = false;

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            int masu = i * j + (n - i) * (m - j);
            if(masu == k){
                flag = true;
                break;
            }
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
A,B,C,X,Y=map(int,input().split())
D,E=min(2*C,A),min(2*C,B)

if 2*C<A+B:
  print(2*C*min(X,Y)+((X-Y)*D if X>=Y else E*(Y-X)))
else:
  print(A*X+B*Y)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    while(true){
         cin>>a;
         cin>>b;
         if(a==0&&b==0){
             break;
         }
        else if(a<=b){
            cout<<a;
            cout<<" ";
            cout<<b<<endl;
        }
         else if(b<=a){
        cout<<b;
        cout<<" ";
        cout<<a<<endl;
        }
    }
}
   
    
   
   


Measured memory_bytes: 3016
use std::io::{BufRead, Write};
use std::cmp;

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let n: usize = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let mut x: Vec<i64> = vec![0; n];
    let mut y: Vec<i64> = vec![0; n];
    let mut p: Vec<i64> = vec![0; n];
    for i in 0..n {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        x[i] = iter.next().unwrap().parse().unwrap();
        y[i] = iter.next().unwrap().parse().unwrap();
        p[i] = iter.next().unwrap().parse().unwrap();
    }

    let mut a: Vec<Vec<i64>> = vec![vec![std::i64::MAX; n]; 1 << n];
    let mut b: Vec<Vec<i64>> = vec![vec![std::i64::MAX; n]; 1 << n];
    for i in 0..(1 << n) {
        for j in 0..n {
            a[i][j] = cmp::min(a[i][j], x[j].abs());
            b[i][j] = cmp::min(b[i][j], y[j].abs());
            if i & 1 << j == 0 { continue; }
            for k in 0..n {
                a[i][k] = cmp::min(a[i][k], (x[j] - x[k]).abs());
                b[i][k] = cmp::min(b[i][k], (y[j] - y[k]).abs());
            }
        }
    }

    let pow = |mut a: usize, mut n: usize| {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 { res *= a; }
            a *= a;
            n >>= 1;
        }
        res
    };

    let mut ans = vec![std::i64::MAX; n + 1];
    for i in 0..pow(3, n) {
        let mut c = 0;
        let mut x = i;
        let mut s = 0;
        let mut t = 0;
        for j in 0..n {
            let y = x % 3;
            if y == 1 {
                s += 1 << j;
                c += 1;
            }
            else if y == 2 {
                t += 1 << j;
                c += 1;
            }
            x /= 3;
        }

        let mut res = 0;
        for i in 0..n {
            res += p[i] * cmp::min(a[s][i], b[t][i]);
        }
        ans[c] = cmp::min(ans[c], res);
    }

    for i in 0..=n {
        writeln!(writer, "{}", ans[i]).unwrap();
    }
}

Measured memory_bytes: 11792
#include <iostream>
int main(){

int d = 0;
std::cin >> d;

if(d == 25){

std::cout << "Christmas" << std::endl;

}else if(d == 24){

std::cout << "Christmas Eve" << std::endl;

}else if(d == 23){

std::cout << "Christmas Eve Eve" << std::endl;

}else if(d == 22){

std::cout << "Christmas Eve Eve Eve" << std::endl;

}

}

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

int main(){
	string s, t;
    cin >> s >> t;
    int n = s.size();
    int freq[n+1][26];
    for(int i = 0; i < 26; i++){
        freq[n-1][i] = -1;
    }
    int first[26];
    memset(first, -1, sizeof(first));
    first[s[n-1] - 'a'] = n-1;
    for(int i = n-2; i >= 0; i--){
        first[s[i] - 'a'] = i;
        for(int j = 0; j < 26; j++){
            freq[i][j] = freq[i+1][j];
        }
        freq[i][s[i+1] - 'a'] = i+1;
    }
    int m = t.size();
    int src = first[t[0] - 'a'];
    bool flag = false;
    long long int c = 0;
    if(src != -1)c = 1;
    else {
        cout << -1;
        return 0;
    }
    for(int i = 1; i < m; i++){
        // cout << t[i] << " ";
        // cout << c << " " << src << " " << freq[src][t[i] - 'a'] << "\n";
        if(freq[src][t[i] - 'a'] == -1){
            c++;
            src = first[t[i] - 'a'];
            if(src == -1){
                flag = true;
                break;
            }
        }else{
            if(flag){
                flag = false;
            }
            src = freq[src][t[i] - 'a'];
        }
    }
    if(flag && src == -1){
        cout << -1;
    }else{
        // cout << c << " " << src << " ";
        cout << c*n - (n-src-1);
    }
}

Measured memory_bytes: 10752
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main()
{

	int n, k;
	cin >> n >> k;

	vector<int> p(n);

	int hiscore = 0;
	int a = 0;

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

		cin >> p[i];

		a += p[i];

		if (i >= k) { a -= p[i - k]; }
		if (a > hiscore) hiscore = a;
	}



	double answer = (double)(hiscore + k) / 2.0;

	cout << setprecision(8) << answer << endl;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9


def check_palindrome(w):
    for i in range(len(w)//2):
        if w[i] != w[-i-1]:
            return False
    return True

def main():
    S = input()

    n = len(S)//2
    is_palindrome1 = check_palindrome(S)
    is_palindrome2 = check_palindrome(S[:n])
    is_palindrome3 = check_palindrome(S[n+1:])
    if is_palindrome1 and is_palindrome2 and is_palindrome3:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    map<string, ll> S;
    Rep (i, N) {
        string s;
        cin >> s;
        S[s]++;
    }

    ll cnt = 0;
    for (auto e : S) {
        chmax(cnt, e.second);
    }

    for (auto e : S) {
        if (e.second == cnt) {
            cout << e.first << "\n";
        }
    }
}

Measured memory_bytes: 23808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmpArray = br.readLine().split(" ");
		int w = Integer.parseInt(tmpArray[0]);
		int h = Integer.parseInt(tmpArray[1]);
		int x = Integer.parseInt(tmpArray[2]);
		int y = Integer.parseInt(tmpArray[3]);
		int r = Integer.parseInt(tmpArray[4]);
		if(x >= r && w - x >= r && y >= r && h - y >= r){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

Measured memory_bytes: 24392
#include<bits/stdc++.h>
using namespace std;
int n,m,p,a[1<<17],i,r,V,W,X;
main(){
cin>>n>>m>>p;
for(i=0;i<m;i++){cin>>a[i];a[i]+=n-p;a[i]%=n;}
sort(a,a+m);
r=min(a[m-1],n-a[0]);
for(int i=0;i<m-1;i++){
V=a[i],W=n-a[i+1];if(V>W)swap(V,W);
X=2*V+W;r=min(r,X);
}
cout<<r*100<<endl;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N,K;
	cin>>N>>K;
	vector<int> f(10);

	rep(i,K){
		int x;
		cin>>x;
		f[x]++;
	}

	for (int i = N;;++i){
		string S = to_string(i);
		bool ok = true;
		for (int j = 0; j < S.size(); ++j){
			if(f[S[j] - '0'])ok = false;
		}
		if(ok){
			cout<<i<<endl;
			break;
		}
	}
}

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

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

  int ans = 1e9;
  for (int i = 1; i <= 100; i++)
  {
    int sum = 0;
    for (int j = 0; j < n; j++)
    {
      sum += (x[j]-i)*(x[j]-i);
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
}

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

using Vec = vector<int>;

vector<Vec> transpose(vector<Vec>& mat) {
    int m = mat.size(),
        n = mat[0].size();
    // cerr << "(m, n) " << m << ", " << n << endl;
    vector<Vec> res(n, Vec(m));
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < m; c++) {
            // cerr << "(r, c) " << r << ", " << c << endl;
            res[r][c] = mat[c][r];
        }
    }
    return res;
}

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    if (H % h == 0 and W % w == 0) {
        cout << "No" << endl;
        return 0;
    }

    vector<Vec> a(H, Vec(W));

    bool trans = false;
    if (H % h != 0) {
        trans = true;
        swap(H, W);
        swap(h, w);
        a = transpose(a);
    }

    int x = (W / w) / (W % w) + 1;

    // cerr << "bbbbb" << endl;

    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            if ((r + 1) % h == 0 and (c + 1) % w == 0) a[r][c] = -(h * w - 1) * x - 1;
            else a[r][c] = x;
        }
    }

    // cerr << "aaaaa" << endl;
    
    if (trans) {
        swap(H, W);
        a = transpose(a);
    }

    // cerr << "ccccc" << endl;

    cout << "Yes" << endl;
    for (int r = 0; r < H; r++) {
        for (int c = 0; c < W; c++) {
            cout << a[r][c] << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2460
#include<stdio.h>
#include<math.h>
double MAX(double a){return a<0?0:a;}
double MIN(double a,double b){return a<b?a:b;}
int main(){
  int i,j,k,n,a[1010],b[1010],c[1010]={};
  double d[1010][1010]={};
  scanf("%d %d %d %d %d",&a[0],&b[0],&a[1],&b[1],&n);
  n+=2;
  for(i=2;i<n;i++)scanf("%d %d %d",&a[i],&b[i],&c[i]);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)d[i][j]=MAX(hypot(a[i]-a[j],b[i]-b[j])-c[i]-c[j]);
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      for(k=0;k<n;k++)d[j][k]=MIN(d[j][k],d[j][i]+d[i][k]);
    }
  }
  printf("%.10lf\n",d[0][1]);
  return 0;
}


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

int main() {
	int n,ir,dr,t;
	cin>> n >> dr;
	if(n>=10)
	{
	    ir=dr;
	}
	else
	{
	   ir= dr+100*(10-n);
	    
	}
	cout<<ir;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int i,j;
	int n;
	int b = 0;
	int s1 = 0;
	int s2;
	int sa1, sa2;

	scanf("%d", &n);

	int w[n];

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

		b += w[i];
	}

	s2 = b;
	j = 0;

	while (s1 < s2) {
		s1 += w[j];
		s2 -= w[j];
		j++;

		
	}
	
	sa1 = s1 - s2;

	s1 -= w[j - 1];
	s2 += w[j - 1];

	sa2 = s2 - s1;

	if (sa1 <= sa2) {
		printf("%d", sa1);
	}
	else {
		printf("%d", sa2);
	}


	return 0;
}

Measured memory_bytes: 128
import numpy as np
N,M = map(int,input().split())
s = np.zeros([N,2])
c = np.zeros([M,2])

for i in range(N):
  s[i,:] = np.array(list(map(int,input().split())))
for i in range(M):
  c[i,:] = np.array(list(map(int,input().split())))
  
for i in range(N):
  temp_c = np.abs(c-s[i,:])
  temp_c = np.sum(temp_c,axis=1)
  print(np.argmin(temp_c)+1)

Measured memory_bytes: 12388
s = input()
s_00 = 0
s_01 = 0 
s_10 = 0
s_11 = 0
count = 0

if s == "0" or s == "1":
    print(0)
    exit()


for i in s:
    count += 1
    if i == "0" and count % 2 == 1:
        s_00 += 1
    elif i == "1" and count % 2 == 1:
        s_01 += 1
    elif i == "0" and count % 2 == 0:
        s_10 += 1
    elif i == "1" and count % 2 == 0:
        s_11 += 1

if s_00 + s_11 <= s_01 + s_10:
    print(s_00 + s_11)
else:
    print(s_01 + s_10)


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

int main() {
  int N;
    cin >> N;
  int judge;
  judge = N % 10;

 if (judge == 2){
    cout << "hon" << endl;
  }
  else if (judge == 4){
    cout << "hon" << endl;
  }
  else if (judge == 5){
    cout << "hon" << endl;
  }
  else if (judge == 7){
    cout << "hon" << endl;
  }
  else if (judge == 9){
    cout << "hon" << endl;
  }
 
  else if (judge == 0){
    cout << "pon" << endl;
  }
  else if (judge == 1){
    cout << "pon" << endl;
  }
  else if (judge == 6){
    cout << "pon" << endl;
  }

  else if (judge == 8){
    cout << "pon" << endl;
  }
  else{
   cout << "bon" << endl;
  }
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    int k;
    cin >> k;

    vector<int> fe = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    cout << fe[k - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
s1={1,3,5,7,8,10,12}
s2={4,6,9,11}
s3={2}
x,y=map(int,raw_input().split())
if ((x in s1) and (y in s1)) or ((x in s2) and (y in s2)) or ((x in s3) and (y in s3)):
 print 'Yes'
else:
 print 'No'


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  int N,M; cin>>N>>M;
  cout<<N*(N-1)/2+M*(M-1)/2<<endl;
  return 0;
}

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

class Dice{
public:
	int num[6];

	Dice(int a, int b, int c, int d, int e, int f);
	void roll(char s);
	void mroll(string s);
};

Dice::Dice(int a, int b, int c, int d, int e, int f){
	num[0] = a;
	num[1] = b;
	num[2] = c;
	num[3] = d;
	num[4] = e;
	num[5] = f;
}

void Dice::roll(char s){
	int dum;
	switch (s)
	{
		case 'N':
			dum = num[0];
			num[0] = num[1];
			num[1] = num[5];
			num[5] = num[4];
			num[4] = dum;
			break;
		case 'E':
			dum = num[0];
			num[0] = num[3];
			num[3] = num[5];
			num[5] = num[2];
			num[2] = dum;
			break;
		case 'W':
			dum = num[0];
			num[0] = num[2];
			num[2] = num[5];
			num[5] = num[3];
			num[3] = dum;
			break;
		case 'S':
			dum = num[0];
			num[0] = num[4];
			num[4] = num[5];
			num[5] = num[1];
			num[1] = dum;
			break;
		case 'R':
			dum = num[1];
			num[1] = num[2];
			num[2] = num[4];
			num[4] = num[3];
			num[3] = dum;
			break;
		case 'L':
			dum = num[1];
			num[1] = num[3];
			num[3] = num[4];
			num[4] = num[2];
			num[2] = dum;
			break;
		default:
			break;
	}
	return;
}

void Dice::mroll(string s){
	for (int i = 0; s[i] != '\0'; i++){
		roll(s[i]);
	}
	return;
}

int main(){
	int a, b, c, d, e, f, q;
	cin >> a >> b >> c >> d >> e >> f >> q;
	Dice dice(a, b, c, d, e, f);
	int up, front;
	for (int i = 0; i < q; i++){
		cin >> up >> front;
		for (int j = 0; j < 3; j++){
			if (dice.num[0] == up) break;
			dice.roll('N');
			if (dice.num[0] == up) break;
			dice.roll('E');
		}
		for (int j = 0; j < 4; j++){
			if (dice.num[1] == front) break;
			dice.roll('L');
		}
		cout << dice.num[2] << endl;
	}
}


Measured memory_bytes: 3088
import java.util.*;

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

    String s = sc.next();
    char[] c = s.toCharArray();
    String ans = "No";

    Arrays.sort(c);
    if((c[0] == c[1]) && (c[2] == c[3]) && (c[0] != c[3])){
      ans = "Yes";
    }

    System.out.println(ans);
  }
}


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

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

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

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll>plus, minus;
    rep(i, 0, n){
        int a;
        cin >> a;
        if(a>=0)plus.push_back(a);
        else minus.push_back(a);
    }
    reverse(minus.begin(),minus.end());
    int p = plus.size();
    int q = minus.size();
    ll ans = inf;
    rep(i, 0, k+1){
        int cnt = 0;
        ll temp = 0;
        if(i>p || k-i >q)continue;
        if(i!=0)temp += plus[i-1], cnt++;
        if(i!=k)temp += -1*(minus[k-i-1]), cnt++;
        if(cnt == 2)temp+= min(plus[i-1], -1*(minus[k-i-1]));
        //cout << i <<  " "<<temp << " " << plus[i-1] << " " <<  -1*(minus[k-i-1]) << endl;
        ans = min(ans, temp);
    }
    cout << ans << endl;
}

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

const int N = 10;

char mx[N][N];
bool f[N][N];

int main() {
#ifdef HOME
	freopen("agc7a.in", "r", stdin);
	freopen("agc7a.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);	
	int n, m, lx, ly;
	bool flag = true;

	lx = ly = 1e9;

	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> (mx[i] + 1);
		for (int j = 1; j <= m; ++j) if (mx[i][j] == '#') {
			lx = min(lx, i), ly = min(ly, j); } }

	if (lx == 1e9) {
		cout << "Impossible" << endl;
		return 0; }

	while (true) {
		f[lx][ly] = true;
		if (mx[lx + 1][ly] == '#')
			lx+= 1;
		else if (mx[lx][ly + 1] == '#')
			ly+= 1;
		else
			break; }

	for (int i = 1; i <= n; ++i)
	for (int j = 1; j <= m; ++j) if (mx[i][j] == '#')
		flag&= f[i][j];

	cout << (flag ? "Possible" : "Impossible") << endl;		

	return 0; }


Measured memory_bytes: 256