akhauriyash/Code-Regression huggingface dataset:
def acinput():
    return list(map(int, input().split(" ")))



import numpy as np
#from functools import reduce
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
import copy
import functools

N,M=acinput()

if N==M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14136
#include<iostream>
using namespace std;
using ll=long long;

int n,ans=0;

int dfs(ll x,bool f7,bool f5,bool f3){
	if(x>n)return 0;
	if(f7&&f5&&f3)ans++;
	dfs(x*10+7,true,f5,f3);
	dfs(x*10+5,f7,true,f3);
	dfs(x*10+3,f7,f5,true);
	return ans;
}

int main(){
	cin>>n;
	cout<<dfs(0,0,0,0)<<endl;
}

Measured memory_bytes: 256
<?php
[$N, $K] = ints();
$dp[0] = array_merge([0],ints());
for($i = 1; $i <= log($K)/log(2); $i++){
  $dpi = &$dp[$i];
  $dpim = $dp[$i-1];
  for($j = 1; $j <= $N; $j++){
    $dpi[$j] = $dpim[$dpim[$j]];
  }
}
$c = 1;
$i = 0;
while($K >> $i){
  if($K >> $i & 1)$c=$dp[$i][$c];
  $i++;
}
echo $c;

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}

Measured memory_bytes: 398716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var firstLine = Console.ReadLine().Split(' ');
            var N = int.Parse(firstLine[0]);
            var K = int.Parse(firstLine[1]);

            List<int> trees = new List<int>();
            for (int i = 0; i < N; i++)
            {
                trees.Add(int.Parse(Console.ReadLine()));
            }
            trees = trees.OrderBy(x => x).ToList();

            var len = trees.Count;
            int result = int.MaxValue;
            for (int i = 0; i < len-K+1; i++)
            {
                int tmp = 0;
                tmp = trees[ i + K-1 ] - trees[i];
                if (tmp <= result)
                {
                    result = tmp;
                }
            }

            Console.WriteLine(result.ToString());
        }
    }
}


Measured memory_bytes: 20572
S = input()
T = input()

m = 0
for i in range(len(S)-len(T)+1):
    s = S[i:i+len(T)]
    cnt = 0
    for j in range(len(T)):
        if s[j]==T[j]:
            cnt+=1
    if m<cnt:
        m = cnt
print(len(T)-m)

Measured memory_bytes: 73240
#include <iostream>

using namespace std;

int main()
{
  int N, x = 0, y = 0;
  cin >> N;
  string S;
  cin >> S;
  for(int i = 0; i < N; i++){
    if(S.at(i) == 'I'){
      x++;
    }else{
      x--;
    }
    if(y < x){
      y = x;
    }
  }
  cout << y;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int total_holiday = sc.nextInt();
        int total_homework = sc.nextInt();
        int total = 0;
        
        for(int i = 0;i < total_homework;i++){
            total += sc.nextInt();
        }
        if(total_holiday >= total){
            System.out.println(total_holiday-total);
        }else{
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 46228
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

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

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl

int32_t main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int a; string s; cin >> a >> s;
    if(a < 3200)
        cout << "red";
    else
        cout << s;
    
   
    
    return 0;
}


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

int main() {
	ll N;
	map<ll,ll> m;
	cin >> N;

	rep(i,200)
		rep(j,200-i)
			rep(k,200-i-j) {
				ll x = (i+1)*(i+1)+(j+1)*(j+1)+(k+1)*(k+1)+(i+1)*(j+1)+(j+1)*(k+1)+(k+1)*(i+1);
				if(m.count(x))
					++m.at(x);
				else
					m[x] = 1;
			}

	rep(i,N) {
		if(m.count(i+1))
			cout << m.at(i+1);
		else
			cout << 0;
		cout << endl;
	}
}

Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;

struct Node{
    int key;
    Node *parent,*left,*right;
};

Node *root,*NIL;  //メモ：初期アドレスは0

void insert(int k){
    Node *x = root;
    Node *y = NIL;
    Node *z;

    z = (Node *)malloc(sizeof(Node)); //メモ：メモリを確保するとアドレスが与えられる
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){  //メモ：xにアドレスが与えられているかどうか、すなわち、二分木が空かどうか、または、挿入前の節にたどり着いたかどうか。
        y=x;
        if(z->key < x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    z->parent = y;
    if(y == NIL)
        root = z;
    else if(z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL)return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}
    
Node * find(Node *u,int k){
    while(u != NIL && u->key != k){
        if(k < u->key){
            u=u->left;
        }
        else{
            u=u->right;
        }
    }
    return u;
}




int main() 
{
    int n;
    string com;
    cin >> n;
    rep(i,n){
      	cin >> com;
        if(com == "insert"){
            int x;
            cin >> x;
            insert(x);
        }
        else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        if(com[0] == 'f'){
            int y;
            cin >> y;
            if(find(root,y) != NIL)cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 21804
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)




const int mod = 1000000007;
const int INF = (1LL << 62) - 1;

#define MAXN 300005

#define N 300005
int fac[N],invfac[N];


int modexp(int x, int y)
{
    int res = 1;
    x = (x % mod + mod) % mod;
    while(y)
    {
        if(y & 1)
            res = (res*x) % mod;
        y >>= 1;
        x = (x*x) % mod;
    }
    return res%mod; 
}

int modinv(int x)
{
  return modexp(x,mod-2)%mod;
}



void precompute()
{
  fac[0] = 1;
  for(int i = 1; i < N; i++)
  {
    fac[i] = (fac[i-1]%mod)*(i%mod);
    fac[i] %= mod;
  }

  for(int i = 0; i < N; i++)
  {
    invfac[i] = modinv(fac[i])%mod;
  }


}


int ways(int a,int b)
{
  int ans = fac[a+b]%mod;
  ans *= invfac[a]%mod;
  ans %=mod;
  ans *= invfac[b]%mod;
  ans %= mod;
  return ans;
}


bool customsort(const pair<int,int> &a,const pair<int,int> &b)
{
  return a.first + a.second < b.first + b.second;
}



int32_t main()
{


    IOS


    precompute();

    int h,w,n;
    cin >> h >> w >> n;

    vector<pair<int,int>> v;

    for(int i = 0; i < n; i++)
    {
      int x,y;
      cin >> x >> y;
      v.push_back(make_pair(x,y));
    }


    sort(all(v),customsort);
    v.push_back(make_pair(h,w));

    vector<int> dp(n+1);
    dp[0] = ways(v[0].first-1,v[0].second-1);

    int x = dp[0];

    for(int i = 1; i <= n; i++)
    {
      int ans = ways(v[i].first-1,v[i].second-1);

      for(int j = 0; j < i; j++)
      {
        if(v[j].first <= v[i].first and v[j].second <= v[i].second)
        {
        ans -= (dp[j]*ways(v[i].first-v[j].first,v[i].second-v[j].second))%mod;
        ans += mod;
        ans %=mod;
        }
      }

      dp[i] = ans%mod;

    }


    cout << dp[n];





    
    return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int> > a(26);
    rep (i, 26) a[i].insert(Inf);
    rep (i, s.size()) a[s[i] - 'a'].insert(i);

    rep (_, q) {
        int x;
        cin >> x;
        if (x == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            a[s[i] - 'a'].erase(i);
            s[i] = c;
            a[c - 'a'].insert(i);
        } else {
            int l, r;
            cin >> l >> r;
            l--, r--;
            int res = 0;
            rep (i, 26) {
                auto iter = a[i].lower_bound(l);
                if (*iter <= r) res++;
            }
            cout << res << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 24220
#include<bits/stdc++.h>
#define N 100010
#define ll long long
using namespace std;
int n;
ll A[N];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i)
		scanf("%lld", &A[i]);
	sort(A + 1, A + n + 1);
	if(n & 1)
	{
		ll ans1 = 0, ans2 = 0;
		for(int i = 1; i <= n / 2 - 1; ++ i)
			ans1 -= 2 * A[i];
		ans1 -= A[n / 2] + A[n / 2 + 1];
		for(int i = n / 2 + 2; i <= n; ++ i)
			ans1 += 2 * A[i];
		
			
		for(int i = 1; i <= n / 2; ++ i)
			ans2 -= 2 * A[i];
		for(int i = n / 2 + 3; i <= n; ++ i)
			ans2 += 2 * A[i];
		ans2 += A[n / 2 + 1] + A[n / 2 + 2];
		printf("%lld", max(ans1, ans2));
	}
	else
	{
		ll ans = 0;
		for(int i = 1; i <= n / 2 - 1; ++ i)
			ans -= 2 * A[i];
		ans -= A[n / 2];
		for(int i = n / 2 + 2; i <= n; ++ i)
			ans += 2 * A[i];
		ans += A[n / 2 + 1];
		printf("%lld", ans);
	}
	return 0;
}

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

int main() {
  string sa, sb, sc;
  cin>>sa>>sb>>sc;

  string s[3] = {sa, sb, sc};
  int i[3] = {0, 0, 0};
  size_t l[3] = {sa.length(), sb.length(), sc.length() };

  int cur = 0;
  while (true) {
    if (i[cur] == l[cur]) {
      cout<<(char)(cur + 'A')<<endl;
      break;
    }
    int next = s[cur][i[cur]] -'a';
    ++i[cur];
    cur = next;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
  long double A, B, H, M, radH, radM, ans;
  cin >> A >> B >> H >> M;
  radH = (2 * M_PI * H / 12)+(2 * M_PI * M / (60*12));
  radM = 2 * M_PI * M / 60;
  ans = sqrt(A * A + B * B - 2 * A * B * cos(abs(radH - radM)));
  printf("%.10Lf\n", ans);
}

Measured memory_bytes: 4168
N,K = map(int,input().split())
Mod = [0 for i in range(K)]
for a in range(1,N+1):
    Mod[a%K] += 1
if K%2 == 1:
    Answer = Mod[0]**3
else:
    Answer = Mod[K//2]**3 + Mod[0]**3
print(Answer)

Measured memory_bytes: 10352
N = int(input())
A = list(map(int, input().split()))
list.sort(A, reverse=True)
ans = A[0]
if N % 2 == 0:
    for i in range(1, N // 2):
        ans += A[i] * 2
if N % 2 == 1:
    for i in range(1, N // 2):
        ans += A[i] * 2
    ans += A[N // 2]
print(ans)


Measured memory_bytes: 31620
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
const ll mod = 1000000007;
const ll nmax=1000003;
#define int ll
int n, k, a[2002], ans1, ans2, cnt[2002];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    for(int i=1; i<=n; i++){
		cin>>a[i];
		for(int j=1; j<i; j++) cnt[i]+=(a[i]<a[j]);
	}
	for(int i=1; i<=n; i++) ans1+=cnt[i];
	for(int i=1; i<=n; i++){
		for(int j=i+1; j<=n; j++) cnt[i]+=(a[i]<a[j]);
	}

	for(int i=1; i<=n; i++) ans2+=cnt[i];
	//cout<<ans1<<" "<<ans2<<endl;
	ans1*=k; ans1%=mod;
	ans2*=((k-1)*k/2)%mod; ans2%=mod;
	cout<<(ans1+ans2)%mod;
}


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

int main() {
  int tc; scanf("%d", &tc);
  for(int tci = 0; tci < tc; tci++) {
    int gx,gy,p; scanf("%d%d%d", &gx, &gy, &p);
    static int tbl[20][20];
    fill(&tbl[0][0], &tbl[20][20], 0);
    for(int i = 0; i < p; i++) {
      int x1,y1,x2,y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      if(x1==x2) {
        tbl[x1][min(y1,y2)] |= 1;
      } else {
        tbl[min(x1,x2)][y1] |= 2;
      }
    }
    static int dp[20][20];
    fill(&dp[0][0], &dp[20][20], 0);
    dp[0][0] = 1;
    for(int x = 0; x <= gx; x++) {
      for(int y = 0; y <= gy; y++) {
        if(!(tbl[x][y]&1)) {
          dp[x][y+1] += dp[x][y];
        }
        if(!(tbl[x][y]&2)) {
          dp[x+1][y] += dp[x][y];
        }
      }
    }
    if(dp[gx][gy] == 0) {
      printf("Miserable Hokusai!\n");
    } else {
      printf("%d\n", dp[gx][gy]);
    }
  }
  return 0;
}

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

a.sort(reverse=True)

score=0
index=1
count=0
for i in range(len(a)):
  if i==0:
    score+=0
  elif i==1:
    score+=a[0]
  else:
    score+=a[index]
    count+=1
    if count==2:
      index+=1
      count=0
print(score)

Measured memory_bytes: 31444
/*-----------Author: Araz Jabrayilov---------*/
/*------------@araz17----(~~)#5371-----------*/

#include <bits/stdc++.h>

#define ll long long
#define endl '\n'

using namespace std;



int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    int n = 0;

    for (n = 0; n < 10000; ++n) {
      int a2 = n * 8 / 100;
      int b2 = n * 10 / 100;

      if (a == a2 && b == b2) {
        cout << n << endl;
        return 0;
      }
    }
    cout << -1 << endl;


    return 0;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
	string s;

	cin >> s;

	if(s=="SUN")
		cout << 7 << endl;
	else if(s=="MON")		
		cout << 6 << endl;
	else if(s=="TUE")
		cout << 5 << endl;
	else if(s=="WED")
		cout << 4 << endl;
	else if(s=="THU")
		cout << 3 << endl;
	else if(s=="FRI")
		cout << 2 << endl;
	else if(s=="SAT")
		cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 256
/*
Pollocks conjecture
https://onlinejudge.u-aizu.ac.jp/problems/1167
*/

#include <iostream>
#include <vector>
using namespace std;

const int MAX = 1000100;
const int INF = 1<<29;

int main() {
    vector<int> dp_all(MAX, INF), dp_odd(MAX, INF);
    dp_all[0] = dp_odd[0] = 0;
    for (int i = 1;; ++i) {
        int num = i * (i+1) * (i+2) / 6;
        if (num >= MAX) break;
        for (int j = num; j < MAX; ++j) {
            dp_all[j] = min(dp_all[j], dp_all[j-num]+1);
            if (num & 1) dp_odd[j] = min(dp_odd[j], dp_odd[j-num]+1);
        }
    }

    //for(int i=0; i<MAX; i++) cout << dp_all[i] << " " << dp_odd[i] << endl;
    int n;
    while (cin >> n, n!=0) {
        cout << dp_all[n] << " " << dp_odd[n] << endl;
    }
}


Measured memory_bytes: 10500
#include <stdio.h>
#include <stdlib.h>

typedef struct node {
  int name;
  int parent;
  int child;
  int brother;
} node_t;

node_t tree[100003];

int main()
{
  int n,i,child_number,j,child,depth,parent,heap;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    tree[i].name = -1;
    tree[i].parent = -1;
    tree[i].child = -1;
    tree[i].brother = -1;
  }

  for(i = 0;i < n;i++){
    scanf("%d",&heap);
    tree[heap].name = heap;
    scanf("%d",&child_number);
   /* ある変数に一個上の兄の情報を更新する  */
   /* 一個上の兄の変数 */
    for(j = 0;j < child_number;j++){
      if(j == 0){
	scanf("%d",&tree[heap].child);
	tree[tree[heap].child].parent = tree[heap].name; /* 親情報を入力 */
	child = tree[heap].child; /* 一個上の兄を更新 */
      }
      else{
	scanf("%d",&tree[child].brother);
	tree[tree[child].brother].parent = tree[heap].name; /* 親情報を入力 */
	child = tree[child].brother; /* 一個上の兄を更新 */
      }
    }
  }

  /* 出力 */
  for(i = 0;i < n;i++){
    depth = 0;
    parent = tree[i].parent;
    while(parent != -1){
      depth++;
      parent = tree[parent].parent;
    }
    printf("node %d: parent = %d, depth = %d, ",tree[i].name,tree[i].parent,depth);
    if(tree[i].parent == -1) printf("root, ");
    else if(tree[i].child == -1) printf("leaf, ");
    else printf("internal node, ");
    printf("[");
    child = tree[i].child;
    while(child != -1){
      printf("%d",child);
      child = tree[child].brother;
      if(child != -1) printf(", ");
    }
    printf("]\n");
  }

  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int K, N;
  cin >> K >> N;
  int house[200010];
  int ans = 0;
   for(int i = 0; i < N; i++){
    cin >> house[i];
  }
  for(int i = 0; i < N-1; i++){
    ans = max(house[i+1] - house[i], ans);
  }
  ans = max(K - house[N-1] + house[0], ans);
  
  cout << K-ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){


    int n;
    cin>> n;
    int a[n];
    for (int i=0 ;i<n;i++)cin>> a[i];
    int min = 1234343,idx=0;

    for(int i =1;i<=100;i++){
            int sum=0;
            for(int j=0;j<n;j++){
            int x = (a[j]-i)*(a[j]-i);
            sum+=x;
            //cout<<a[j]-i<<" ";

            //idx++;
            }
              if(min>sum){
                    min =sum;
                //sum=0;

            }

    }
    cout<<min;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
int main(void){
    int n,k;
    cin>>n>>k;
    int sum=1;
    rep(i,n){
    if(i==0) sum*=k;
    else sum*=k-1;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

void process() {
    int H, W;

    do {
        scanf(" %d %d", &H, &W);
        if( H == 0 && W == 0 ) return;

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if( (i+j)%2 == 0 ) putchar('#');
                else putchar('.');
            }
            putchar('\n');
        }
        putchar('\n');

    } while( true );
}

int main() {
    process();
    return 0;
}


Measured memory_bytes: 2600
#!/usr/bin/env python3
import sys, math, fractions, itertools

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def find_root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if(x == y):
            return 
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def is_same_group(self, x, y):
        return self.find_root(x) == self.find_root(y)

    def size(self, x):
        return -self.root[self.find_root(x)]


def solve(N: int, M: int, p: "List[int]", x: "List[int]", y: "List[int]"):
    uf = UnionFind(N)
    for i in range(M):
        uf.unite(x[i]-1, y[i]-1)
    counter = 0
    for i in range(N):
        if uf.is_same_group(i, p[i]-1):
            counter += 1
    print(counter)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]" 
    y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, M, p, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20096
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    unordered_map<ll, ll> mp;
    ll ans = 0;
    rep(_,N){
        ll a;
        cin >> a;
        mp[a]++;
        mp[a - 1]++;
        mp[a + 1]++;
        ans = max({ans, mp[a], mp[a - 1], mp[a + 1]});
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 4260
/*
the top of the losers
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    Lcm(a,b)  ((a*b)/(__gcd(a,b)))
#define    X            real()
#define    Y            imag()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
#define     point        complex<double>
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    PI  acos(-1)
typedef  long long     ll ;
typedef  unsigned long long     ull ;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=100000+9;
const ll inf=1e16;
int a[N],b[N],c[N];
ll dist[N];
vector<pair<int,int> > v[N];
multiset<ll> st;
int main(){
    GO();
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        v[a[i]].pb(mp(0,i));
        v[b[i]].pb(mp(1,i));
    }

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

        for(int j=0;j<sz(v[i-1]);j++){
            int sat=v[i-1][j].first;
            int id=v[i-1][j].second;

            if(sat==0){
                st.insert(dist[a[id]]+c[id]);
            }
            else if(sat==1){
                st.erase(st.find(dist[a[id]]+c[id]));
            }
        }
        if(sz(st)==0){
            cout<<"-1\n";
            return 0;
        }
        dist[i]=(*st.begin());
        if(i==n){
            cout<<dist[i]<<endl;
            return 0;
        }

    }

}

















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

using namespace std;

int main() {
  int min_t= 100000;
  int min_c = 100000;
  int N, T;
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    int ci, ti;
    cin >> ci >> ti;
    if (ti <= T && ci < min_c) {
      min_t = ti;
      min_c = ci;
    }
  }
  if (min_c == 100000) {
    cout << "TLE" << endl;
  } else {
    cout << min_c << endl;
  }
  return 0;
}

Measured memory_bytes: 256
alist = list(map(int,input().split()))

alist.sort()
if alist[0] == alist[1] and not alist[1] == alist[2]:
    print('Yes')
elif alist[1] == alist[2] and not alist[0] == alist[1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int W, H, N;
    cin >> W >> H >> N;
    vector<int> x(N), y(N), a(N);
    REP(i, N) cin >> x[i] >> y[i] >> a[i];

    int w = 0, h = 0;
    REP(i, N) {
        if (a[i] == 1)
            chmax(w, x[i]);
        if (a[i] == 2)
            chmin(W, x[i]);
        if (a[i] == 3)
            chmax(h, y[i]);
        if (a[i] == 4)
            chmin(H, y[i]);
    }
    if (W - w < 0 || H - h < 0) {
        std::cout << 0 << '\n';
        return 0;
    }

    int ans = (W - w) * (H - h);
    if (0 < ans)
        std::cout << ans << '\n';
    else
        std::cout << 0 << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif // INPUT_FROM_FILE
	int n = 0;
	int m = 0;
	std::vector<std::vector<int> > mat_A;
	std::vector<int> vec_b;

#if INPUT_FROM_FILE
	ifs >> n >> m;
#else
	std::cin >> n >> m;
#endif // INPUT_FROM_FILE

	mat_A.resize(n);
	for(int i = 0; i < n; i++){
		mat_A[i].resize(m, 0);
	}
	vec_b.resize(m, 0);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
#if INPUT_FROM_FILE
			ifs >> mat_A[i][j];
#else
			std::cin >> mat_A[i][j];
#endif // INPUT_FROM_FILE
		}
	}
	for(int i = 0; i < m; i++){
#if INPUT_FROM_FILE
		ifs >> vec_b[i];
#else
		std::cin >> vec_b[i];
#endif // INPUT_FROM_FILE
	}

	for(int i = 0; i < n; i++){
		int result = 0;
		for(int j = 0; j < m; j++){
			result += mat_A[i][j] * vec_b[j];
		}
		std::cout << result << std::endl;
	}

	return 0;
}

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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N;
    cin >> N;
    int nums[N];
    for(int i = 0; i < N; i++){
        cin >> nums[i];
    }
    int ans = 0;
    for(int i = 0; i < N - 1; i++){
        if(nums[i] == i + 1){
            ans++;
            swap(nums[i], nums[i + 1]);
        }
    }
    cout << ans + (nums[N - 1] == N) << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    int MAX_L = *max_element(L.begin(),L.end());
    int SUM_L = 0;
    rep(i,N) SUM_L += L[i];
    if ( SUM_L > MAX_L * 2){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a[4],b[4];
	int i,j;
	int hit = 0,blow = 0;
	while(scanf("%d %d %d %d\n%d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) != EOF){
		hit = 0;
		blow = 0;
		
		for(i = 0;i < 4;i++){
			if(a[i] == b[i]){
				hit++;
			}else{
				for(j = 0;j < 4;j++){
					if(a[i] == b[j])blow++;
				}
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

Measured memory_bytes: 596
/*****************************************************
 				*	Logged in : HABIBUR RAHMAN						 *
				*	Dept	  : COMPUTER SCIENCE AND ENGINEERING	 *
				*													 *
				*	KHULNA UNIVERSITY OF ENGINEERING AND TECHNOLOGY  *
				******************************************************/


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<string> vs;
typedef pair<ll,ll> pll;
#define fast_io 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) 				v.begin(),v.end()
#define allr(v) 			v.rbegin(),v.rend()
#define rep(i,a,b) 			for(ll i=a;i<=b;i++)
#define rep0(i,n)			for(ll i=0;i<n;i++)
#define rrep0(i, n) 		for(ll i=(ll)(n);i>0;--i)
#define rrep(i, a, b) 		for(ll i=(ll)(a);i>=(ll)(b);--i)
#define pb(z) 				push_back(z)
#define ff					/first
#define ss 					second
#define caset 				int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define sz(X) 				((ll)(X).size())
#define scan(X) 			scanf("%s", (X))
#define ms(v,val)			memset((v),(val),sizeof((v)))
#define ms0(X) 				memset((X), 0, sizeof((X)))
#define ms1(X) 				memset((X), -1, sizeof((X)))
#define m_p(a,b)            make_pair(a,b)
#define get_pos(c,x) 		(lower_bound(c.begin(),c.end(),x)-c.begin())
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define INF9                1000000010
#define INF18               4000000000000000010
#define bpll(a)             __builtin_popcountll(a)
#define sqr(a)              ((a)*(a))
#define nl					"\n"
//#define mod					1e9+7;
#define mx_el(v)			*max_element(all(v));
#define mn_el(v)			*min_element(all(v));
#define pcase(z,x)    		cout<<"Case "<<z<<": "<<x<<"\n"
const double pi = 2*acos(0) ;
#define display(v)			vi :: iterator it;for(it=(v).begin();it!=(v).end();it++){cout << *it << " " ;}cout << endl;
#define taking(n,v) 		for(ll i=0;i<(n);i++){ll inp;cin>>inp;(v).push_back(inp);}

void start(){
      #ifndef ONLINE_JUDGE 
      freopen("input.txt" , "r" , stdin) ;
      freopen("output.txt" , "w" , stdout) ;
      #endif
}

void solve()
{
 	 ll n;cin>>n;
 	 vector<ll>v,l(n+4),r(n+5);
 	 rep0(i,n){
 	 	ll inp;cin>>inp;
 	 	v.pb(inp);
	  }
	  ll g=0;
	  rep0(i,n){
	  	g=__gcd(g,v[i]);
	  	l[i]=g;
	  }
	  g=0;
	  for(ll i=n-1;i>=0;i--){
	  	g=__gcd(g,v[i]);
	  	r[i]=g;
	  }
	  ll ans = 1;
      rep0(i,n) {
        if(i == 0) {
            ans = max(ans, r[1]);
            continue;
        }
        if(i == n-1) {
            ans = max(ans, l[n-2]);
            continue;
        }
         ans = max(ans, __gcd(l[i-1], r[i+1]));
    	}
    	cout << ans << nl;
}

int main() {
	fast_io
	//start();
    //caset{
    	//cout << "Case " << tt << ": ";

		  solve();
	//}
	
	return 0;
}


Measured memory_bytes: 5720
#!/usr/bin/perl -w

chomp($line=<>);
($n,$h,$w)=split(/ /,$line);
$cnt=0;
for($i=0;$i<$n;$i++){
    chomp($hoge=<>);
    ($a,$b)=split(/ /,$hoge);
    while($h <= $a && $w <= $b){
        $a=$a-$h;
        $b=$b-$w;
        $cnt++;
    }
}
print $cnt;

Measured memory_bytes: 512
while True:
    record = str(input())
    if record == "0":
        break
    A = 0
    B = 0
    for i in range(1, len(record)):
        if record[i] == "A":
            A += 1
        else:
            B += 1
    if A > B:
        A += 1
    else:
        B += 1
    print(A,B)


Measured memory_bytes: 5552
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
int a,b,c;
  cin >> a >> b >>c;
  if (a <= c && c <=b) cout << "Yes" <<endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> a(n);
    rep(i,n){
        cin >>x[i];
        a[i]=x[i];
    }
    sort(x.begin(),x.end());
    int right = n/2;
    int left = n/2-1;
    rep(i,n){
        if(a[i]<=x[left]){
            cout << x[right]<<endl;
        }
        else{
            cout<<x[left]<<endl;
        }
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll n;
vector<pair<ll,ll>>po(100);
double ans=0;
void dfs(int depth,vi pa,ll bi){
  if(depth == n){
    double sum=0;
    for(int i=0;i<n-1;i++){
      sum+=sqrt((po[pa[i]].F-po[pa[i+1]].F)*(po[pa[i]].F-po[pa[i+1]].F)+(po[pa[i]].S-po[pa[i+1]].S)*(po[pa[i]].S-po[pa[i+1]].S));
    }
    ans+=sum;
    return;
  }
  for(int i=0;i<n;i++){
    if(bi&BITLE(i)){
    }else{
      pa.pb(i);
      dfs(depth+1,pa,bi|BITLE(i));
      pa.pop_back();
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>po[i].F>>po[i].S;
  }
  vi hoge;
  dfs(0,hoge,0);
  ll wa=1;
  for(ll i=1;i<=n;i++)wa*=i;
  printf("%.10f\n",ans/(double)wa);
  return 0;
}


Measured memory_bytes: 384
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back

#define eb emplace_back
#define mod   1000000007
#define PI 2*acos(0.0)
#define all(r)(r).begin(),(r).end()
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
#define inf 1000000000000000000
#define N 500000
int dirx[] = {1, -1,0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};



//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    int n;
    cin>>n;
    ll ans = 0;
    n--;
    for(double i = 1; i<= n; i++)
        ans += floor(n/i);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3648
d, n = map(int, input().split())
add = 100 ** d
cnt = 0
ans = 0

while True:
    ans += add
    if d == 0:
        if ans % 100 != 0:
            cnt += 1
    else:
        if ans != 0 and ans % (100 ** d) == 0 and ans % (100 ** (d + 1)) != 0:
            cnt += 1
    if cnt == n:
        break
print(ans)


Measured memory_bytes: 38736
import math

n,k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
f = list(map(int, input().strip().split()))
a.sort()
f.sort()
#f = f[::-1]
af = [[] for i in range(n)]
r = 0
for i in range(n):
	af[i] = [a[n-1-i]*f[i], f[i]]
	r = max(r, af[i][0])
af.sort()
af = af[::-1]

#r = af[0][0]
l = 0
while l < r:
	c = (l+r)//2
	training = 0
	for e in af:
		if c >= e[0] or k < training:
			break
		training += (e[0]-c + e[1]-1) // e[1]
	if training <= k:
		r = c
	else:
		l = c+1
print(l)


Measured memory_bytes: 130636
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
#define maxn 100005
using namespace std;
ll sum[maxn];
int n;
struct node
{
    int id;
    ll val;
}a[maxn];
bool cmp(node a,node b)
{
    if(a.val==b.val)
return a.id<b.id;
return a.val>b.val;
}
int main()
{

    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        {scanf("%lld",&a[i].val);
        a[i].id=i;
        }
    sort(a+1,a+n+1,cmp);
    int pos=a[1].id;
   ll num=1;
    a[n+1].val=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i+1].val==a[i].val)
            num++;
            else
            {
              sum[pos]+=(a[i].val-a[i+1].val)*num;
              num++;
             if(a[i+1].id<pos)
                pos=a[i+1].id;
            }

    }
    for(int i=1;i<=n;i++)
        printf("%lld\n",sum[i]);
    return 0;


}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, W; cin >> n >> W;
    vector <pair <int, int> > obj;
    for (int i = 0; i < n; ++ i) {
        int w, v; cin >> w >> v;
        obj.emplace_back(w, v);
    }
    vector <vector <vector <int> > > dp(n + 1, vector <vector <int> > (n + 1, vector <int> (3 * n + 1, -0x3f3f3f3f)));
    dp[0][0][0] = 0;
    auto chkmax = [&] (int & x, int y) {x = y > x ? y : x;};
    for (int i = 0; i < n; ++ i) {
        int w = obj[i].first, v = obj[i].second;
        for (int j = 0; j <= n; ++ j) {
            for (int k = 0; k <= 3 * n; ++ k) {
                if (j < n) chkmax(dp[i + 1][j + 1][k + w - obj[0].first], dp[i][j][k] + v);
                chkmax(dp[i + 1][j][k], dp[i][j][k]);
            }
        }
    }
    int ans = -0x3f3f3f3f;
    for (int i = 0; i <= n; ++ i) {
        for (int j = 0; j <= 3 * n; ++ j) {
            if (1LL * i * obj[0].first + j <= W) {
                chkmax(ans, dp[n][i][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

bool check(string s, string t, int end, int num) {
    string u = "";
    for(int i = s.size() - end - num; i < s.size() - end; i++) {
        u += s[i];
    }
    if(t == u) return true;
    return false;
}

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

    int end = 0;
    while(s.size() > t.size()) {
        if(check(s, "dreamer", end, 7)) {
            t = "dreamer" + t;
            end += 7;
        } else if(check(s, "eraser", end, 6)){
            t = "eraser" + t;
            end += 6;
        } else if(check(s, "dream", end, 5)) {
            t = "dream" + t;
            end += 5;
        } else if(check(s, "erase", end, 5)) {
            t = "erase" + t;
            end += 5;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}




Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define pie 3.141592653589793
#define si(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define sl(a) scanf("%lld",&a)
#define pi(a) printf("%d",a)
#define pl(a) printf("%lld",a)
#define ps(a) printf("%s",a)
#define ll long long
using namespace std;
int main()
{
  char a,b;
  cin >> a >> b;
  if(a>b)
    cout << ">" << endl;
  else if(a==b)
    cout << "=" << endl;
  else
    cout << "<" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    int a,ans = 0;
    cin >> a;
    for(int i = 1; i < n; i++){
        int aa; cin >> aa;
        if(aa == a){
            ans++;
            a = INF;
        }else a = aa;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tc ll t;cin>>t;while(t--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007

int main()
{
  io;
  ll k,n;
  cin>>k>>n;
  cinv(a,n);
  vll d(n);
  FOR(i,0,n-1)
  {
  	d[i]=a[i+1]-a[i];
  }
  d[n-1]=k-a[n-1]+a[0];
  sort(all(d));
  cout<<k-d[n-1];
  return 0;
}

Measured memory_bytes: 3328
getMinMax :: [Int] -> (Int,Int)
getMinMax (x:xs) = foldl judg (x,x) xs
  where judg :: (Int,Int) -> Int -> (Int,Int)
        judg (min,max) x
          | x < min = (x,max)
          | max < x = (min,x)
          | otherwise = (min,max)

main = do
  line <- getLine
  let
    dat = map read $ words line :: [Int]
    (min,max) = getMinMax dat
  putStrLn $ show min ++ " " ++ show max


Measured memory_bytes: 3664