akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int n;
            int count;

            bool[] array;

            while (true)
            {
                n = cin.GetInt();

                if (n == 0)
                    break;

                count = 0;

                array = new bool[2 * n + 1];

                for (int i = 2; i <= Math.Sqrt(2 * n); i++)
                {
                    for (int j = 2; i * j < 2 * n + 1; j++)
                    {
                        // ?´???°??§???????????? true
                        array[i * j] = true;
                    }
                }

                for (int i = n + 1; i < 2 * n + 1; i++)
                {
                    if (!array[i])
                        count++;
                }

                Console.WriteLine(count);
            }
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        private string[] _s;
        private int _i;
        private char[] _sep = { ' ', ',' };

        public string GetLine()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            string line;
            this._i = 0;
            do
            {
                line = Console.ReadLine();
            } while (line == "");

            this._s = line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);

            return this._s[this._i++];
        }

        public int GetInt()
        {
            return int.Parse(this.GetLine());
        }

        public long GetLong()
        {
            return long.Parse(this.GetLine());
        }

        public double GetDouble()
        {
            return double.Parse(this.GetLine());
        }
    }
}

Measured memory_bytes: 6300
n = int(input())
nums = list(map(int, input().split()))

ans = 0
for i in range(n):
  if i ==0:
    ans += nums[0]
  else:
    if i+1<=len(nums):
      ans += min(nums[i],nums[i-1])
    else:
      ans += nums[-1]
print(ans)

Measured memory_bytes: 3060
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(M)]

# print(a,b,xyc)
ans = min(a)+min(b)
for i in range(M):
    x = a[xyc[i][0]-1]
    y = b[xyc[i][1]-1]
    nedan = x + y - xyc[i][2]
    if nedan < ans:
        ans = nedan
print(ans)

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

int main(){
	int five_count = 2;
	int seven_count = 1;
	for(int i = 0; i<3; i++){
		int tmp;
		cin >> tmp;
		if(tmp == 5 && five_count){
			five_count--;
		} else if (tmp == 7 && seven_count){
			seven_count--;
		} else {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;
using Real = double;
using Point = complex< Real >;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

//constexpr long long MOD = 1000000007;
constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001LL;
constexpr double INF = 1e10;
constexpr Real EPS = 1e-10;
const Real PI = acos(-1);
using number = double;


int main() {
    int n; cin >> n;
    vll d(n);
    rep(i,n) cin >> d[i];

    if(d[0] != 0){
        cout << 0 << endl;
        return 0;
    }

    vll hs(101010);
    rep(i,n) hs[d[i]]++;

    if(hs[0] != 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;

    // ll num = 1; 
    // bool funi = false;
    // bool ok = true;
    for(ll i = 1; i < 101000; i++){
        if(hs[i]){
            rep(j,hs[i]) ans = (ans * hs[i-1]) % MOD;
        }
        else continue;
    }

    cout << ans << endl;
  
}

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

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  
  ll sum = 0, res1 = 0;
  if(a[0] > 0)
  {
    sum = a[0];
  }
  else
  {
    sum = 1;
    res1 += 1 - a[0];
  }
  for(int i = 1; i < n; i++)
  {
    sum += a[i];
    if(i % 2 == 1 && sum >= 0)
    {
      res1 += sum + 1;
      sum = -1;
    }
    else if(i % 2 == 0 && sum <= 0)
    {
      res1 += 1 - sum;
      sum = 1;
      
    }
    //cout << sum << " " << res1 << endl;
  }
  
  sum = 0;
  ll res2 = 0;
  if(a[0] < 0) sum = a[0];
  else
  {
    res2 += 1 + a[0];
    sum = -1;
  }
  for(int i = 1; i < n; i++)
  {
    sum += a[i];
    if(i % 2 == 1 && sum <= 0)
    {
      res2 += 1 - sum;
      sum = 1;
    }
    else if(i % 2 == 0 && sum >= 0)
    {
      res2 += 1 + sum;
      sum = -1;
    }
    //cout << sum << " " << res2 << endl;
  }
  cout << min(res1, res2) << endl;

  
  return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;

    int A, B;
    cin >> A >> B;

    string U;
    cin >> U;

    if(U == S) {
        A--;
    } else {
        B--;
    }

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

Measured memory_bytes: 256
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: u32
    }
    for i in n..1000 {
        let cs = i.to_string().chars().collect::<Vec<char>>();
        if cs.iter().all(|c| *c == cs[0]) {
            println!("{}", cs.into_iter().collect::<String>());
            return;
        }
    }
}


Measured memory_bytes: 4352
def f(a):
	r = []
	for d in range(1,int(a ** 0.5) + 1):
		if a % d == 0:
			r.append(d)	
			if d * d != a: r.append(a/d)
	return r if r else [1]
a,b,k = map(int, raw_input().split(' '))
r = []
for d in f(a):
	if d in f(b):
		r.append(d)

r.sort()

print r[-k]

Measured memory_bytes: 85308
#include <stdio.h>

int main() {
	int n, m, l, nm[101][101], ml[101][101];
	long long int max[101][101];
	for (int k = 0; k < 100; k++) {
		for (int i = 0; i < 100; i++) {
			nm[k][i] = 0;
			ml[k][i] = 0;
			max[k][i] = 0;
		}
	}

	scanf("%d %d %d", &n, &m, &l);

	for (int i = 0; i < n; i++) {
		for (int p = 0; p < m; p++) {
			scanf("%d", &nm[i][p]);
		}
	}
	
	for (int i = 0; i < m; i++) {
		for (int p = 0; p < l; p++) {
			scanf("%d", &ml[i][p]);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int p = 0; p < m; p++) {
			for (int q = 0; q < l; q++) {
				max[i][q] += nm[i][p] * ml[p][q];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int p = 0; p < l-1; p++) {
			printf("%lld ", max[i][p]);
		}
		printf("%lld\n", max[i][l-1]);
	}
	
}


Measured memory_bytes: 2928
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, T; cin >> N >> T;
    int mi = 1 << 30;
    int ma = 0;
    map<int, int> M;
    vector<int> A(N);
    rep(i, N) {
        cin >> A.at(i);
        if (mi > A[i]) {
            mi = A[i];
            ma = A[i];
        }
        if (ma < A[i]) {
            ma = A[i];
            M[ma-mi]++;
        }
    }

    cout << rbegin(M)->second << endl;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = (1ll << 31) - 1;
const int MOD = (int)(1e9) + 7;
const int NIL = -1;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct SegmentTree {
	int n;
	vector<int>d, lazy;
	SegmentTree(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, INF);
		lazy.assign(2 * n, NIL);
	}
	void eval(int k, int l, int r) {
		if (lazy[k] != NIL) {
			d[k] = lazy[k];
			if (r - l > 1)lazy[2 * k] = lazy[2 * k + 1] = lazy[k];
			lazy[k] = NIL;
		}
	}
	void update(int a, int b, int x, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = x;
			eval(k, l, r);
		}
		else {
			update(a, b, x, 2 * k, l, (l + r) / 2);
			update(a, b, x, 2 * k + 1, (l + r) / 2, r);
			d[k] = min(d[2 * k], d[2 * k + 1]);
		}
	}
	int find(int a, int b, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		if (r <= a || b <= l)return INF;
		eval(k, l, r);
		if (a <= l&&r <= b)return d[k];
		else return min(find(a, b, 2 * k, l, (l + r) / 2), find(a, b, 2 * k + 1, (l + r) / 2, r));
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegmentTree seg(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int s, t; cin >> s >> t;
			cout << seg.find(s, t + 1) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			seg.update(s, t + 1, x);
		}
	}
	return 0;
}

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

const int mod = 998244353;

#define N 3000030
int fac[N], rfac[N], ri[N];
void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i ++) fac[i] = 1ll * fac[i-1] * i % mod;
    rfac[0] = rfac[1] = 1, ri[1] = 1;
    for(int i = 2; i < N; i ++) {
        int t = mod / i;
        ri[i] = (1ll * t * (mod - ri[mod % i])) % mod;
        rfac[i] = (1ll * rfac[i-1] * ri[i]) % mod;
    }
}

int C(int n, int k) {
	if (!(0 <= k && k <= n)) return 0;
	return 1ll * fac[n] * rfac[k] % mod * rfac[n-k] % mod;
}

int main() {
	init();
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0;
	for (int o = m & 1; o <= m && o <= n; o += 2) {
		int d = (3 * m - o) / 2;
		ans = (ans + 1ll * C(n, o) * ((C(n + d - 1, d) - 1ll * o * C(n + d - m - 1, d - m) - 1ll * (n - o) * C(n+d-m-2,d-m-1)) % mod)) % mod;
	}
	if (ans < 0) ans += mod;
	cout<<ans<<endl;
}


Measured memory_bytes: 35456
#include<stdio.h>
#include<math.h>
int main(){
	int i;
	double a[4],d;
	for(i=0;i<4;i++)scanf("%lf",&a[i]);
	d=sqrt(pow((a[2]-a[0]),2.0)+pow((a[3]-a[1]),2.0));
	printf("%lf\n",d);
	return 0;
}

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

int main() {
    int n, a[110];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = n - 1; i > 0; --i) {
        cout << a[i] << ' ';
    }
    cout << a[0] << endl;
    
    return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

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

    for (int i = n - 1; i >= 0; i--) {
        if (i == n - 1) {
            vv[i] = min(vv[i], vt[i]);
        } else {
            vv[i] = min(vv[i], vv[i + 1] + vt[i]);
        }
    }

    int v = 0;
    int res = 0;
    int r = 0;
    for (int i = 0; i < n; i++) {
        int next = 0;
        int now = vv[i];
        if (i + 1 < n) next = vv[i + 1];
        for (int j = 1; j <= vt[i]; j++) {
            if (v - (vt[i] - j + 1) == next) {
                v--;
            } else if (v - (vt[i] - j + 1) == next - 1) {
                if (v != now) r++;
            } else {
                if (v < now) v++;
            }
            res += v;
        }
    }
    cout << res + r / 4;
    if (r % 4 > 0) {
        cout << "." << (r % 4) * 25;
    }
    cout << endl;
}




Measured memory_bytes: 3632
<?php

function move($x, $y, $map, &$visit){
    // x,y 座標
    // map 与えられた地図
    // visit 塗りつぶした箇所の地図（情報）
    $dx = [1,-1,0,0];
    $dy = [0,0,1,-1];
    // 上下左右（xとy）で動きを表現する。
    if (($map[$y][$x] == '.' || $map[$y][$x] == '@') && $visit[$y][$x] == false){
        $visit[$y][$x] = true;
        for ($i = 0; $i < 4; $i++){
            if(($x + $dx[$i] < count($map[$y]) && $x + $dx[$i] >= 0) && ($y + $dy[$i] < count($map) && $y + $dy[$i] >= 0)){
                // printmap($visit);
                move($x + $dx[$i], $y + $dy[$i], $map, $visit);
            }
        }
    }
}

function printmap($map){
    foreach($map as $ma){
        foreach($ma as $m){
            if($m){
                echo 'X';

            } else {
                echo '.';
            }
        }
        echo "\n";
    }
}


$numbers = preg_split("/[\s,]+/", rtrim(fgets(STDIN)));
$w = intval($numbers[0]);
$h = intval($numbers[1]);

while ($w != 0){
    $map = [];
    for ($i = 0; $i < $h; $i++){
        $ar = [];
        for ($j = 0; $j < $w; $j++){
            $ar[] = ' ';
        }
        $map[] = $ar;
    }
    $visit = [];
    for ($i = 0; $i < $h; $i++){
        $ar = [];
        for ($j = 0; $j < $w; $j++){
            $ar[] = false;
        }
        $visit[] = $ar;
    }
    $visit1 =& $visit;

    $x = 0;
    $y = 0;
    for ($i = 0; $i < $h; $i++){
        $c = rtrim(fgets(STDIN));
        for ($j = 0; $j < $w; $j++){
            $map[$i][$j] = substr($c, $j, 1);
            if($map[$i][$j] == '@'){
                $x = $j;
                $y = $i;
            }
        }
    }

    // printmap($map);
    // exit;

    $count = 0;
    move($x, $y, $map, $visit1);
    // printmap($visit1);
    foreach ($visit1 as $vi){
        foreach ($vi as $v){
            if ($v){
                $count += 1;
            }
        }
    }
    echo $count;
    echo "\n";

    $numbers = preg_split("/[\s,]+/", rtrim(fgets(STDIN)));
    $w = intval($numbers[0]);
    $h = intval($numbers[1]);
}



Measured memory_bytes: 10476
#include <iostream>
#include <algorithm>

using namespace std;

int powi(int x, int a) {
    if (a == 0) return 1;
    else {
        int xa = powi(x, a/2);
        if (a%2 == 0) return xa*xa;
        else return xa*xa*x;
    }
}

int main() {
    int m, k;
    cin >> m >> k;
    int len = powi(2, m);
    if (k >= len) {
        cout << -1 << '\n';
        return 0;
    }
    if (m == 1) {
        if (k == 0) cout << "0 0 1 1\n";
        else cout << -1 << '\n';
        return 0;
    }
    for (int j=0; j<len; j++)
        if (j != k)
            cout << j << ' ';
    cout << k << ' ';
    for (int j=len-1; j>=0; j--)
        if (j != k)
            cout << j << ' ';
    cout << k << '\n';
    return 0;
}


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

struct edge {int to,cost;};

#define P pair<int,int>

int v;
vector<edge> g[100];
long long int d[100];

const long long int INF = 1000000*500;

void swap(edge& a, edge& b){
  edge tmp;
  tmp.to = a.to; a.to = b.to; b.to = tmp.to;
  tmp.cost = a.cost; a.cost = b.cost; b.cost = tmp.cost;
}

long long int dijkstra(int s,int a){

  priority_queue<P,vector<P>,greater<P> > que;
  fill(d,d+v,INF);
  d[s] = 0;
  que.push(P(0,s));

  while(!que.empty()){
    P p = que.top(); que.pop();
    int k = p.second;
    if (d[k] < p.first) continue;
    for(int i=0; i<g[k].size(); i++){
      edge e = g[k][i];
      if(d[e.to] > d[k] + e.cost){
        d[e.to] = d[k] + e.cost;
        que.push(P(d[e.to],e.to));
      }
    }
  }
  if(d[a] != INF){
    return d[a];
  }
  else{
    return -1;
  }
}
int main(){

    int k;

    while(1){

      cin >> v >> k;

      if(v == 0 && k == 0){
        break;
      }

      for(int i=0; i<100; i++){
        vector<edge>().swap(g[i]);
      }

      int order,a,b,c;

      while(k--){
        cin >> order;
        if(order == 0){
          cin >> a >> b;
          a--;b--;
          cout << dijkstra(a,b) << endl;
        }
        else{
          bool flag = false;
          cin >> a >> b >> c;
          a--;b--;
        /*  for(int i=0; i<g[a].size(); i++){
            if(g[a][i].to == b){
              if(g[a][i].cost > c){
                g[a][i].cost = c;
                for(int j=0; j<g[i].size(); j++){
                  if(g[i][j].to == a){
                    g[i][j].cost = c;
                    break;
                  }
                }
                flag = true;
                break;
              }
            }
          }
          if(!flag){*/
            edge ed;
            ed.to = b;
            ed.cost = c;
            g[a].push_back(ed);
            ed.to = a;
            g[b].push_back(ed);
        //  }
        }
      }

    }


    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define mx3(a,b,c) max(max(a,b),c)
#define pq priority_queue<long long int> 
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
ll dp[101][100001];
ll solve(ll w[],ll v[],int n,int wi)
{
    if((n==0)||(wi==0))
        dp[n][wi] = 0;
    if(dp[n][wi]!=-1)
        return dp[n][wi];
    if(dp[n-1][wi]==-1)
        dp[n-1][wi] = solve(w,v,n-1,wi);
    if(w[n]<=wi)
        if(dp[n-1][wi-w[n]]==-1)
            dp[n-1][wi-w[n]] = solve(w,v,n-1,wi-w[n]);
    if(w[n]>wi)
        dp[n][wi] = dp[n-1][wi];
    else
        dp[n][wi] = max(v[n] +dp[n-1][wi-w[n]] , dp[n-1][wi]);
    return dp[n][wi];
}

int main()
{
    flash;
    memset(dp,-1,sizeof(dp));
    ll t,n,wi,i;
    t=1;
    while(t--)
    {
        cin>>n>>wi;
        ll w[n+1],v[n+1];
        FOR(i,1,n+1)  cin>>w[i]>>v[i];
        
        ll x = solve(w,v,n,wi);
        cout<<x<<endl;
    }
}

Measured memory_bytes: 79232
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class UnionFindTree
{
private:
    const int n;
    vector<pair<int, T> > parent; // 親ノード
    vector<int> rank;             // 木の高さの上限

    pair<int, T> find(int x){
        if(parent[x].first == x){
            return parent[x];
        }else{
            pair<int, T> p = find(parent[x].first);
            p.second += parent[x].second;
            return parent[x] = p;
        }
    }
public:
    UnionFindTree(int n) : n(n){ // コンストラクタ
        parent.resize(n);
        for(int i=0; i<n; ++i)
            parent[i] = make_pair(i, 0);
        rank.assign(n, 0);
    }
    bool unite(int a, int b, T diff){ // aとbのグループを併合
        pair<int, T> x = find(a);
        pair<int, T> y = find(b);
        a = x.first;
        b = y.first;
        if(a != b){
            if(rank[a] < rank[b]){
                parent[a] = make_pair(b, y.second - x.second + diff);
            }else{
                parent[b] = make_pair(a, x.second - y.second - diff);
                if(rank[a] == rank[b])
                    ++ rank[a];
            }
            return true;
        }
        else{
            return x.second - y.second == diff;
        }
    }
    pair<bool, T> getDiff(int a, int b){ // aとbの値の差を調べる
        pair<int, T> x = find(a);
        pair<int, T> y = find(b);
        if(x.first == y.first)
            return make_pair(true, x.second - y.second);
        else
            return make_pair(false, 0);
    }
};

int main()
{
    int n, m;
    cin >> n >> m;

    UnionFindTree<int> uft(n);
    for(int i=0; i<m; ++i){
        int l, r, d;
        cin >> l >> r >> d;
        -- l;
        -- r;
        if(!uft.unite(l, r, d)){
            cout << "No" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    string s;
    cin >> s;
    string ret = "";

    rep(i,3)
    {
        if(s.substr(i,1) == "1")
            ret += "9";
        else
            ret += "1";
    }
    
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>

using namespace std;


int main(){
	int n;
	int ans = 0;

	while(cin >> n){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				for(int x=0;x<10;x++){
					for(int y=0;y<10;y++){
						if(i+j+x+y == n)ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
		ans = 0;
	}

	return 0;
}

Measured memory_bytes: 3220
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())

r = [0]*n
g = [0]*n
b = [0]*n

rc,gc,bc = 0,0,0

for i in range(n-1,-1,-1):
    if s[i] == "R":
        rc += 1
    elif s[i] == "G":
        gc += 1
    else:
        bc += 1

    r[i] = rc
    g[i] = gc
    b[i] = bc

if n in [1,2]:
    print(0)
else:
    res = 0
    for i in range(1,n-1):
        for j in range(i):
            if s[i] == s[j]:
                continue
            if s[i] != "G" and s[j] != "G":
                res += g[i+1]
                if i+i-j < n and s[i+i-j] == "G":
                    res -= 1
            if s[i] != "B" and s[j] != "B":
                res += b[i+1]
                if i+i-j < n and s[i+i-j] == "B":
                    res -= 1
            if s[i] != "R" and s[j] != "R":
                res += r[i+1]
                if i+i-j < n and s[i+i-j] == "R":
                    res -= 1
            
    print(res)            

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

int main(){
  int K, S;
  cin >> K >> S;

  int ans=0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if(0 <= z && z <= K) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    vector<int> a(n,0);
    rep(i,n)cin>>a[i];
    vector< vector<int> > v(h,vector<int>(w,0));
    queue<int> que;
    rep(i,n)
    {
        rep(j,a[i])
        {
            que.push(i+1);
        }
    }
    rep(i,h)
    {
        if(i%2==0)
        {
            rep(j,w)
            {
                v[i][j]=que.front();
                que.pop();
            }
        }
        else
        {
            for(int j=w-1;j>=0;j--)
            {
                v[i][j]=que.front();
                que.pop();
            }
            
        }
        
    }
    rep(i,h)
    {
        rep(j,w)
        {
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
    #define vi vector<int>
    #include <algorithm>
    #include <iterator>
    #include<iostream>
     
    using namespace std;
     
    int main()
    {
        int n;
        cin>>n;
      	if(n==2){cout<<"Garbage"<<endl;}
        int dp[3]={0};
        for(int d=0;d<n;d++){
            int arr[3];
            for(int i=0;i<3;i++) scanf("%d", &arr[i]);
            int curr[3] = {0};
            for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                    if(i==j)continue;
                    curr[j] = max(curr[j], dp[i] + arr[j]);
                }
            }
     
            for(int z = 0;z<3;z++){
                dp[z] = curr[z];
            }
        }
        printf("%d", max({dp[0], dp[1], dp[2]}));
       return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
void R_YESNO(bool p){cout<<(p?"YES":"NO")<<endl;}
void R_YesNo(bool p){cout<<(p?"Yes":"No")<<endl;}

/*!* [fenwick] *!*/
/*+* フェニック木
     長さNの配列の部分和と更新をO(log N)で行う *+*/
template <typename T, typename F = function<T(T, T)>>
struct Fenwick {
    int N;
    vector<T> array;
    const F f;
    const T id;
    Fenwick() {}
    Fenwick(int len, const F f, const T &id) : N(len), f(f), id(id) {
        array.assign(N, id);
    }
    inline int LSB(int x) { return x & (-x); }
    void update(int i, T val) {
        for (; i < N; i += LSB(i + 1)) {
            array[i] = f(array[i], val);
        }
    }
    // sum of the elements [0:i]
    T sum(int i) {
        T s = id;
        for (i++; i; i -= LSB(i)) {
            s = f(s, array[i - 1]);
        }
        return s;
    }
};

struct Data {
    i64 h, a;
};

int main() {
    int N;
    cin >> N;
    vector<Data> data(N);
    for(Data &x : data) {
        cin >> x.h;
        x.h--;
    }
    for(Data &x : data) cin >> x.a;
    Fenwick<i64> fenwick(N + 1, [](i64 x, i64 y) -> i64 {return max(x, y);}, 0);
    for(int i = 0; i < N; i++) {
        i64 x = fenwick.sum(data[i].h);
        fenwick.update(data[i].h, x + data[i].a);
    }
    i64 ans = 0;
    for(int i = 0; i < N; i++) {
        ans = max(ans, fenwick.array[i]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define ft first
#define sd second
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 1e5 + 10;
const int MOD = 1e9 + 7;
LL num[60];
LL p[qq];
int main(){
	LL n;	scanf("%lld", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%lld", num + i);
	}
	LL k = 0;
	while(1) {
		int cnt = 0;
		for(int i = 0; i < n; ++i) {
			if(num[i] <= n - 1)	cnt++;
		}
		if(cnt >= n)	break;
		LL sum = 0;
		for(int i = 0; i < n; ++i) {
			p[i] = num[i] / n;
			sum += p[i];
		}
		k += sum;
		for(int i = 0; i < n; ++i) {
			num[i] = num[i] - p[i] * n + (sum - p[i]);
		}
	}
	printf("%lld\n", k);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a[6];
    int max;
    for(int i = 0; i<5; i++){
        cin>>a[i];
        if(i == 0){
         max = a[0];
        }
        if(a[i]%10!=0&&10-max%10<(a[i]/10+1)*10-a[i]){
            
            max = a[i];
        }
    }
    
    int sum = 0; 
    int count = 0;
    for(int i = 0; i<5; i++){
        if(a[i]%10!=0){
            
            count++;
            sum = sum+(10-a[i]%10);
        }
        sum = sum+a[i];
    }
    if(count==0){
        cout<<sum<<endl;
        return 0;
    }
   
    
    cout<<sum-(10-max%10)<<endl;
    return 0;
}

Measured memory_bytes: 256
//解説AC
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;

    // 「1 の個数」「0 の個数」を交互に記録していく
    vector<int> nums;    
    if (S[0] == '0') nums.push_back(0); // 先頭が 0 だったら
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i]) ++j; // S[i] の数値がどこまで続くか
        nums.push_back(j - i);
        i = j;
    }
    if (S.back() == '0') nums.push_back(0); // 最後尾が 0 だったら

    // 累積和
    vector<int> sums((int)nums.size() + 1, 0);
    for (int i = 0; i < nums.size(); ++i) sums[i+1] = sums[i] + nums[i];

    // 偶数番目の添字から始まる、長さ 2K+1 (以下) の区間の総和のうち、最大値を求める
    int res = 0;
    for (int left = 0; left < sums.size(); left += 2) {
        int right = left + K*2+1;
        if (right >= sums.size()) right = (int)sums.size() - 1;
        res = max(res, sums[right] - sums[left]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define int long long 
using namespace std;

int32_t main(){

    int n , sum = 0;  cin >> n;
    vector<int> a(n);   for(int x=0;x<n;x++) cin >> a[x] , sum += a[x];
    int fi = 0 , ans = 2e9;

    for(int x=0;x<n-1;x++){
        fi += a[x];
        int se = sum - fi;
        ans = min(ans , abs(se - fi));
    }

    cout << ans << endl;

    return 0;
}

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


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

Measured memory_bytes: 3912
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


# https://atcoder.jp/contests/abc094/tasks/arc095_b
n = a_int()
A = ints()
if len(A) == 2:
    A.sort()
    exit(*A[::-1])
ma = max(A)
ans = -1
d = 10**10
for a in A:
    if abs(a - ma / 2) < d:
        d = abs(a - ma / 2)
        ans = a


print(ma, ans)


Measured memory_bytes: 80040
program gluttony
  implicit none
  integer :: n, i
  integer(8) :: k, l = -1_8, r = 1000000000000_8, m, s
  integer(8), dimension(200000) :: a = 0_8, f = 0_8
  read(*,*) n, k
  read(*,*) a(1:n)
  if (sum(a(1:n)) <= k) then
    write(*,'(i0)') 0
    stop
  end if
  read(*,*) f(1:n)
  call bitonic_sort(a(1:n),.true.)
  call bitonic_sort(f(1:n),.false.)
  do while (r-l > 1_8)
    m = (l+r)/2_8
    s = 0_8
    do i = 1, n
      if (a(i)*f(i) <= m) cycle
      s = s+(a(i)*f(i)-m+f(i)-1_8)/f(i)
    end do
    if (s <= k) then
      r = m
    else
      l = m
    end if
  end do
  write(*,'(i0)') r
contains
  recursive subroutine bitonic_sort(a,ascend)
    integer(8), intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n
    n = size(a)
    if (n == 1) return
    call bitonic_sort(a(1:n/2),.not.ascend)
    call bitonic_sort(a(n/2+1:n),ascend)
    call bitonic_merge(a,ascend)
  end
  recursive subroutine bitonic_merge(a,ascend)
    integer(8), intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n, m, i
    n = size(a)
    if (n == 1) return
    m = 1
    do while (2*m < n)
      m = 2*m
    end do
    do i = 1, n-m
      if ((a(i) > a(i+m)) .eqv. ascend) then
        a(i) = xor(a(i),a(i+m))
        a(i+m) = xor(a(i),a(i+m))
        a(i) = xor(a(i),a(i+m))
      end if
    end do
    call bitonic_merge(a(1:m),ascend)
    call bitonic_merge(a(m+1:n),ascend)
  end
end program gluttony

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll c=0;
  ll x[n];
  cin>>x[0];
  for(int i=1;i<n;i++){
    cin>>x[i];
    c+=min((x[i]-x[i-1])*a,b);
  }
  cout<<c<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
 

int parentNode(int i);
int leftChild(int i);
int rightChild(int i);
void maxHeapify(int i);
void buildMaxHeap(void);
 

int A[500001];
int n;
 

main(){
 
    int i;

    scanf("%d", &n);
    for(i=1; i<=n; i++){
        scanf("%d", &A[i]);
    }
     
    buildMaxHeap();
     
    for(i=1; i<=n; i++){

        printf(" %d", A[i]);

    }
     
    printf("\n");
     
    return 0;
     
}
 
int parentNode(int i){

    return (int)i/2;

}
 
int leftChild(int i){

    return 2*i;

}
 
int rightChild(int i){

    return 2*i+1;

}
 
void maxHeapify(int i){

    int l = leftChild(i);
    int r = rightChild(i);
    int largest, tmp;
     
    if(l <= n && A[l] > A[i]){

        largest = l;  
  
    }else{

        largest = i;

    }
    if(r <= n && A[r] > A[largest]){
        largest = r;    
    }
    if(largest != i){

        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(largest);

    }
}
 
void buildMaxHeap(void){

    int i;
    for(i=(int)n/2; i>0; i--)
        maxHeapify(i);

}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

ll mod_num = 1e9+7;

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

    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    dp[0][0] = 1.0;

    rep(i, n) rep(j, n) {
        dp[i+1][j] += dp[i][j] * (1.0-p[i]);
        dp[i+1][j+1] += dp[i][j] * p[i];
    }

    double ans = 0;
    // 表の数が裏を上回る位置(半分から、全て表までの確率を足し合わせたのが答え)
    for(int i=n/2+1; i <= n; i++) ans += dp[n][i];

    cout << std::setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 70784
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	a <- readInt
	print $ n^2 - a


Measured memory_bytes: 508
import math

k = int(input())
ans = 0

for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            ans += math.gcd(math.gcd(a, b), c)*6

for a in range(1,k):
    for b in range(a+1,k+1):
        ans += math.gcd(a,b)*6

for a in range(1,k+1):
    ans += a

print(ans)


Measured memory_bytes: 9200
import java.util.Scanner;                      
                                               
 class Main {                                  
    public static void main(String[] args) {   
     Scanner scanner = new Scanner(System.in);      

     int a=0;
     int b=0;
     int c=0;
     int d=0;
	    a = scanner.nextInt();
	    b = scanner.nextInt();
	    c = scanner.nextInt();

     for(int i=a ; i<=b;i++){
    	 if(c%i == 0){
    		 d++;}
    		
     }
System.out.println(d);
     scanner.close();
    }                                          
 }  
                 



Measured memory_bytes: 26172
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        String s=scn.next();
        int min=1000;
        for(int i=0;i<s.length()-2;i++){
            int check=Integer.parseInt(s.substring(i, i+3));
            if(min>Math.abs(check-753)){
                min=Math.abs(check-753);
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = "575";
			s = s.replaceFirst(sc.next(), "");
			s = s.replaceFirst(sc.next(), "");
			s = s.replaceFirst(sc.next(), "");
			System.out.println(s.length() == 0 ? "YES" : "NO");
		}
	}
}


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

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

  string ans = "No";
  if ((N.at(0) == N.at(1) && N.at(0) == N.at(2)) ||
      (N.at(1) == N.at(2) && N.at(1) == N.at(3)))
    ans = "Yes";

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i = a; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef complex<double> P;

#define EPS (1e-10)

int n;
P s,g;
P p[52][4];
double h[52];

double dot(P a,P b){
  return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a,P b){
  return (a.real() * b.imag() - a.imag() * b.real());
}

int ccw(P a,P b,P c){
  b -= a;
  c -= a;
  if(cross(b,c) > 0) return +1;
  if(cross(b,c) < 0) return -1;
  if(dot(b,c) < 0) return +2;
  if(abs(b) < abs(c)) return -2;
  return 0;
}

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

int inter(P a,P b,P c,P d){
  return
    ccw(a,b,c) * ccw(a,b,d) <= 0 &&
    ccw(c,d,a) * ccw(c,d,b) <= 0;
}

bool error(int i){
  P a = p[i][0];
  P b = p[i][2];
  if(a.real() <= s.real() && s.real()<= b.real()
     && a.imag() <= s.imag() && s.imag() <= b.imag()){
    return true;
  }
  if(a.real() <= g.real() && g.real()<= b.real()
     && a.imag() <= g.imag() && g.imag() <= b.imag()){
    return true;
  }

  rep(j,4){
    if(inter(s,g,p[i][j],p[i][(j+1)%4])){
      return true;
    }
  }

  return false;
}

double calc(double r , double hh){
  if(r<=hh){
    return r;
  }
  else{
    return (hh*hh+r*r)/(2*hh);
  }
}

void solve(){
  double r = 999999999;

  rep(i,n){
    if(error(i)){
      //cout<<"error "<<endl;
      cout<<"0.0000"<<endl;
      return;
    }

    double minDist = 999999999;
    rep(j,4){
      double dist = distanceSP(s,g,p[i][j]);
      dist = min(dist  ,distanceSP(p[i][j] , p[i][(j+1)%4] , s));
      dist = min(dist  ,distanceSP(p[i][j] , p[i][(j+1)%4] , g));
      //            cout<<"dist"<<j<<" "<<dist<<endl;
      minDist = min(dist,minDist);

    }
    r = min(r,calc(minDist,h[i]));
  }
  printf("%.4f\n",r);
}

int main(){
  /*
  P d = P(0,0);
  P e = P(10,0);
  P f = P(12,0);
  P g = P(20,0);
  cout<<inter(d,e,f,g)<<endl;
  */

  while(cin>>n && n){
    cin>>s.real()>>s.imag()>>g.real()>>g.imag();

    rep(i,n){
      P a,b;
      cin>>a.real()>>a.imag()>>b.real()>>b.imag()>>h[i];
      p[i][0] = a;
      p[i][1] = P(a.real(),b.imag());
      p[i][2] = b;
      p[i][3] = P(b.real(),a.imag());
    }
    solve();
  }
}

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

typedef pair<int,string> pis;

int main()
{
  while(1){
    int N, Q;
    cin >> N >> Q;
    if(N == 0 && Q == 0) break;
    map<int,pis> m;
    for(int i = 0; i < N; i++){
      string s;
      int x, y;
      cin >> s >> x >> y;
      m.insert(make_pair(y,pis(x,s)));
    }
    for(int i = 0; i < Q; i++){
      bool flag = true;
      int x;
      cin >> x;
      map<int,pis>::iterator ite;
      for(ite = m.begin(); ite != m.end(); ite++){
        if(x > ite->first - ite->second.first && x <= ite->first){
          flag = false;
          cout << ite->second.second << " " << ite->second.first - ite->first + x << endl;
          break;
        }
      }
      if(flag) cout << "Unknown" << endl;
    }
  }
}

Measured memory_bytes: 1332
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

const double PI = 3.141592653589793238462643383279;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(13);
	long long N; cin >> N;
	int L; cin >> L;
	vector<int> T(N); rep(i, 0, N) {
		cin >> T[i];
	}
	double ansx = 0, ansy = 0;
	long long c = 0;
	rep(i, 0, N)rep(j, i + 1, N) {
		double x = PI * (T[i] + T[j]) / L;
		double y = PI * (T[i] + L + T[j]) / L;
		int c1 = N + i - j - 1;
		int c2 = j - i - 1;
		ansx += cos(x) * c1;
		ansy += sin(x) * c1;
		ansx += cos(y) * c2;
		ansy += sin(y) * c2;
	}
	ansx /= N * (N - 1) * (N - 2) / 3 / 2;
	ansy /= N * (N - 1) * (N - 2) / 3 / 2;
	cout << ansx << " " << ansy << endl;
	return 0;
}


Measured memory_bytes: 384
// author: hjy
// Problem:
#include<bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define rep(i,n) for(register int i=0; i<(int)(n); ++i)
#define per(i,n) for(register int i=(int)(n)-1; i>=0; --i)
#define rep1(i,n) for(register int i=1; i<=(int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<"="<<x<<'\n'
template<typename T1, typename T2>
inline bool umin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; }
template<typename T1, typename T2>
inline bool umax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; }
inline int read() {
	int x=0,ng=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') ng=1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return ng?-x:x;
}
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int seed=20040305;

int n;
int a[100100],b[100100];
int sum[100100];
int tree[800100];
int ans=0;


void update(int k,int l,int r,int pos,ll val)
{
	if(l==r)
	{
		tree[k]+=val;
		return ;
	}
	int m=(l+r)/2;
	if(pos<=m) update(k*2+1,l,m,pos,val);
	else update(k*2+2,m+1,r,pos,val);
	tree[k]=(tree[k*2+1]+tree[k*2+2]);
}

ll query(int k,int l,int r,int a,int b)
{
	if(a<=l&&r<=b)
	{
		return tree[k];
	}
	int m=(l+r)/2;
	ll res=0;
	if(a<=m) res+=query(k*2+1,l,m,a,b);
	if(m<b) res+=query(k*2+2,m+1,r,a,b);
	return res;
}

ll chk(int val)
{
	rep(i,n)
	{
		if(a[i]==val) b[i]=-1;
		else if(a[i]>val) b[i]=1;
		else b[i]=-1;
	}
	memset(sum,0,sizeof(sum));
	memset(tree,0,sizeof(tree));
	sum[0]=b[0];
	for(int i=1;i<n;i++)
		sum[i]=sum[i-1]+b[i];
//	rep(i,n) cout<<sum[i]<<' '; puts("");
	for(int i=0;i<n;i++)
		update(0,0,200000,sum[i]+100000,1);
	ll cnt=0;
	cnt+=query(0,0,200000,0,100000-1);
//	debug(cnt);
	for(int i=0;i<n-1;i++)
	{
		update(0,0,200000,sum[i]+100000,-1);
		cnt+=query(0,0,200000,0,100000+sum[i]-1);
	}
	return cnt;
}

int main()
{
	scanf("%d",&n);
	rep(i,n)
		scanf("%d",&a[i]);
	vector<int> v;
	rep(i,n) v.pb(a[i]);
	sort(all(v));
	int l=0,r=n-1;
	while(l<=r)
	{
		int m=(l+r)/2;
		ll res=chk(v[m]);
//		debug(v[m]);
//		debug(res);
//		debug(n*(n+1)/2/2+1);
		if(res>=(ll)n*(n+1)/2/2+1) 
		{
			ans=v[m];
			r=m-1;
		}
		else 
		{
			l=m+1;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 5112
n = int(raw_input())
a = map(int, raw_input().split())
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
while len(a)>=2:
    k = gcd(a[0],a[1])
    a[1]=k
    del a[0]
print k


Measured memory_bytes: 11296
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[]) {
    int a[3];
    std::cin >> a[0] >> a[1] >> a[2];

    std::sort(a, a + 3, std::greater<int>());
    std::cout << a[0] * 10 + a[1] + a[2] << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };
int c[200006];
vector<int>G[200006];
int dp[200006];
signed main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> c[i];
		G[c[i]].push_back(i);
	}
	dp[0] = 1;
	rep(i, n) {
		dp[i + 1] += dp[i];
		auto itr = upper_bound(G[c[i]].begin(), G[c[i]].end(), i);
		if (itr != G[c[i]].end()&&((*itr)!=i+1)) {
			dp[*itr] += dp[i];
			dp[*itr] %= mod;
		}
		dp[i+1] %= mod;
	}

	cout << dp[n - 1]%mod << endl;
}


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

int main(void) {
	int a, b;
	cin >> a >> b;
	
	if ((a * b) % 2 == 1) {
		cout << "Odd" << endl;
	} else {
		cout << "Even" << endl;
	}
	return 0;
}

Measured memory_bytes: 256