akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
    int N;
    scanf("%d",&N);
    int v[N],rand;
    double mix=0;
    for(int i=0;i<N;i++){
        scanf("%d",&v[i]);
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(v[i]>v[j]){
                rand=v[i];
                v[i]=v[j];
                v[j]=rand;
            }
        }
    }
    for(int i=0;i<N;i++){
        if(i==0)
            mix=(v[i]+v[i+1])/(double)2;
        if(i>1)
            mix=(mix+v[i])/(double)2;
    }
    printf("%lf\n",mix);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    int red =0;
    int blue =0;
    for(int i=0;i<N;i++){
        if(s[i] == 'R'){
            red++;
        }else{
            blue++;
        }
    }
    if(red>blue){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 10007;
const ld PI = acosl(-1);

ll dijkstra(int s, int t, Graph<pii> &G) {
    int N = G.size();
    vector<ll> dist(N, 1e17);
    priority_queue<pli, vector<pli>, greater<pli>> que;

    dist[s] = 0;
    que.emplace(pli{s, dist[s]});
    while (!que.empty()) {
        auto [d, v] = que.top();
        que.pop();
        if (dist[v] < d)
            continue;
        for (auto [nv, cost] : G[v]) {
            if (dist[nv] <= dist[v] + cost)
                continue;
            dist[nv] = dist[v] + cost;
            que.push({dist[nv], nv});
        }
    }

    return dist[t];
}

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

    int N, M;
    cin >> N >> M;
    Graph<pii> G(N);

    for (int i = 0; i + 1 < N; ++i)
        G[i + 1].emplace_back(pii{i, 0});
    for (int i = 0; i < M; ++i) {
        int L, R, C;
        cin >> L >> R >> C;
        L--, R--;
        G[L].emplace_back(pii{R, C});
    }

    ll ans = dijkstra(0, N - 1, G);
    cout << (ans < 1e17 ? ans : -1) << endl;

    return 0;
}


Measured memory_bytes: 11320
//
//  main.cpp
//  B - Ordinary Number
//
//  Created by Hashizo on 2019/06/29.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

#undef INT_MAX
#undef INT_MIN

#define INT_MAX	2147483647
#define INT_MIN	(-INT_MAX  -1)

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define REPLACE(s, f, t) regex_replace(s, regex(f), t)

int main(int argc, const char * argv[]) {
	int cnt = 0;
	int n;
	cin >> n;

	int p[n];
	
	
	
	REP(i, n) {
		cin >> p[i];
	}
	
	FOR(i, 1, n-1) {
		if (p[i-1] > p[i]) {
			if (p[i+1] <= p[i]) {
				cnt++;
			}
		}
		else {
			if (p[i+1] > p[i]) {
				cnt++;
			}
		}
	}
	
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    N = int(input())

    for h in range(1, 3501):
        for n in range(1, 3501):
            if 4 * h * n - N * n - N * h > 0:
                w = (N * h * n) / (4 * h * n - N * n - N * h)
                if w.is_integer() and w > 0 and 4 * h * n * w == N * n * w + N * h * w + N * h * n:
                    print(h, n, int(w))
                    exit()


if __name__ == '__main__':
    resolve()


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

int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  
  if (c-a-b<0) puts("No");
  else {
    if (4*a*b<(c-a-b)*(c-a-b)) puts("Yes");
    else puts("No");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep_1(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define rep_2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main(){
    int a,b,m;cin>>a>>b>>m;
    vector<int> A(a),B(b);

    int mna = INF;
    rep(i,a){
        cin>>A[i];
        mna = min(mna,A[i]);
    }
    int mnb = INF;
    rep(i,b){
        cin>>B[i];
        mnb = min(mnb,B[i]);
    }
    int ans = mna + mnb;

    rep(i,m){
        int x,y,c;cin>>x>>y>>c;
        x--;
        y--;
        ans = min (ans,A[x] + B[y] - c);
    }

    cout << ans <<endl;


    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

int main(){
	std::vector<int> aList(4,0);

	for(int i=0; i<6; i++){
		int num;
		std::cin>>num;
		aList[num-1]++;
	}

	bool isAvailable=true;
	for(int i=0; i<4; i++)
		if(aList[i]>2)
			isAvailable=false;

	if(isAvailable)
		std::cout<<"YES"<<std::endl;
	else
		std::cout<<"NO"<<std::endl;

	return 0;
	
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0)break;
			team[] list = new team[n];
			for(int s=0;s<n;s++){
				list[s]=new team(in.nextInt());
				for(int i=0;i<4;i++){
					list[s].plus(in.nextInt(),in.nextInt());
				}
			}
			Arrays.sort(list);
			System.out.println(list[0].ban);
			System.out.println(list[1].ban);
			System.out.println(list[n-2].ban);
		}
	}
}
class team implements Comparable<team>{
	double time;
	int ban;
	team(int ban){
		time=0;
		this.ban=ban;
	}
	public void plus(int hun,int byou){
		time+=hun*60;
		time+=byou;
	}
	public int compareTo(team o) {
		if(this.time<o.time)return -1;
		else if(this.time>o.time)return 1;
		return 0;
	}
}

Measured memory_bytes: 70888
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,k,x,y,z1,z2;
  cin>>k>>a>>b;
  x=b/k; y=a/k;z1=b%k;z2=a%k;
  if(z1==0||z2==0) cout<<"OK";
  else if(x==0||y==0) cout<<"NG";
  else if((x*k)>=a&&(x*k)<=b) cout<<"OK";
  else if(((x+1)*k)>=a&&((x+1)*k)<=b) cout<<"OK";
 else if((y*k)>=a&&(y*k)<=b) cout<<"OK";
  else if(((y+1)*k)>=a&&((y+1)*k)<=b) cout<<"OK";
  else cout<<"NG";
   return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e6+1;
const int M = 1e4;
int n, a[N], A[M];
map<int, int> m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  a[1] = -1;
  FOR(i, 2, N){
    if(a[i]) continue;
    for(int j=i; j<N; j+=i) a[j] = i;
  }
  cin >> n;
  FOR(i, 0, n){
    int b, p=0, c=0;
    cin >> b;
    A[i] = b;
    while(b>0){
      if(p!=a[b]){
        if(p) maxs(m[p], c);
        p = a[b], c=0;
      }
      c++;
      b /= a[b];
    }
  }
  ll l = 1, ans = 0;
  for(auto p:m) l = l * modPow(p.fi, p.se, MOD) % MOD;
  FOR(i, 0, n) ans += l * modInv(A[i], MOD) % MOD;
  cout << ans % MOD << endl;
}

Measured memory_bytes: 4736
n,m=map(int,input().split())
a=list(map(int,input().split()));b=list(map(int,input().split()))
A=set(a);B=set(b)
c=1;N=0;M=0
for k in range(m*n,0,-1):
  if k in A and k in B:N+=1;M+=1
  elif k in A:c*=M;N+=1
  elif k in B:c*=N;M+=1
  else:c*=M*N-m*n+k
  c=c%(10**9+7)
print(c)

Measured memory_bytes: 3188
#include <stdio.h>

int main(void) {
	int a, b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else if(a == b){
		printf("a == b\n");
	}
	return 0;
}



Measured memory_bytes: 2604
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
vector <int> v;
void dfs(int digit, int pos, int num)
{
    if (pos == 11) return;
    num = (num * 10) + digit;
    v.pb(num);
    if (digit >= 1)
    {
        dfs(digit - 1, pos + 1, num);
    }
    if (digit < 9)
    {
        dfs(digit + 1, pos + 1, num);
    }
    dfs(digit, pos + 1, num);
}
int32_t main() {
    fast_io();
    int k;
    cin >> k;
    for (int i = 1; i <= 9; i++)
    {
        dfs(i, 0, 0); // assume starting of the number is digit i
    }
    sort(v.begin(), v.end());
    // for (auto p : v)
    //     cout << p << "\n";
    cout << v[k - 1] << "\n";
    return 0;
}

Measured memory_bytes: 10604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    string s;
    cin>>s;
    rep(i,s.size()-1){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using PP = pair<P, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 305;
const P INF = P(500,0);
int n, m, l, a, b, c, q, s, t, from, d[MX][MX];
P cost; //  (hokyu, cost)
vector<P> G[MX]; // to, dist
priority_queue<PP, vector<PP>, greater<PP>> qu; // ((hokyu,cost), to)
void dijkstra(int s){
	vector<P> dist(n,INF);
	qu.push(PP(P(0,0),s)); dist[s] = P(0,0);
	while(!qu.empty()){
		tie(cost,from) = qu.top(); qu.pop();
		if(dist[from] == cost){
			for(P it: G[from]){
				P tmp = cost;
				tmp.second += it.second;
				if(tmp.second > l){
					tmp.second = it.second;
					tmp.first++;
				}
				if(dist[it.first] > tmp){
					dist[it.first] = tmp;
					qu.push(PP(tmp, it.first));
				}
			}
		}
	}
	rep(i,n) d[s][i] = dist[i].first;
}
int main(){
	scanf("%d%d%d", &n, &m, &l);
	rep(i,m){
		scanf("%d%d%d", &a, &b, &c); a--; b--;
		if(c <= l){
			G[a].push_back(P(b,c));
			G[b].push_back(P(a,c));
		}
	}
	rep(i,n) dijkstra(i);
	scanf("%d", &q);
	rep(i,q){
		scanf("%d%d", &s, &t); s--; t--;
		printf("%d\n", d[s][t] == 500 ? -1 : d[s][t]);
	}
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

void solve()
{
  
  ll n; cin >> n;
  // ll x, y, z; cin >> x >> y >> z;
  // string s; cin >> s;
  vector<ll> a(n);   REP(i, n) cin >> a[i];
  vector<ll> r, l;
  REP(i, n) {
    if((n+i)%2 == 1) {
      l.push_back(a[i]);
    } else {
      r.push_back(a[i]);
    }
  }
  for(ll i = l.size()-1; i >= 0; i--) {
    cout << l[i] << " ";
  }
  for(auto v : r) {
    cout << v << " ";
  }
  cout << endl;
  
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 5484
import java.util.Scanner;

class Main
{
	private static int wall[];
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int w = sc.nextInt(),
				q = sc.nextInt();
			if (w == 0 && q == 0) break;
			wall = new int[w];
			for (int i = 0; i < w; i++) wall[i] = -1;
			for (int i = 0; i < q; i++)
			{
				char a = sc.next().charAt(0);
				if (a == 's')
				{
					int id = sc.nextInt(),
						width = sc.nextInt();
					int b = -1;
					for (int j = 0; j + width - 1 < w; j++)
					{
						if (check(j, width))
						{
							b = j;
							break;
						}
					}
					if (b == -1)
					{
						System.out.println("impossible");
					}
					else
					{
						System.out.println(b);
						for (int j = b; j < b + width; j++)
						{
							wall[j] = id;
						}
					}
				}
				else if (a == 'w')
				{
					int id = sc.nextInt();
					for (int j = 0; j < w; j++)
					{
						if (wall[j] == id)
							wall[j] = -1;
					}
				}
			}
			System.out.println("END");
		}
	}
	private static boolean check(int begin, int length)
	{
		for (int i = begin; i < begin + length; i++)
		{
			if (wall[i] != -1) return false;
		}
		return true;
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
int main() {
	int H, W, i, j;
	while (1) {
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0) {
			break;
		}
		for (i = 0;i < H;i++) {
			for (j = 0;j < W;j++) {
				if (i==0||i==(H-1)||j==0||j==(W-1)){
					printf("#");
				}
				else {
					 printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{

	char s[1000]; 
	int a,b;
	int i;
	cin>>s;
	for(i=0;s[i]!='\0';i++)
	{
		cout<<"x";
	
	}

}

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

int main(){
  long long n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  bool can=true;
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      can=false;
      break;
    }
  }
  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 1792
def solve(string):
    s, k = string.split()
    k = int(k)
    chars = sorted(set(s))
    exists = []

    def dfs(base):
        exists.append(base)
        if len(exists) >= k:
            return
        for c in chars:
            if base + c in s:
                dfs(base + c)

    for c in chars:
        dfs(c)

    return exists[k - 1]


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 3060
d,n = map(int,input().split())


i = 1
ans = 0

while True:
    cnt = 0
    s = i
    while s%100 == 0:
        s /= 100
        cnt += 1
        
    if cnt == d:
        ans += 1
        if ans == n:
            break
    i += 1
    
print(i)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e5 + 5;

int N, deg[maxn], c[maxn], d[maxn];
vector<int> adj[maxn];
priority_queue<ii, vector<ii>, greater<ii>> pq;

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  cin >> N;
  for(int i = 1; i < N; ++i){
    int u, v; cin >> u >> v;
    adj[u].eb(v); adj[v].eb(u);
    deg[u]++; deg[v]++;
  }
  for(int i = 1; i <= N; ++i){
    cin >> c[i];
    pq.push(mp(deg[i], i));
  }
  sort(c + 1, c + 1 + N);
  ll res = 0;
  for(int i = 1; i <= N; ++i){
    while(pq.size() && (deg[pq.top().se] != pq.top().fi || d[pq.top().se])) pq.pop();
    res += 1ll * c[i] * pq.top().fi;
    d[pq.top().se] = c[i];
    int u = pq.top().se; pq.pop();
    for(int v : adj[u]){
      if(d[v]) continue;
      deg[v]--;
      pq.push(mp(deg[v], v));
    }
  }
  cout << res << '\n';
  for(int i = 1; i <= N; ++i)
    cout << d[i] << ' ';
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////





int main() {

	ll N,M;
	cin >> N>>M;

	vector<vector<ll>> g(N+1,vector<ll>(N+1,0));

	repn(i, M) {
		ll a, b;
		cin >> a >> b;
		g[a][b] = 1;
		g[b][a] = 1;
	}

	vector<ll> v(N + 1);
	repn(i, N) { v[i] = i; }

	ll ans = 0;

	do {
		ll t = 1;
		if (v[1] != 1) { t = 0; }
		repn(i, N - 1) { if (g[v[i]][v[i + 1]] == 0) { t = 0; } }
		ans += t;
	} while (next_permutation(++v.begin(), v.end()));

	cout << ans;


	system("PAUSE");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int func(int64_t n) {
    int v = 0;
    while(n % 2 == 0) {
        n /= 2;
        v++;
    }
    return v;
}
int main() {
    int n;
    cin >> n;
    int sum = 0;
    int64_t a;
    for(int i = 0;i < n;i++) {
        cin >> a;
        sum += func(a);
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define fs first
#define sc second

using namespace std;
typedef double D;
typedef pair<int,int> P;
typedef pair<P,P> L;
typedef pair<D,int> pdi;

const D EPS = 1e-8;

inline D func(int x, P a, P b){
  int difx = b.fs - a.fs;
  D dify = b.sc - a.sc;
  return dify/difx * (x-a.fs) + a.sc;
}

int main(){
  int m,l,r;
  P p[110];
  L s[110];
  while(scanf("%d",&m),m){
    l = 10000, r = -10000;
    rep(i,m){
      scanf("%d%d",&p[i].fs,&p[i].sc);
      p[i].fs*=2;
      l = min(l,p[i].fs);
      r = max(r,p[i].fs);
    }
    rep(i,m){
      s[i] = L(p[i],p[(i+1)%m]);
      if(s[i].fs > s[i].sc)swap(s[i].fs,s[i].sc);
    }

    int ans = 0;
    for(int x=l+1;x<r;x+=2){
      vector<pdi> inv; inv.reserve(110);
      rep(i,m){
	if(s[i].fs.fs < x+EPS && x< s[i].sc.fs+EPS){
	  inv.push_back(pdi(func(x,s[i].fs,s[i].sc), i));
	}
      }

      sort(all(inv));
      int prv = -10000;
      for(int i=0;i<(int)inv.size();i+=2){
	int u = inv[i+1].sc, b = inv[i].sc;
	int up = ceil(max(func(x-1,s[u].fs,s[u].sc),
			  func(x+1,s[u].fs,s[u].sc))-EPS);
	int bot = floor(min(func(x-1,s[b].fs,s[b].sc),
			    func(x+1,s[b].fs,s[b].sc))+EPS);
	if(bot<prv)bot = prv;
	ans += up - bot;
	prv = up;
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1196
#include <cstdio>
#include <iostream>
#include <queue>
#include <map>  
using namespace std;
int ans = 0;

typedef pair<int,int >P;
int gh=0, gw=0;
char c[1000][1000];
int d[1000][1000];
int mh[4] = { 1,0,-1,0 };
int mw[4] = { 0,1,0,-1 };
char hijou[9] = { '1','2','3','4','5','6','7','8','9' };
void judge(int h, int w, int g) {
	queue<P> que;
	que.push(P(h,w));
	while (que.size()) {
		P p = que.front(); que.pop();
		if (c[p.first][p.second] == hijou[g])
		{
			gh = p.first;
			gw = p.second;
			ans+=d[p.first][p.second];
			break;
		}
		for (int i = 0; i < 4; i++) {
			int  nh = p.first + mh[i];
			int  nw = p.second + mw[i];
			if (nh >= 0 && nh < 1000 && nw >= 0 && nw < 1000 && d[nh][nw] == 500000 && c[nh][nw] != 'X') {
				d[nh][nw] = d[p.first][p.second] + 1;
				que.push(P(nh, nw));
			}
		}
	}
}
int main() {
	int h, w, n,sh,sw;
	for (int i = 0; i < 1000;i++){
		for (int j = 0; j < 1000; j++)
		{
			c[i][j] = 'X'; 
		}
	}
	cin >> h >> w >> n;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w;j++){
			cin >> c[i][j];
			if (c[i][j] == 'S') { sh = i; sw = j; }
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 1000; j++) {
			for (int k = 0; k < 1000; k++)
				d[j][k] = 500000;
		}
	
		d[sh][sw] = 0;
		judge(sh, sw, i);
		sh = gh; sw = gw;
}
	cout << ans << endl;

 	return 0;
}

Measured memory_bytes: 6100
#include <cstdio>
#include <vector>
#include <algorithm>

int n;
int W[1000], S[1000], V[1000];


std::vector<std::pair<int, long long int> > dp0, dp1, dp2;

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d%d%d", W+i, S+i, V+i);
  std::vector<std::pair<int, int> > v;
  for(int i = 0; i < n; i++){
    v.emplace_back(S[i] + W[i], i);
  }
  std::sort(v.begin(), v.end());

  dp0.emplace_back(0, 0);
  for(int i = 0; i < n; i++){
    int j = v[i].second;
    for(const auto &x: dp0){
      if(x.first > S[j]) break;
      dp1.emplace_back(x.first + W[j], x.second + V[j]);
    }
    for(auto i0 = dp0.begin(), i1 = dp1.begin(); ;){
      if(i0 == dp0.end()){ dp2.insert(dp2.end(), i1, dp1.end()); break; }
      if(i1 == dp1.end()){ dp2.insert(dp2.end(), i0, dp0.end()); break; }
      if(i0->first <= i1->first && i0->second >= i1->second) ++i1;
      else if(i0->first >= i1->first && i0->second <= i1->second) ++i0;
      else if(i0->first <= i1->first) dp2.push_back(*i0), ++i0;
      else dp2.push_back(*i1), ++i1;
    }
    dp1.clear();
    dp0.swap(dp2);
    dp2.clear();
//    for(const auto &x: dp0) printf("(%d %lld) ", x.first, x.second);
//    puts("");
  }
  printf("%lld\n", dp0.back().second);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
    string s;
    cin >> s;
    sort(all(s));

    cout << ((s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ? "Yes" : "No") << endl;
    
    return 0;
}

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

typedef long long ll;

ll inf = 1e9+7;
ll fact[200010] = {0};
ll inv[200010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			fact[i] = 1;
			inv[i] = 1;
		}
		else{
			fact[i] = (i*fact[i-1])%inf;
			inv[i] = mult(fact[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	else return (((fact[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll hcomb(ll n,ll k){
	if(n==0 && k==0) return 1;
	return comb(n+k-1,k);
}

int N,M,K;
ll X[200010],Y[200010];

int main(){
    cin >> N >> M >> K;
    factorial(N+M);
    ll ans = 0;
    for(ll i=1;i<=N-1;i++){
        ll num = N-i;
        (ans += num*i%inf*M%inf*M%inf)%=inf;
    }
//    (ans1 *= comb(N,K-2))%=inf;
//    (ans1 *= M*M%inf*comb(M,K-2))%=inf;
    for(ll i=1;i<=M-1;i++){
        ll num = M-i;
        (ans += num*i%inf*N%inf*N%inf)%=inf;
    }
//    (ans2 *= comb(M,K-2))%=inf;
//    (ans2 *= N*N%inf*comb(N,K-2)%inf)%=inf;
    for(ll i=1;i<=K-2;i++){
        (ans *= (M*N-2)-(i-1))%=inf;
        (ans *= mult(i,inf-2))%=inf;
    }
    cout << ans << endl;
}

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

int main()
{
   int n,sum;
   cin>>n>>sum;
   long int wei[n],val[n];
   for(int i=0;i<n;i++)
   cin>>wei[i]>>val[i];
   vector<long int>tmp(sum+1,0);
   vector<vector<long int>>dp(n,tmp);  
   for(int i=0;i<=sum;i++)
   if(wei[0]<=i)
   dp[0][i]=val[0];
   
   for(int i=1;i<n;i++)
   for(int j=1;j<=sum;j++)
   {
     if(j-wei[i]>=0)
     dp[i][j]=val[i]+dp[i-1][j-wei[i]];
     dp[i][j]=max(dp[i-1][j],dp[i][j]);
   }

   cout<<dp[n-1][sum]<<endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long i, a, b, sum=0;
    cin >> a;
    b=a;
    for(i=1;i<n;i++){
        cin >> a;
        if(a < b){
            sum += b-a;
        }else{
            b=a;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << max({a * c, a * d, b * c, b * d}) << endl;
}


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

int main() {
    string s;
    cin >> s;

    int ans = 0;
    int cnt = 0;
    rep(i, s.size()) {
        char c = s[i];
        if (c == 'A' || c== 'C' || c == 'G' || c == 'T') ++cnt;
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#define INF 1000010000
using namespace std;

vector<long long> vec[4];
long long sar[4][110];

int main(){
	long long N,W;
	cin>>N>>W;
	long long we1,we,va;
	cin>>we1>>va;
	vec[0].push_back(va);
	for(long long i=1;i<N;i++){
		cin>>we>>va;
		vec[we-we1].push_back(va);
	}
	for(long long i=0;i<=3;i++) sort(vec[i].begin(),vec[i].end(),greater<long long>());

	for(long long i=0;i<=3;i++){
		for(long long j=0;j<vec[i].size();j++){
			sar[i][j+1]=sar[i][j]+vec[i][j];
		}
	}

	long long lo[4];
	long long sum=0;
	for(lo[0]=0;lo[0]<=vec[0].size();lo[0]++){
		for(lo[1]=0;lo[1]<=vec[1].size();lo[1]++){
			for(lo[2]=0;lo[2]<=vec[2].size();lo[2]++){
				for(lo[3]=0;lo[3]<=vec[3].size();lo[3]++){
					if(lo[0]*we1+lo[1]*(we1+1)+lo[2]*(we1+2)+lo[3]*(we1+3)<=W){
						sum=max(sum,sar[0][lo[0]]+sar[1][lo[1]]+sar[2][lo[2]]+sar[3][lo[3]]);
					}
				}
			}
		}
	}

	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
using namespace std;
typedef long long ll;

int main(){
    int n;
    for(;;){
        scanf("%d",&n);
        if(n==0) break;
        vector<int> dp(n);
        dp[0]=1;
        dp[1]=2;
        dp[2]=4;
        for(int i=3;i<n;i++){
            dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
        }
        printf("%d\n",dp[n-1]%3650==0?dp[n-1]/3650:dp[n-1]/3650+1);
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
bool check(string str)
{
    string opp = str;
    reverse(opp.begin(), opp.end());
    for(int i = 0; i < opp.length(); i++)
    {
        if(opp[i] == str[i] && i == opp.length() - 1)
            return true;
        if(opp[i] != str[i])
            return false;
    }
    
}
string cut(string str, int n, int mode)
{
    string tmp;
    switch(mode)
    {
        case 1:
            for(int i = 0; i < n; i++)
            {
                tmp += str[i];
            }
            break;
        case 2:
            for(int i = n - 1; i < str.length(); i++)
            {
                tmp += str[i];
            }
            break;
    }

    return tmp;
}
int main()
{


    string str;
    cin >> str;
    int n = str.length();
    string tmp;

    if(check(str) && check(cut(str, (n - 1) / 2, 1)) && check(cut(str, (n + 3) / 2, 2)))
        cout << "Yes";
    else
        cout << "No";
}



Measured memory_bytes: 256
N = int(input())
bs = [int(i) for i in input().split()]
cs = bs.copy()
f = [False for i in range(N)]

def solve():
    ans = []
    i = N - 1
    while i >= 0:
        if f[i]:
            i -= 1
            continue
        
        if cs[i] == 1:
            ans.append(bs[i])
            f[i] = True
            i -= 1
        elif cs[i] < 1:
            return []
        else:
            j = i
            flg = True
            while j >= 0:
                if f[j]:
                    j -= 1
                    continue
                if cs[j] == 1:
                    ans.append(bs[j])
                    f[j] = True
                    flg = False
                    break
                else:
                    cs[j] -= 1
                    j -= 1
            if flg:
                return []
    return ans

ans = solve()
if len(ans) == 0:
    print(-1)
else:
    print(*ans, sep='\n')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

const int N = 2e5;
const int INF = 2e9;
const double PI = acos(-1);

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    string str;
    cin >> str;

    int len = str.length();
    int a=0, b=0, c=0;
    for(int i=0;i<len;++i){
        if(str[i] == 'a') a++;
        if(str[i] == 'b') b++;
        if(str[i] == 'c') c++;
    }

    int minn = min(a, min(b,c));
    a -= minn;
    b -= minn;
    c -= minn;

    if(a > 1 || b > 1 || c > 1) cout << "NO\n";
    else cout << "YES";

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;


int main() {

	int x, a;
	cin >> x >> a;

	if (x < a)cout << 0;
	else cout << 10;

	cout << endl;

	return 0;
}





Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int as[N + 1][M + 1];
  vector<int> ks(N + 1);
  for (int i = 1; i <= N; ++i) {
    int ki;
    cin >> ki;
    ks[i] = ki;
    for (int j = 1; j <= ki; ++j) {
      int ai;
      cin >> ai;
      as[i][j] = ai;
    }
  }

  bool ans[M + 1];
  fill(ans, ans + M + 1, true);
  for (int i = 1; i <= N; ++i) {
    bool tmp[M + 1];
    fill(tmp, tmp + M + 1, false);
    for (int j = 1; j <= ks[i]; ++j) {
      int num = as[i][j];
      tmp[num] = true;
    }

    for (int j = 1; j <= M; ++j) {
      if (!tmp[j]) {
        ans[j] = false;
      }
    }
  }

  int cnt = 0;
  for (int i = 1; i <= M; ++i) {
    if (ans[i]) {
      ++cnt;
    }
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#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>>;


int main(){
    string s, t;
    cin >> s >> t;
    ll ans = t.size();
    for(ll i = 0; i + t.size() <= s.size(); ++i){
        ll count = 0;
        REP(j, t.size()){
            count += t.at(j) != s.at(i + j);
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int A, B;
	cin >> A >> B;
	if ((abs(A - B) & 1)) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << (A + B) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=min(a,k);
	k-=min(a,k);
	k-=min(b,k);
	ans-=min(c,k);
	cout<<ans;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n,k; cin >> n >> k;
  vl hp(n);
  
  rep(i,n){
    ll x; cin >> x;
    hp.at(i) = x;
  }
  
  sort(all(hp));
  
  ll sum = 0;
  rep(i,n-k){
    sum += hp.at(i);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define vec std::vector<ll>
#define mp map<ll,ll>
#define fo(i,j,n) for(ll i=j;i<n;i++)
#define co cout<<
#define end <<"\n"
using namespace std;
int main (){
    boost;
    ll a,b,c,d,ans=-1*1e18;
    cin>>a>>b>>c>>d;
    ans=max(b*d,ans);
    ans=max(a*d,ans);
    ans=max(a*c,ans);
    ans=max(b*c,ans);
    cout<<ans;
   
   
    return 0;
}



Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if (S.substr(0, 4) == "YAKI") {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K

int main(){
	ll x,y;
	cin >> x >> y;
	ll minNum = (ll)min(x,y);
	ll maxNum = (ll)max(x,y);
	ll commonDivisor = maxNum%minNum;
	if(commonDivisor == 0){
		cout << minNum << endl;
		return 0;
	}
	for(int i=(ll)min(minNum,commonDivisor);;i--){
		if(minNum%i==0 && commonDivisor%i==0){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3096
/*----------------by syr----------------*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

const int INF=1e9+7;

int n;
int a[100005];
char s[100005];

bool judge(int p){
	int l=p-1+n,r=p+1;
	l%=n;r%=n;
	if(a[p]==0){
		if(s[p]=='o'&&a[l]==a[r]) return true;
		else if(s[p]=='x'&&a[l]!=a[r]) return true;
	}else{
		if(s[p]=='o'&&a[l]!=a[r]) return true;
		else if(s[p]=='x'&&a[l]==a[r]) return true;
	}
	return false;
}

void arrange(){
	for(int i=1;i<n-1;i++){
		int l=i-1,r=i+1;
		if(a[i]==0){
			if(s[i]=='o') a[r]=a[l];
			else a[r]=a[l]^1;
		}else{
			if(s[i]=='o') a[r]=a[l]^1;
			else a[r]=a[l];
		}
	}
	if(judge(0)&&judge(n-1)){
		for(int i=0;i<n;i++){
			if(a[i]==0) printf("S");
			else printf("W");
		}
		puts("");
		exit(0);
	}
}

int main(){
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			memset(a,-1,sizeof(a));
			a[0]=i,a[1]=j;
			arrange();
		}
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 768
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
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")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read::<i64>();
    }
    aseq.sort();
    println!("{}", aseq.last().unwrap() - aseq[0]);
}


Measured memory_bytes: 4352
#include<iostream>
#include<math.h>
using namespace std;

long double cost[1002][1002];
long double d[1002];
bool used[1002];

int main() {

	long double d[1002];
	long double x[1002], y[1002], r[1002];
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	int i, n, j;
	cin >> n;
	r[0] = 0; r[1] = 0;
	for (i = 0; i < n; i++) {
		cin >> x[i + 2] >> y[i + 2] >> r[i + 2];
	}
	for (i = 0; i < n + 2; i++) {
		for (j = 0; j < n + 2; j++) {
			cost[i][j] = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) - r[i] - r[j];
			if (cost[i][j] < 0)cost[i][j] = 0;
		}
	}
	long double INF = 3000000000;

	for (i = 0; i <= n + 1; i++) {
		d[i] = INF;
		used[i] = false;
	}
	d[0] = 0;
	while (true) {
		int v = -1;

		for (int u = 0; u < n + 2; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v]))v = u;
		}
		if (v == -1)break;
		used[v] = true;
		for (int u = 0; u < n + 2; u++) {
			if (d[u] > d[v] + cost[v][u]) {
				d[u] = d[v] + cost[v][u];
			}
		}
	}

	printf("%.10Lf\n",d[1]);
	return 0;

	/*int n, x;
	cin >> n >> x;
	long long int a[100001];
	int i;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
	}

	long long int counter = 0;
	for (i = 1; i <= n; i++) {
		if (a[i] + a[i - 1] > x) {
			//cout << i << endl;
			counter = counter + (a[i] + a[i - 1] - x);
			a[i] = a[i] - (a[i] + a[i - 1] - x);
			//cout << a[i] << endl;a
			
		}
	}
	cout << counter << endl;
	return 0;*/
}

Measured memory_bytes: 19572
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

//unionfind
//init: union_find name(size)

class union_find{
private:
    //根にはグループの要素数に―1をかけたもの、それ以外には根の値
    //初期値は-1
    vector<int> uni;
public:
    //Constructer
    //uniを必要なサイズで初期化する、初期値は―1
    union_find(int unisize) : uni(unisize,-1){}

    //引数aの根を求める、なければaを根として返す
    int root(int a){
        if(uni[a] < 0) return a;
        return uni[a] = root(uni[a]);  
    }

    //頂点aとbを繋ぐ関数unite
    //戻り値：
    //  元々同じグループであればfalse
    //  連結に成功すればtrue
    bool unite(int a, int b){
        //a, bにそれぞれが属するグループの根を入れる
        //uni[a], uni[b]がa, bがそれぞれが属するグループのサイズになる
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a,b); //bの方を大きいものにする
        uni[a] += uni[b];
        uni[b] = a; //大きい方のグループに属するものの親を小さいものの根にする(rootが高速で動くようになる)
        return true;
    }
    //頂点aとbが同じグループかを調べる
    bool isConnected(int a, int b){
        return root(a) == root(b);
    }
    //頂点aを含むグループの頂点数を調べる
    int unisize(int a){
        return -uni[root(a)];
    }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m,k; cin >> n >> m >> k;
    union_find uni(n+1);
    int a,b;
    vector<int> friends(n+1,0);
    rep(i,m){
        cin >> a >> b;
        uni.unite(a,b);
        friends[a]++;
        friends[b]++;
    }
    
    vector<int> blocked(n+1,0);
    int c,d;
    rep(i,k){
        cin >> c >> d;
        if(uni.isConnected(c,d)){
            blocked[c]++;
            blocked[d]++;
        }
    }
    rep(i,n) cout << uni.unisize(i+1) - (friends[i+1] + blocked[i+1]) -1 << " ";

}

Measured memory_bytes: 2048
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for(ll i=n-1;i>=a;i--)
#define nl "\n"
#define LLMAX 1e18
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define fastread cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
#define online_judge

const ll MOD=1e9+7;

ll pow(ll n, ll e){
  if(e==0)
    return 1;
  else if(e==1)
    return n;
  else if(e%2==0)
    return pow(n,e/2);
  else
    return pow(n,e/2)*n;
}

bool prime(ll n){
  ll ct=0;
  rep(i,2,sqrt(n)+1){
    if(n%i==0)
      return false;
  }
  return true;
}

void solve(){
  fastread;
  ll n,m,temp,mi,q,ma=0,t;
  ll x,y;
  cin >> n >> m;
  ll sum=0;
  while(n--){
    cin >> x >> y;
    if(sqrt(x*x + y*y)<=m)
      sum++;
  }
  cout << sum;
}

int main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
  #endif
  clock_t start, end;
  start = clock();
  solve();
  end=clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    cerr << "Time taken by program is : " << fixed  
         << time_taken << setprecision(5); 
    cerr << " sec " << endl;
  return 0;
}

Measured memory_bytes: 3820
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

using namespace std;

int combi(int n, int s, int usedNum = 0){
	int combiCount = 0;
	int tmp;
	n--;
	for(int i = usedNum; i <= 9; i++){
		tmp = s - i;		
		if(n != 0){
			combiCount += combi(n, tmp, i + 1);
		}
		else if(n == 0 && tmp == 0){
			return 1;
		}
	}
	return combiCount;
}


int main(){
	int n, s;
	int combiCount = 0;
	while(cin >> n >> s && (n != 0 || s != 0)){
		combiCount = combi(n, s);
		cout << combiCount << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
while True:
        H, W = map(int, input().split())
        if H == 0 and W == 0:
                break
        countl = 0
 
        while True:
                if W == 0:
                        break
                if countl == H:
                        break
                elif countl % 2 == 0:
                        countll = 0
                        while True:
                                if countll % 2 == 0:
                                        print('#', end='')
                                        countll += 1
                                else:
                                        print('.', end='')
                                        countll += 1
                                if countll == W:
                                        print()
                                        break
                elif countl % 2 == 1:
                        countll = 0
                        while True:
                                if countll % 2 == 0:
                                        print('.', end='')
                                        countll += 1
                                else:
                                        print('#', end='')
                                        countll += 1
                                if countll == W:
                                        print()
                                        break
                countl += 1
        print()

Measured memory_bytes: 9008
(* O(√n) *)
let n = read_int () in
let f m =
  if m = 0 then 0
  else
    let r = n mod m in
    let q = n / m in
    if r = q then m else 0 in
let rec sum acc i =
  if i * i > n then acc
  else if n mod i <> 0 then sum acc @@ i + 1
  else
    let j = n / i in
    sum (acc + f (i - 1) + if i <> j then f @@ j - 1 else 0) @@ i + 1 in
sum 0 1 |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;
typedef unsigned long long ULL;

struct Dict {
    map<string,int> dict;
    int id;
    Dict() : id(0) {}

    int get(const string &name) {
        if(dict.count(name)) return dict[name];
        return dict[name] = id++;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        Dict dict;
        vector<ULL> price(N);
        vector<vector<int> > materials(N);
        for(int i = 0; i < N; ++i) {
            string name;
            int p;
            cin >> name >> p;
            price[dict.get(name)] = p;
        }
        int M;
        cin >> M;
        for(int i = 0; i < M; ++i) {
            string to;
            cin >> to;
            const int to_id = dict.get(to);
            int cnt;
            cin >> cnt;
            while(cnt--) {
                string material;
                cin >> material;
                materials[to_id].push_back(dict.get(material));
            }
        }
        vector<ULL> memo(price);
        while(true) {
            bool updated = false;
            for(int i = 0; i < N; ++i) {
                const vector<int> &list = materials[i];
                if(list.size() == 0) continue;
                ULL acc = 0;
                for(vector<int>::const_iterator it = list.begin(); it != list.end(); ++it) {
                    acc += memo[*it];
                }
                if(acc < memo[i]) {
                    memo[i] = acc;
                    updated = true;
                }
            }
            if(!updated) break;
        }
        string target;
        cin >> target;
        cout << memo[dict.get(target)] << endl;
    }
    return 0;
}

Measured memory_bytes: 1244