akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
   int m, f, r, sum;

   scanf("%d %d %d", &m, &f, &r);
      while(m + f +r != -3){
         sum = m + f;
         if(m == -1 || f == -1){
            printf("F\n");
         } else if(sum >= 80){
            printf("A\n");
         } else if(sum >= 65){
            printf("B\n");
         } else if(sum >= 50){
            printf("C\n");
         } else if(sum >=30){
            if(r >= 50){
               printf("C\n");
            } else {
               printf("D\n");
            }
         } else{
            printf("F\n");
         }

      scanf("%d %d %d", &m, &f, &r);
      if(m + f + r == -3){
         break;
      }
      }

   return 0;
}



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

int main(){
  string s;
  cin >> s;
  int c = s.size(),cnt=0,cnt1=0,cnt2=0;
  int a[c],b[c];
  for(int i=0;i<c;i++){
    if(s.at(i)=='W'){
      cnt++;
      cnt1=0;
    }
    else{
      cnt1++;
      cnt = 0;
    }
    a[i]=cnt;
    b[i]=cnt1;
  }
  for(int i=0;i<c;i++){
    if(a[i]==1||b[i]==1)
      cnt2++;
  }
  cout << cnt2-1 << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

class UnionFind{
public:
	vector<ll> par;
	vector<ll> num;

	UnionFind(ll N):par(N),num(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		return par[x]=root(par[x]);
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
		num[ry] += num[rx];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}
};

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

	string S=in<string>();
	int K=in();
	vector<string> V;
	for(int k=0;k<K;k++){
		for(int i=0;i<S.size()-k;i++){
			V.emplace_back(S.substr(i,k+1));
		}
	}
	sort(ALL(V));
	unique(ALL(V));
	
	cout << V[K-1] << endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;

#define MOD 1000000007

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%MOD;
    }
    return res;
}

int main(){
    ll n;
    cin>>n;
    
    ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
    
    ans%=MOD;
    
    if(ans<0)
        ans=(ans+MOD)%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
from collections import defaultdict
n = int(input())

d = defaultdict(int)

i = 2
while i * i <= n:
    while n % i == 0:
        d[i] += 1
        n /= i
    i += 1
if n != 1:
    d[n] += 1

ans = 0
for v in d.values():
    # x * (x + 1) // 2 <= vとなる最大のx
    x = 0
    while (x + 1) * (x + 2) // 2 <= v:
        x += 1
    ans += x
print(ans)


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

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

    ll ans = 0;
    for (ll i = 1; i * i < N; i++) {
        if (N % i == 0) {
            if (N / i - 1 > i) {
                ans += N / i - 1;
            }
        }
    }

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

Measured memory_bytes: 256
#include<cstdio>
int arr[1010];
int count;
int main() {
	int n, a, b, x;
	scanf("%d%d%d", &n, &a, &b);
	for(int i=1; i<=n; i++) {
		scanf("%d", &x);
		if(x<a||x>=b) count++;
	}
	printf("%d\n", count);
	return 0;
}

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

int main(int argc, char *argv[]){
    int N,a,b,c;
	cin >> N;
	for (int i = 0; i < N; ++i){
		cin >> a >> b >> c;
		cout << (((a*a+b*b==c*c) || ((a*a+c*c==b*b) || (c*c+b*b==a*a))) ? "YES":"NO") << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    ll z = 0, h = 0;
    for (size_t i = 1; i <= n; i++) if (i % k == 0) ++z;
    if (k % 2 == 0) for (int i = 1; i <= n; i++) if (i % k == k / 2) ++h;
    ll ans = 0;
    ans += (ll)pow(z, 3) + (ll)pow(h, 3);
    cout << ans << endl;
    
    return 0;
}

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

template <std::uint_fast64_t mod>
class ModInt {
    using u64 = std::uint_fast64_t;

   public:
    u64 x;
    ModInt(const int x = 0) : x(x < 0 ? (mod - (-x % mod)) % mod : x % mod) {}

    ModInt operator+(const ModInt r) { return ModInt(*this) += r; }
    ModInt operator*(const ModInt r) { return ModInt(*this) *= r; }
    ModInt operator-(const ModInt r) { return ModInt(*this) -= r; }
    ModInt operator/(const ModInt r) { return ModInt(*this) /= r; }
    ModInt operator-() { return ModInt(mod - x); }

    ModInt &operator+=(const ModInt r) {
        x += r.x;
        if (x >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt r) {
        if (x < r.x) x += mod;
        x -= r.x;
        return *this;
    }
    ModInt &operator*=(const ModInt r) {
        x *= r.x;
        if (x >= mod) x %= mod;
        return *this;
    }
    ModInt &operator/=(ModInt r) {
        if (!(x % r.x)) {
            x /= r.x;
            return *this;
        }
        u64 p = mod - 2;
        *this *= r.pow(p);
        return *this;
    }
    ModInt &operator++(int) { return (*this) += 1; }
    ModInt &operator++() { return (*this) += 1; }
    ModInt &operator--(int) { return (*this) -= 1; }
    ModInt &operator--() { return (*this) -= 1; }

    bool operator<(const ModInt r) { return x < r.x; }
    bool operator>(const ModInt r) { return x > r.x; }
    bool operator<=(const ModInt r) { return x <= r.x; }
    bool operator>=(const ModInt r) { return x >= r.x; }
    bool operator==(const ModInt r) { return x == r.x; }
    bool operator!=(const ModInt r) { return x != r.x; }

    ModInt inv() { return (ModInt)1 / (*this); }
    int get_mod() { return mod; }

    friend std::istream &operator>>(std::istream &in, ModInt &m) {
        int a;
        in >> a;
        if (a < 0) a = mod - (-a % mod);
        if (a >= mod) a %= mod;
        m.x = a;
        return in;
    }
    friend std::ostream &operator<<(std::ostream &out, const ModInt &m) {
        out << m.x;
        return out;
    }
};
constexpr std::uint_fast64_t mod = 1e9 + 7;
using mint = ModInt<mod>;

template <typename T, typename U>
T pow(T x, U n) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main() {
    mint n;
    cin >> n;
    vector<mint> C;
    for (int i = 0; i < n.x; i++) {
        mint c;
        cin >> c;
        C.push_back(c);
    }
    sort(C.begin(), C.end(), [](mint x, mint y) { return x > y; });
    mint ans = 0;
    for (mint i = 0; i < n; i++) {
        ans += (i + 2) * C[i.x];
    }
    ans *= pow<mint, int>(4, n.x - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans=0;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                int total = i*500 + j*100 + k*50;
                if(total == x) ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
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 gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
ll n, x, a[100];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x;
  FOR(i, 0, n) cin >> a[i];
  sort(a, a+n);
  ll s = 0;
  FOR(i, 0, n) s += a[i];
  if(x > s){
    cout << n-1 << endl;
    return 0;
  }
  int idx = 0;
  s = 0;
  while(idx < n){
    s += a[idx];
    if(s > x){
      cout << idx << endl;
      return 0;
    }
    if(s == x){
      cout << idx+1 << endl;
      return 0;
    }
    idx++;
  }
  cout << idx << endl;
  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <cstdio>

using namespace std;

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

const int Max_N(200050);
typedef long long int LL;

int N, W[Max_N], P[Max_N];

struct node
{
	int u, cnt0, cnt1;
};
set<node> S;
int Father[Max_N];
node V[Max_N];
LL Ans;

int Get_Father(int x)
{
	return Father[x] == x ? x : Father[x] = Get_Father(Father[x]);
}

inline bool operator<(const node &a, const node &b)
{
	LL t1 = a.cnt1 * 1LL * b.cnt0, t2 = b.cnt1 * 1LL * a.cnt0;
	return t1 == t2 ? a.u < b.u : t1 < t2;
}

int main()
{
	gi(N);
	for (int i = 2;i <= N;++i)
		gi(P[i]);
	for (int i = 1;i <= N;++i)
	{
		gi(W[i]), Father[i] = i, V[i].u = i, V[i].cnt0 = (W[i] == 0), V[i].cnt1 = (W[i] == 1);
		if (i > 1)
			S.insert(V[i]);
	}
	for (node t;S.empty() == false;)
	{
		t = *S.begin(), S.erase(t);
		int fa = Get_Father(P[t.u]);
		if (fa != 1)
			S.erase(V[fa]);
		Ans += V[fa].cnt1 * 1LL * t.cnt0, V[fa].cnt0 += t.cnt0, V[fa].cnt1 += t.cnt1, Father[t.u] = fa;
		if (fa != 1)
			S.insert(V[fa]); 
	}
	print(Ans);
	return 0;
}

Measured memory_bytes: 23040
n = [int(_) for _ in input().split()]
if len(n) == 3 and all(1 <= item <= 9 for item in n):
    print('YES' if 0 == (100 * n[0] + 10 * n[1] + n[2]) % 4 else 'NO')
else:
    print('hoge!')

Measured memory_bytes: 2940
'use strict'
function Main (input) {
  const tmp = input.split('\n');
  const N = parseInt(tmp[0], 10);
  const stones = tmp[1].split(' ').map((elem) => parseInt(elem, 10));
 
  let dp = new Array(N);
  dp.fill(Infinity);
  dp[0] = 0;
  for (let i = 0; i < stones.length; i++) {
    for(let j = i + 1; j <= i + 2; j++ ) {
      if (j < stones.length) {
        dp[j] = Math.min(dp[j], dp[i] + Math.abs(stones[i] - stones[j]));
      }
    }
  }
  console.log(dp[stones.length - 1]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 27680
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    D = I()
    c = LI()
    s = LLIN(D)
    lst = [0] * 26
    total = 0
    for i in range(D):
        ans = int(input())-1
        l = s[i]
        for j in range(26):
            lst[j] += c[j]
        lst[ans] = 0
        total += s[i][ans]
        for li in lst:
            total -= li
        print(total)




if __name__ == '__main__':
    main()

Measured memory_bytes: 84080
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  s=chomp(readline())
  flag=(s[1]=='A') && (count(x->x=='C',s[3:end-1])==1) && (count(x->x in 'a':'z',s)==length(s)-2)
  println(flag ? "AC" : "WA")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 111200
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

string text,in;
int cur,len;

void out(){
  cout<<text.substr(0,cur)<<"^"<<text.substr(cur)<<endl;
}

int main()
{
  int CS,n; cin>>CS; cin.ignore();
  rep(cs,CS){
    getline(cin,text);
    cin>>n; cin.ignore();
    len=text.size();
    cur=0;
    rep(i,n){
      getline(cin,in);
      if(in=="forward char")cur=min(cur+1,len);
      else if(in=="backward char")cur=max(cur-1,0);
      else if(in=="delete char"){
	if(cur>=text.size())continue;
	text.erase(text.begin()+cur); len--;
      }
      else if(in.find("insert")!=in.npos){
	int s=in.find('"'),t=in.find('"',s+1);
	text=text.substr(0,cur)+in.substr(s+1,t-s-1)+text.substr(cur);
	cur+=t-s-1; len+=t-s-1;
      }
      else if(in=="forward word"){
	for(;cur<len&&text[cur]==' ';cur++);
	for(;cur<len&&text[cur]!=' ';cur++);
      }
      else if(in=="backward word"){
	for(;cur>0&&text[cur-1]==' ';cur--);
	for(;cur>0&&text[cur-1]!=' ';cur--);
      }
      else if(in=="delete word"){
	int s=cur,t;
	for(;text[s]==' ';s++);
	if(s>=len)continue;
	for(t=s;text[t]!=' '&&t<len;t++);
	text=text.substr(0,cur)+text.substr(t); len-=t-cur;
      }
    }
    out();
  }
  return 0;
}

Measured memory_bytes: 0
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Tue Jan 22 16:31:27 2019
//
package main

import "fmt"

func scanSlice(slice []int) {
	for i := range slice {
		fmt.Scan(&slice[i])
	}
}

func main() {
	var N int
	fmt.Scan(&N)

	slice := make([]int, N)
	scanSlice(slice)

	ans := 0
	for i := 0; i < 100; i++ {
		num := 0
		above0 := false
		for j := range slice {
			if slice[j] > 0 {
				slice[j]--
				above0 = true
			} else {
				if above0 {
					num++
					above0 = false
				}
			}
		}

		if above0 {
			num++
		}
		ans += num
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().toCharArray()[0];
		if (c>='A'&&c<='Z') {
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}
}

Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a + b == c || b + c == a || c + a == b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
        int a,b;
        scanf("%d %d", &a, &b);

        int r1 = a + b;
        int r2 = a - b;
        int r3 = a * b;

        if (r1 > r2) {
                if (r1 > r3) {
                        printf("%d", r1);
                } else {
                        printf("%d", r3);
                }
        } else {
                if (r2 > r3) {
                        printf("%d", r2);
                } else {
                        printf("%d", r3);
                }
        }
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
  int r0, w0, c, r;
  while (true) {
    cin >> r0 >> w0 >> c >> r;
    if (!(r0 || w0 || c || r)) break;

    int rest = w0*c - r0;
    if (rest < 0) cout << 0 << endl;
    else {
      if (rest % r == 0) cout << rest/r << endl;
      else cout << rest/r + 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<vector<int> > v(n);
  for(int i=0 ; i<n ; i++){
    v[i].resize(10);
    for(int j=0 ; j<10 ; j++){
      cin >> v[i][j];
    }
  }
  vector<vector<int> > p(n);
  for(int i=0 ; i<n ; i++){
    p[i].resize(11);
    for(int j=0 ; j<11 ; j++){
      cin >> p[i][j];
    }
  }
  ll sumax = -1e15;
  for(int bit=1 ; bit<(1<<10) ; bit++){
    vector<int> c(n, 0);
    ll sum = 0;

    for(int i=0 ; i<10 ; i++){//自分の店のi番目の時間帯がどうか
      if(bit & (1<<i)){//自分の店は開いている
        for(int j=0 ; j<n ; j++){//他の店はどうか
          if(v[j][i] == 1){
            c[j]++;
          }
        }
      }
    }
    for(int i=0 ; i<n ; i++){
      sum += p[i][c[i]];
    }
    sumax = max(sumax, sum);
  }
  cout << sumax << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V, string sep = " ", string end_ = "endl") {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << sep;
    }
    if(end_ == "endl")
        cout << endl;
    else
        cout << end_;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> B(N);
    list<int> A(0);
    rep(i, N) cin >> B[i];
    for(int i = N - 1; i >= 0; i--) {
        if(B.at(i) == i + 1) {
            B.erase(B.begin() + i);
            A.push_front(i + 1);
            i = B.size();
        }
    }
    if(B.empty()) {
        vecout(A, "\n");
    } else {
        cout << -1 << endl;
    }
}

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

struct Link {
    int num;
    int to;
    Link(int n, int t) {
        num = n;
        to = t;
    }
};

int N;
vector<vector<Link>> links;

void input() {
    cin >> N;
    links = vector<vector<Link>>(N);
    rep(i, N-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        links[a].push_back(Link(i, b));
        links[b].push_back(Link(i, a));
    }
}

int main() {
    input();
    vector<int> color(N);
    vector<bool> visit(N);
    vector<int> ans(N-1);
    int K = 1;
    vector<int> now_node{0};
    color[0] = 0;
    while (now_node.size() > 0) {
        vector<int> next_node;
        for (int i : now_node) {
            visit[i] = true;
            int k = 0;
            for (Link l : links[i]) {
                if (visit[l.to]) continue;
                next_node.push_back(l.to);
                k++;
                if (k == color[i]) k++;
                color[l.to] = k;
                ans[l.num] = k;
            }
            K = max(K, k);
        }
        now_node = next_node;
    }
    cout << K << endl;
    for (int x : ans) cout << x << endl;
}


Measured memory_bytes: 7524
n = int(input())
x = list(map(int, input().split()))
x_sort = sorted(x)
first_median = x_sort[n//2 - 1]
second_median = x_sort[n//2]
for i in x:
    if i <= first_median:
        print(second_median)
    else:
        print(first_median)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x)  (x).begin(),(x).end()

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;

    ll len = s.size();
    
    ll cnt = 0;
    rep(i, len){
        if(s[i] == '1'){
            cnt++;
        }
    }

    if(cnt <= len / 2) {
        cnt = len - cnt;
    }

    cout << 2*len - 2*cnt << endl;

    return 0;
}


Measured memory_bytes: 512
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
#include<bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define read(a) long long int a; cin>>a;
#define readstr(s) string s; cin>>s;
#define readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rloop(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define v(pi) vector<ll>pi
#define vp(pi) vector<pair<ll,ll>>pi
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#include <cmath>
#include <map>
#include <string>
#define mi(lol) map<ll,ll>lol
#define fsort(vec) sort(vec.begin(),vec.end())
#define rsort(vec) sort(vec.begin(),vec.end(),compare)
#define inf ll inf=INT_MAX
//sorting according to the second element vector 

bool compare(pair<ll,ll> p,pair<ll,ll> q){
	return p.second < q.second;	
}

//   example:-
//   sort(vec.begin(),vec.end(),compare);


int main() {
	fast;
	read(a)
	read(m)
	ll n=a/m;
	ll l=n+1;
	cout<<min(abs(a-n*m),abs(a-l*m))<<endl;
	return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heapreplace

def main():
    INF = 10 ** 9 + 5

    N, K, *TD = map(int, open(0).read().split())

    E = [[] for _ in range(N)]
    for t, d in zip(*[iter(TD)] * 2):
        E[t - 1].append(d)

    for e in E:
        if e:
            e.sort(reverse=True)
        else:
            e.append(-INF)
    E.sort(key=lambda x: -x[0])

    cur = 0
    Q = []
    for ei in E[:K]:
        cur += ei[0]
        for eij in ei[1:]:
            heappush(Q, -eij)

    for ei in E[K:]:
        for eij in ei:
            heappush(Q, -eij)

    res = cur + K * K
    for x in reversed(range(1, K)):
        v, w = E[x][0], -Q[0]
        if v < w:
            heapreplace(Q, -v)
            cur += w - v

        res = max(res, cur + x * x)

    print(res)

if __name__ == '__main__':
    main()


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

int main() {
  long long int A, B, K;
  scanf("%lld %lld %lld", &A, &B, &K);
  if (A > K)
    printf("%lld %lld", A - K, B);
  else if (B + A - K > 0) {
    printf("%lld %lld", 0, B + A - K);
  } else {
    printf("0 0");
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int> 

set<int> divs(int n){
  set<int> retset;
  for (int i=1;i<=(int)sqrt(n);i++){
    if (n%i==0){
      retset.insert(i);
      retset.insert(n/i);
    }
  }
  return retset;
}

int main(){
  int N; cin >> N;
  int A[N+2]={};
  for (int i=1;i<=N;i++) cin >> A[i];
  
  int L[N+2]={}, R[N+2]={},M[N+1]={};
  for (int i=1;i<=N;i++) L[i] = __gcd(L[i-1],A[i]);
  for (int i=N;i>=1;i--) R[i] = __gcd(R[i+1],A[i]);
  for (int i=1;i<=N;i++) M[i] = __gcd(L[i-1],R[i+1]);
  
  int retval = 1;
  for (int i=1;i<=N;i++) retval = max(retval,M[i]);
  
  cout << retval << endl;

  return 0;
}

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

int main(){

  string S;

  cin >> S;
  if(S == "AAA"){
    cout << "No" << endl;
  }else if(S == "BBB"){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * Soccer
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Short.parseShort(line);
			int[][] points = new int[n + 1][3];

			for (int i = 0; i < n + 1; i++) {
				points[i][0] = i;
			}

			int g = (n * (n - 1)) / 2;
			int t1, t2, p1, p2;
			StringTokenizer st;
			for (int i = 0; i < g; i++) {
				st = new StringTokenizer(br.readLine());
				t1 = Integer.parseInt(st.nextToken());
				t2 = Integer.parseInt(st.nextToken());
				p1 = Integer.parseInt(st.nextToken());
				p2 = Integer.parseInt(st.nextToken());

				if (p1 > p2) {
					points[t1][1] += 3;
				} else if (p1 == p2) {
					points[t1][1] += 1;
					points[t2][1] += 1;
				} else {
					points[t2][1] += 3;
				}
			}

			Arrays.sort(points, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return o2[1] - o1[1];
				}
			});

			int rank, prev;
			rank = 1;
			prev = points[0][1];
			for (int i = 0; i < n + 1; i++) {
				if (points[i][1] != prev) {
					rank = i + 1;
				}
				points[i][2] = rank;
				prev = points[i][1];
			}

			Arrays.sort(points, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return o1[0] - o2[0];
				}
			});

			StringBuilder sb = new StringBuilder();
			for (int i = 1; i < n + 1; i++) {
				sb.append(points[i][2] + "\n");
			}
			System.out.print(sb.toString());
		}

	}
}

Measured memory_bytes: 24828
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! {
        n: usize,
        a: [usize; n],
    }
    if let Some(max) = a.iter().max() {
        if let Some(min) = a.iter().min() {
            println!("{}", max - min);
        }
    }
}

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

    bool data[10][7]={
                    {1,1,1,1,1,1,0},
                    {0,1,1,0,0,0,0},
                    {1,1,0,1,1,0,1},
                    {1,1,1,1,0,0,1},
                    {0,1,1,0,0,1,1},
                    {1,0,1,1,0,1,1},
                    {1,0,1,1,1,1,1},
                    {1,1,1,0,0,1,0},
                    {1,1,1,1,1,1,1},
                    {1,1,1,1,0,1,1}};
    int n;
    while(cin>>n,n!=-1){
        bool now[7]={0,0,0,0,0,0,0};
        for(int i=0;i<n;i++){
            int x;
            cin>>x;

            for(int i=6;i>=0;i--){
                if(now[i]!=data[x][i]){
                    now[i]=1-now[i];
                    cout<<1;
                }
                else cout<<0;
            }
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        // スペース区切りの整数の入力
        // int b = sc.nextInt();
        // int c = sc.nextInt();
        // 文字列の入力
        // String s = sc.next();
        // 出力

        if( N <600){
            System.out.println(8);
        }else if (N<800){
            System.out.println(7);
        }else if (N<1000){
            System.out.println(6);
        }else if (N<1200){
            System.out.println(5);
        }else if (N<1400){
            System.out.println(4);
        }else if (N<1600){
            System.out.println(3);
        }else if (N<1800){
            System.out.println(2);
        }else if (N<2000){
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 35780
n, y = map(int, input().split())
a = 10000
b = 5000
c = 1000

for i in range(n+1):
    for j in range(n-i+1):
        if y - i * a - j * b == (n - i - j)* c:
            print(i, j, n - i - j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 40684
#include<stdio.h>
#include<string.h>
int main()
{
  char s[20];
  int i,leng,dem=0;
  scanf("%s", &s);
  leng = strlen(s);
  if (leng<8) 
  {
    printf("YES"); 
    return 0;
  }
  for (i=0; i<leng; i++)
  {
    if (s[i]=='x') dem++;
    if (dem>7)
    {
       printf("NO");
       return 0;
    }
  }
  printf("YES");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define pi 3.141592653589793238462
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
typedef long double ld;
ll ESP=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 ll n,k;
 cin>>n>>k;
 ll cnt1[n],cnt2[n];
 ll a[n];
 f(n)
 {
   cin>>a[i];
   cnt1[i]=0;
   cnt2[i]=0;
 }

 ll cnt=0;
 f(k)
 {
  ll x,y;
  cin>>x>>y;
  x--;y--;
  cnt1[x]++;
  cnt1[y]++;
  if(a[x]>a[y])
    cnt2[x]++;
  if(a[x]<a[y])
    cnt2[y]++;
 }
 for(ll i=0;i<n;i++)
 {
  if(cnt1[i]==cnt2[i])
    cnt++;
 }
 cout<<cnt<<"\n";
 return 0;


}


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

bool check_if_present(int x, vector<int>& vi) {
	for(int i = 0;i < vi.size(); i++){
		if(vi[i] == x)
			return true;
	}

	return false;
}

bool check(vector<vector<char> >& v, int& k, vector<int>& rows, vector<int>& cols) {
	int cnt = 0;
	for(int i  =0 ;i < v.size(); i++) {
		if(check_if_present(i, rows))
			continue;
		for(int j = 0; j < v[0].size(); j++) {
			if(check_if_present(j, cols))
				continue;
			if(v[i][j] == '#')
				cnt++;
		}
	}

	if(cnt == k)
		{
			// cout<<"rows: ";
			// for(int i = 0;i < rows.size(); i++){
			// 	cout<<rows[i]<<" ";
			// }
			// cout<<"\n";
			// cout<<"cols: ";
			// for(int i = 0;i < cols.size(); i++){
			// 	cout<<cols[i]<<" ";
			// }
			// cout<<"=============\n";
			return true;
		}
	return false;
}

int ans = 0;

void result_col(int cur_w,int& w,vector<vector<char> >& v, vector<int>& rows, vector<int>& cols, int& k) {
	ans+=check(v,k,rows,cols);
	for(int j = cur_w; j < w; j++) {
			cols.push_back(j);
			result_col(j + 1,w,v,rows,cols,k);
			cols.pop_back();
		}
}


void result(int cur_h,int& h, int& w,vector<vector<char> >& v, vector<int>& rows, vector<int>& cols, int& k) {
	result_col(0,w,v,rows,cols,k); //all possible columns
	for(int i = cur_h; i < h;i++){
		rows.push_back(i);
		result(i + 1,h , w, v, rows,cols,k);
		rows.pop_back();
	}
}


int main() {
	int h,w,k;
	cin>>h>>w>>k;

	vector<vector<char> > v(h, vector<char>(w));

	for(int i = 0;i < h; i++) { 
		for(int j  =0;j < w; j++) {
			cin>>v[i][j];
		}
	}

	vector<int> rows;
	vector<int> cols;

	result(0,h,w,v,rows,cols,k);
	cout<<ans<<"\n";

	return 0;
}

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

int main() {
  
  int N,sum=0;
  cin >> N;
  
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
  
}

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

using namespace std;

int main() {

    int n, m, v;
    int dx[] = {0, 1, 0, -1};
    int dy[] = {1, 0, -1, 0};
    char d;
    char ds[] = "NESW";

    while(cin >> n, n) {

        int rx = 10, ry = 10, cnt = 0;
        int graph[21][21];

        memset(graph, 0, sizeof(graph));

        for(int i = 0, x, y; i < n; ++i) {
            cin >> x >> y;
            graph[y][x] = 1;
        }

        cin >> m;

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

            cin >> d >> v;

            for(int j = 0; j < 4; ++j) {
                if(d == ds[j]) {
                    for(int k = 1; k <= v; ++k) {
                        rx += dx[j];
                        ry += dy[j];
                        if(graph[ry][rx] == 1) {
                            graph[ry][rx] = 0;
                            ++cnt;
                        }
                    }
                    break;
                }
            }

        }

        cout << (cnt == n ? "Yes" : "No") << endl;

    }

}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

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

const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> a(n), b(n), c(n);
  for(auto &e: a)cin>>e;
  for(auto &e: b)cin>>e;
  for(auto &e: c)cin>>e;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  vector<int> mid(n);
  int start=0;
  for(int i=0;i<n;i++){
    if(i!=0)mid[i]=mid[i-1];
    else mid[i]=0;
    int j=start;
    while(true){
      if(b[i]>a[j] && j<n){
        mid[i]++;
      }else{
        start=j;break;
      }
      j++;
    }
  }
  // for(int x:mid)cout<<x<<" ";
  // cout<<endl;
  start=0;
  vector<ll> ans(n);
  for(int i=0;i<n;i++){
    if(i!=0)ans[i]=ans[i-1];
    else ans[i]=0;
    int j=start;
    while(true){
      if(c[i]>b[j] && j<n){
        ans[i]+=ll(mid[j]);
      }else{
        start=j;break;
      }
      j++;
    }
  }
  // for(int x:ans)cout<<x<<" ";
  // cout<<endl;
  ll ret=0;
  for(int i=0;i<n;i++){
    ret += ans[i];
  }
  cout<<ret<<endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();
        String s = sc.next();

        sc.close();

        int x = 0;
        int max = 0;

        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'I') {
                x++;
                max = Math.max(max, x);
            } else {
                x--;
                max = Math.max(max, x);
            }
        }

        System.out.println(max);

    }
}

Measured memory_bytes: 21844
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}


int main() {
  int n, m; cin >> n >> m;
  vector<ll> p(m);
  vector<string> s(m);
  rep(i, m){
    cin >> p[i] >> s[i];
    --p[i];
  }

  ll acs = 0, pena = 0;
  vector<bool> v(n, false);
  vector<int> cnt(n, 0);
  rep(i, m){
    if(v[p[i]]) continue;
    if(s[i][0] == 'A'){
      ++acs;
      v[p[i]] = true;
      pena += cnt[p[i]];
    } else {
      ++cnt[p[i]];
    }
  }

  cout << acs << endl;
  cout << pena << endl;
}


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

// 展望台を表す配列
// city.first : 標高
// city.first : 標高で負けたかどうか
typedef pair<int, bool> city;

int main(void){
    // Your code here!
    int N, M;
    
    cin >> N >> M;
    
    city cities[N];
    for(int i=0; i<N; i++){
        cin >> cities[i].first;
        cities[i].second = false;
    }
    
    for(int j=0; j<M; j++){
        int start_city, goal_city;
        cin >> start_city >> goal_city;
        
        if (cities[start_city-1].first > cities[goal_city-1].first)
            cities[goal_city-1].second = true;
        else if (cities[start_city-1].first < cities[goal_city-1].first)
            cities[start_city-1].second = true;
        else{
            cities[start_city-1].second = true;
            cities[goal_city-1].second = true;
        }
    }
    
    
    int ans = 0;
    for(int i=0; i<N; i++){
        if (!cities[i].second)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4384
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;

ll xs, ys, xt, yt;
ll x[1200];
ll y[1200];
int en[1200];
ld dd[1200];
ld ed[1200][1200];
ld r[1200];
int n;


int main() {
	cin >> xs >> ys >> xt >> yt;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> x[i] >> y[i] >> r[i];
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			ld d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
			if (d > r[i] + r[j])
				ed[i][j] = d - r[i] - r[j];
		}
	for (int i = 0; i < n; ++i) {
		ld d = sqrt((x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys));
		if (d > r[i])
			ed[i][n] = ed[n][i] = d - r[i];
	}
	for (int i = 0; i < n; ++i) {
		ld d = sqrt((x[i] - xt) * (x[i] - xt) + (y[i] - yt) * (y[i] - yt));
		if (d > r[i])
			ed[i][n + 1] = ed[n + 1][i] = d - r[i];
	}
	ed[n][n + 1] = ed[n + 1][n] = sqrt((xs - xt) * (xs - xt) + (ys - yt) * (ys - yt));
	for (int i = 0; i <= n + 1; ++i)
		dd[i] = 1e10;
	dd[n] = 0;
	for (int i = 0; i <= n + 1; ++i) {
		int mn = -1;
		for (int j = 0; j <= n + 1; ++j)
			if (!en[j] && (mn == -1 || dd[mn] > dd[j]))
				mn = j;
		en[mn] = 1;
		for (int j = 0; j <= n + 1; ++j)
			dd[j] = min(dd[j], dd[mn] + ed[mn][j]);
	}
	printf("%.9Lf\n", dd[n + 1]);
	return 0;
}




Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define N 100001
int n,m,Q,a,b;
int dp[N],color[N];
vector<int> e[N];

void paint(int v,int d,int c){
	if(!color[v]) color[v]=c;
	if(dp[v]>=d || d==0)return;
	dp[v]=d;
	rep(i,e[v].size()){
		paint(e[v][i],d-1,c);
	}
}

void solve(int q){
	if(q==0)return;
	int v,d,c;
	cin>>v>>d>>c;
	solve(q-1);
	paint(v,d,c);
}

int main(void){
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	cin>>Q;
	solve(Q);
	rep(i,n)cout<<color[i+1]<<endl;
	return 0;
}

Measured memory_bytes: 10360
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

class Repeater{
    int st;
    int ed;
    int d;
public:
    class rep_iterator{
        int i; int d;
    public:
        rep_iterator(int x, int pd) :i(x), d(pd) {}

        int& operator*(){ return i; }
        bool operator==(const rep_iterator& k) const { return i == k.i; }
        bool operator!=(const rep_iterator& k) const { return i != k.i; }
        rep_iterator& operator++(){ i+=d; return *this; }
    };

    Repeater(int N) :st(0), ed(N), d(1) {}
    Repeater(int b, int e) :st(b), ed(e), d(1) {if(st > ed){ st--; ed--; d = -1; } }
    Repeater(int b, int e, int dif) :st(b), ed(e), d(dif) {}

    rep_iterator begin() const{ return rep_iterator(st, d); }
    rep_iterator end() const{ return rep_iterator(ed, d); }

};

template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
template<class T> using min_queue = p_queue<T, greater<T>>;
template<class T> using max_queue = p_queue<T, less<T>>;

template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }

ll gcd(ll A, ll B){
    if(B == 0) return A;
    return gcd(B, A%B);
}

ll calc_n(ll N, ll X, ll Y){
    ll ans = N;
    ans -= N / X;
    ans -= N / Y;
    ans += N / (X*Y / gcd(X, Y));
    return ans;
}

void sub_main(istream &cin) {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    if(!cin) return;
    
    cout << calc_n(B, C, D) - calc_n(A-1, C, D) << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_C.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int x, int y){
  if(y==0) 
    return x;
  else
    return gcd(y,x%y);
}

int main(){
  int a,b,x,y;
  scanf("%d",&a);
  scanf("%d",&b);
  if(a>b){
  x=a;
  y=b;
}
  else{
  x=b;
  y=a;
}

printf("%d\n",gcd(x,y));
return 0;
  
}


Measured memory_bytes: 2124
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

bool check(string& O, int start, int end)
{
    string S = O.substr(start, end - start);
    string S2(ALL(S));
    reverse(ALL(S2));
    return S == S2;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    cin >> S;
    const int N = S.size();
    cout << (check(S, 0, N) && check(S, 0, N / 2) 
            && check(S, N / 2 + 1, N) ? "Yes" : "No") << endl;
    return 0;
};

Measured memory_bytes: 256