akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "T" : "F");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

int const N = 200100;
int n, q;
vector<int> tree[N];
int f[N], ans[N];

void dfs(int x=1, int par=0, int z=0){
  z += f[x];
  ans[x] = z;
  for(int v: tree[x]) {
    if( v == par ) continue;
    dfs(v, x, z);
  }
}

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

  cin >> n >> q;
  for(int i=2; i<=n; i++) {
    int a, b; cin >> a >> b;
    tree[a].emplace_back(b);
    tree[b].emplace_back(a);
  }

  while(q--) {
    int p, x; cin >> p >> x;
    f[p]+=x;
  }

  dfs();
  for(int i=1; i<=n; i++) cout << ans[i] << " \n"[i==n];
}


Measured memory_bytes: 24064
#include <iostream>
#include <string>
#define foor for(int i=0;i<n;i++)
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define ic int a;cin>>a;
#define ic2 ic int b;cin>>b;
#define ic3 ic2 int c;cin>>c;
int s = 0;
using namespace std;
int main() {
	ic3 if (a + b + c > 21)cout << "bust" << endl;
	else cout << "win" << endl;
}

Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
xyh = sorted([list(map(int, input().split())) for i in range(n)], key = itemgetter(2),reverse=True)
X,Y,H = xyh[0][0],xyh[0][1],xyh[0][2]
if n == 1:
  print(X,Y,H)
  exit()
for cx in range(101):
  for cy in range(101):
    height = abs(cx-X) + abs(cy-Y) + H
    for x,y,h in xyh[1:]:
      if h != max(0, height - abs(cx-x) - abs(cy-y)):
        break
    else:
      print(cx,cy,height)
      exit()

Measured memory_bytes: 3064
n = int(input())
sum_ = 0

for i in range(1, n+1):
    if i % 3 == 0 and i % 5 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        sum_ += i
        
print(sum_)

Measured memory_bytes: 65276
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Obj[] array = new Obj[m];
		for (int i = 0; i < m; i++) {
			Obj o = new Obj();
			o.a = sc.nextInt();
			o.b = sc.nextInt();
			array[i] = o;
		}
		sc.close();

		Arrays.sort(array, new Comparator<Obj>() {
			public int compare(Obj o1, Obj o2) {
				return o1.b - o2.b;
			}
		});

		int ans = 1;
		int br = array[0].b;
		for (int i = 1; i < m; i++) {
			if (array[i].a >= br) {
				ans++;
				br = array[i].b;
			}
		}
		System.out.println(ans);
	}

	static class Obj {
		int a, b;
	}
}


Measured memory_bytes: 89412
package main

import (
	"fmt"
)

const MAX_DIGIT = 11

var lunluns [][]int

func lastDidit(num int) int {
	return num % 10
}

func makeLunluns(digit int) {
	for _, e := range lunluns[digit-1] {
		last := lastDidit(e)
		switch last {
		case 0:
			lunluns[digit] = append(lunluns[digit], e*10+(last))
			lunluns[digit] = append(lunluns[digit], e*10+(last+1))
		case 9:
			lunluns[digit] = append(lunluns[digit], e*10+(last-1))
			lunluns[digit] = append(lunluns[digit], e*10+(last))
		default:
			lunluns[digit] = append(lunluns[digit], e*10+(last-1))
			lunluns[digit] = append(lunluns[digit], e*10+(last))
			lunluns[digit] = append(lunluns[digit], e*10+(last+1))
		}

	}
}

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

	lunluns = make([][]int, MAX_DIGIT)
	lunluns[1] = make([]int, 9)
	for i := range lunluns[1] {
		lunluns[1][i] = i + 1
	}

	for i := 2; i < MAX_DIGIT; i++ {
		makeLunluns(i)
	}

	for _, lunlun := range lunluns {
		if k < len(lunlun) {
			fmt.Println(lunlun[k-1])
			break
		}
		k -= len(lunlun)
	}
}


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

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

Measured memory_bytes: 128
main(I,O,J,L,d){
	scanf("%d%d%*d%d%d",&I,&O,&J,&L);
	printf("%lld",(long long)O+I+J+L-(I&&J&&L?(d=I%2+J%2+L%2)>1?3-d:d:I%2+J%2+L%2));
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();    
        int N = r.i();
        int[] a = r.ii();
        int max = a[0];
        int min = a[0];
        for(int b : a)
            if(max < b)
                max = b;
            else if(b < min)
                min = b;
        println(max-min);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 22996
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int main() {        
  long N, K;        
  cin >> N >> K;
  N %= K;
  cout << min(abs(N-K), abs(abs(N-K) -K)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = int64_t;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10,9)+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
 //cout << setprecision(15) << std::fixed;

vecll c,p;

ll ret_p(ll n, ll x) {
    if (x == c[n]) return p[n];
    
    ll ans = 0;
    x--;
    
    if (x > 0) {
        ll l = min(x, c[n - 1]);
        ans += ret_p(n - 1, l);
        x -= l;
    }
    
    if (x > 0) {
        ans++;
        x--;
    }
    
    if (x > 0) {
        ll l = min(x, c[n - 1]);
        ans += ret_p(n - 1, l);
        x -= l;
    }
    return ans;
}

int main() {
    ll N, X;
    cin >> N >> X;
    c.resize(N + 1);
    p.resize(N + 1);
    c[0] = p[0] = 1;
    for (int i = 1; i <= N; i++) {
        c[i] = c[i - 1] * 2 + 3;
        p[i] = p[i - 1] * 2 + 1;
    }
    print(ret_p(N, X));
}



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

int main () {
    int ans = 0;
    int n, k;
    cin >> n >> k;
    while (n > 0) {
        ans ++ ;
        n /= k;
    }
    cout << ans << endl;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;

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

 vector<int> l(n);
 REP(i,n)cin>>l[i];
 ll res=0;
sort(ALL(l));
reverse(ALL(l));

 
REP(i,n-2){
  int a,b,c;
    a=l[i];
    FOR(j,i+1,n-1){ 
      b=l[j];
      int k=j+1;
      c=l[k];
      while(k<n){
        c=l[k];
        k++;
        if(a-b<c)res++;
        else break;
        //cout<<a<<' '<<b<<' '<<c<<endl;
      }
  }
}

 cout<<res<<endl;
}

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

using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int N,A,B,C,X;
int Y[200];

int solve(){
    int r = X;
    int reel=0;
    for(int i=0; i<=10000; i++,r=(r*A+B)%C){
        if(r==Y[reel]){
            reel++;
        }
        if(reel==N){
            return i;
        }
    }
    return -1;
}

int main(){
    while(cin>>N>>A>>B>>C>>X && C){
        rep(i,N)cin>>Y[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 1160
from collections import defaultdict
dic = defaultdict(int)
n,x,y = map(int,input().split())
for i in range(1,n+1):
    for j in range(i,n+1):
        val = min(abs(i-j), abs(x-i) + abs(y-j) + 1)
        dic[val] += 1
for i in range(1,n):
    print(dic[i])

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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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

ll cnt[200000],n;


void init() {
    for(ll x = 1; x <= 200; x++ ) {
        for(ll y = 1; y <= 200; y++ ) {
            for(ll z = 1; z <= 200; z++ ) {
               ll tmp = x * x + y * y + z * z + x * y + y * z + z * x;
               if (tmp < 200000) {
                   cnt[tmp]++;
               }
            }   
        }
    }
}
string s;
int main() {
    INIT();
    init();

    cin >> n;
    for(ll i = 0; i < n; i++) {
        cout << cnt[i+1] << endl;
    }
}

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

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  string s; cin >> s;
  if(s[6] == '3' || s[6] == '4' ||
     (s[5] == '0' && s[6] == '1') ||
     (s[5] == '0' && s[6] == '2'))
    cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}

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

using namespace std;

const int N = 1e5 + 10;

char str[2][N];
int s[2][N], q;

int main(){
    cin >> str[0] + 1 >> str[1] + 1;
    for (int type = 0; type < 2; type++)
        for (int i = 1; i <= strlen(str[type] + 1); i++)
            s[type][i] = s[type][i - 1] + (str[type][i] != 'A') + 1;
    cin >> q;
    while (q--){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        puts(((s[0][b] - s[0][a - 1]) - (s[1][d] - s[1][c - 1])) % 3 == 0 ? "YES" : "NO");
    }
}


Measured memory_bytes: 1536
h, w = (int(x) for x in input().split())
S = [list(input()) for _ in range(h)]

next_x = [1, 0, -1, 0]
next_y = [0, 1, 0, -1]

for y in range(h):
    for x in range(w):
        if S[y][x] == "#":
            for i in range(4):
                nx = x + next_x[i]
                ny = y + next_y[i]
                if 0 <= nx < w and 0 <= ny < h and S[ny][nx] == "#":
                    break
            else:
                print("No")
                exit()

print("Yes")


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

int main() {
    string s;
    cin >> s;
    int a[26];
    for (int i = 0; i < 26; i++) a[i] = 0;
    for (int i = 0; i < s.size(); i++) {
        a[s[i]-97]++;
    }
    bool found = true;
    for (int i = 0; i < 26; i++) {
        if (a[i] == 0) {
            found = false;
            char c = i + 97;
            cout << c << endl;
            return 0;
        }
    }
    if (found) cout << "None" << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
 <url:https://agc008.contest.atcoder.jp/tasks/agc008_c>
 問題文============================================================
 正方形のマスを 4 個繋げた形をテトロミノといいます。
 次の 7 種類のテトロミノを順に I, O, T, J, L, S, Z 型と呼ぶことにします。
 
 (図略)
 
 すぬけ君は I, O, T, J, L, S, Z 型のテトロミノをそれぞれ aI, aO, aT, aJ, aL, aS, aZ 個ずつ持っています。
 すぬけ君はこれらのテトロミノのうち K 個を組み合わせ、縦 2 マス、横 2K マスの長方形を作ろうとしています。
 このとき、すぬけ君は次のルールに従います。
 
 各テトロミノを置くとき、回転はできるが、反転はできない。
 長方形の各マスにはちょうど 1 個のテトロミノが置かれているようにする。
 長方形の外部にテトロミノが置かれていないようにする。
 
 すぬけ君はできるだけ大きい長方形を作ろうとしています。 K の最大値を求めてください。
 
 制約
 0≤aI,aO,aT,aJ,aL,aS,aZ≤109
 aI+aO+aT+aJ+aL+aS+aZ≥1
 =================================================================
 
 解説=============================================================
 
 まず、できる長方形は以下の形の組み合わせでしかない
 
 K+=1(O:1個)(1)  K+=3(I,J,L:１個)(2)   K+=2(J:2個 or L:2個)(3)   K+=2(I:2個)(4)
 ◽️◽️         ◽️ ◽️◽️◽️◽️ ◽️         ◽️ ◽️◽️◽️               ◽️◽️◽️◽️
 ◽️◽️         ◽️◽️◽️  ◽️◽️◽️         ◽️◽️◽️ ◽️               ◽️◽️◽️◽️
 
 ここで(2)のパターンは高々1回利用するか、しないかを選択すれば良い。
 ∵ （２）を2回利用すると (3)および（４）を利用した時の個数とKの増加分が一致するため
 
 よって、(2)を利用するかしないかを決めて
 あとは(3)および(4)を実行すれば良い
 
 ================================================================
 */

enum Tetromino { I,O,T,J,L,S,Z};
ll solve(){
    //    cout << I << " " << O << " " << T << " " << J << " " << L << " "<< S << " " << Z << endl;
    ll res = 0;
    ll a[7] = {};
    for(auto &in:a) cin >> in;
    res += a[O]; // (1)
    
    ll t1 = 0, t2 = 0;
    t1 += 2*(a[J]/2);// a[J]%=2;
    t1 += 2*(a[L]/2);// a[L]%=2;
    t1 += 2*(a[I]/2);// a[I]%=2;
    
    if(a[J] >= 1 && a[L] >= 1 && a[I] >= 1){
        t2 += 3; a[J]--; a[L]--; a[I]--;
        t2 += 2*(a[J]/2);// a[J]%=2;
        t2 += 2*(a[L]/2);// a[L]%=2;
        t2 += 2*(a[I]/2);// a[I]%=2;
    }
    
    res += max(t1,t2);
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11

int main()
{
    int n; cin >> n;
    ll a[n],b[n];
    rep(i,n) cin >> a[i];
    rep(i,n){
        b[i] = a[i] - (i+1);
    }
    sort(b,b+n);
    ll mid_a = b[n/2], mid_b = b[n/2-1];
    ll sum1 = 0, sum2 = 0;
    rep(i,n){
        sum1 += abs(b[i]-mid_a);
        sum2 += abs(b[i]-mid_b);
    }
    cout << min(sum1,sum2) << endl;
}

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

using namespace std;

#define ll long long int
#define vi vector<int>
#define prec fixed<<precision(10)
#define mod 1000000007
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)

int main(){
	ll a,b;
	cin >> a >> b;
	cout << min(b-a%b,a%b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N = 1e5 + 5;
int a[N];
int n;
int mem[N];
int oo = 0x3f3f3f3f;
int DP(int i = 0){
    if(i+1 == n)
        return 0;
    int &ret = mem[i];
    if(~ret)
        return ret;
    return ret = min((i+1<n?DP(i+1)+abs(a[i]-a[i+1]):oo), (i+2<n?DP(i+2)+abs(a[i]-a[i+2]):oo) );
}

int main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    memset(mem, -1, sizeof(mem));
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    cout<<DP()<<'\n';
}

Measured memory_bytes: 6728
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template <typename T> using order_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1, typename T2> using order_map = tree <T1, T2, less <T1>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T> bool MIN(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool MAX(T &a, T b) { return a < b ? (a = b, true) : false; }

#define ll              long long int
#define endl            '\n'
#define pii             pair <int, int>
#define pll             pair <ll, ll>
#define mk              make_pair
#define ff              first
#define ss              second
#define all(a)          (a).begin(), (a).end()
#define rall(a)         (a).rbegin(), (a).rend()
#define eb              emplace_back
#define pb              push_back
#define LINE            __LINE__

static const int maxn = 1000 + 5;
static const int logn = 19;

struct Node {
      string s;
      int open, close;
      Node(string s = "", int open = 0, int close = 0)
            : s(s), open(open), close(close) {}
};

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);


      auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
      mt19937 mt_rand(seed);

      function <ll(ll, ll)> Rand = [&](ll l, ll r) {
            ll rnd = uniform_int_distribution <ll> (l, r)(mt_rand);
            return rnd;
      };

      string a, b;
      cin >> a >> b;
      int len = a.size();
      for (int i = 0; i < len; i++) {
            if (a[i] != b[i]) {
                  cout << "No" << endl;
                  return 0;
            }
      }
      cout << "Yes" << endl;

      #ifndef ONLINE_JUDGE
            cerr << endl << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
      #endif // ONLINE_JUDGE
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)
#define ll long long

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

int main(){
    int n,count=0,temp=0;
    cin>>n;
    vector<int> a(n);
    rep(i,n)
        cin>>a.at(i);
    sort(a.begin(),a.end());
    int i=0;
    while(i<n){
        int v= a.at(i);temp =0;
        while(i<n&&v==a.at(i))i++,temp++;
        count+=temp%2;
    }
    cout<<count<<endl;
    return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	string s; cin>>s;
	rep(i,0,s.size()){
		if(s[i]==',')s[i]=' ';
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 3612
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,k;
    cin>>n>>k;
    int ans=k;
    rep(i,n-1){
        ans*=k-1;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, C = map(int, readline().split())
    if A<C<B or A>C>B:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
class Main {
    public static void main(String args[]) {
		java.util.Scanner sc = new java.util.Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        // value, weight
        int[][] m = new int [N+1][2];
        for(int i=1; i<N+1; i++){
            m[i][0] = Integer.parseInt(sc.next());
            m[i][1] = Integer.parseInt(sc.next());
        }

        int[][] dp = new int[N+1][W+1];
        for(int ni=1; ni<N+1; ni++){
            for(int wi=1; wi<W+1; wi++){
                // System.out.println(wi - m[ni][1]);
                int useNiObject = wi - m[ni][1] >= 0 ? dp[ni-1][wi - m[ni][1]] + m[ni][0] : -1;
                dp[ni][wi] = Math.max(dp[ni-1][wi], useNiObject );
            }
        }
        System.out.println(dp[N][W]);
        sc.close();
    }
}


Measured memory_bytes: 30744
#include<iostream>
#include<map>
#include<set>
using namespace std;
int main(){
  long long n;
  map<long long,int>mp;
  set<long long>st;
  cin>>n;

  long long temp=n;  
  for(long long i=2;i*i<=n;i++){
    if(temp%i==0){
      st.insert(i);

      while(temp%i==0){
	mp[i]++;
	temp/=i;
      }
    }
  }
  if(temp!=1){
    st.insert(temp);
    mp[temp]++;
  }

  long long cnt=0;
  for(set<long long>::iterator itr=st.begin();itr!=st.end();itr++){
    long long target=1;
    //        cout<<"itr:"<<*itr<<endl;
    //        cout<<"map:"<<mp[*itr]<<endl;
    while(mp[*itr]>=target){
      cnt++;
      mp[*itr]-=target;
      target++;
    }
  }
  
  cout<<cnt<<endl;
  return(0);
}

Measured memory_bytes: 3636
#include <stdio.h>
main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<b){
    printf("a < b\n");
  }
  else if(a>b){
    printf("a > b\n");
  }
  else{
    printf("a == b\n");
  }
  return 0;
}
  

Measured memory_bytes: 580
#include <stdio.h>

int n, A[50];

int Search (int m, int i) {
    if ( m == 0 ) return 1;
    if ( i >= n ) return 0;
    int res = Search(m, i + 1) || Search(m - A[i], i + 1);
    return res;
}

int main(void) {
  int i, q, m;

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

  scanf ("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &m);
    if (Search(m, 0) ) printf ("yes\n");
    else printf ("no\n");
  }

  return 0;
}

Measured memory_bytes: 580
def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    ans = [1] * n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if H[a] == H[b]:
            ans[a] = 0
            ans[b] = 0
        elif H[a] < H[b]:
            ans[b] = 1 & ans[b]
            ans[a] = 0
        else:
            ans[b] = 0
            ans[a] = 1 & ans[a]
    cnt = ans.count(1)
    print(cnt)


if __name__ == '__main__':
    main()

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



int main(void) {
   int N;
   cin>>N;
   map<ll,ll> A;
   rep(i,N) {
      ll a;
      cin>>a;
      if(A.count(a)) A[a]++;
      else A[a] = 1;
   }
   vector<ll> max2;
   auto itr = A.end();
   while (1) {
      itr--;
      if (itr->second >=2) max2.push_back(itr->first);
      if (itr->second >=4) max2.push_back(itr->first);
      if (max2.size()>=2) break;
      if (itr==A.begin()) break;
   }
   if(max2.size()<2) cout<<0<<endl;
   else cout<<max2[0]*max2[1]<<endl;
   return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		int a, b;
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		
		int[] city = new int[n];
		for(int i : city) i = 0;
		for(int i = 0; i < m; i++) {
			a = s.nextInt();
			b = s.nextInt();
			city[a-1]++;
			city[b-1]++;
		}
		
		for(int i = 0; i < n; i++) System.out.println(city[i]);
	}

}


Measured memory_bytes: 35736
import numpy as np
X=[]
Y=[]
Z=[]
for i in range(5):
  x=int(input())
  X += [x]
for i in range(5):
  Y +=[-(-X[i]//10)*10]

for i in range(5):
  Z +=[Y[i]-X[i]]

answer=sum(Y)-max(Z)

print(answer)

Measured memory_bytes: 12500
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define debug cout<<"****************"<<endl
using namespace std;
typedef long long ll;
inline void ju() {
	freopen("***.in","r",stdin);
	freopen("***.out","w",stdout);
}
inline ll rd() {
	ll x=0,f=1; char c=getchar();
	while((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(c>='0'&&c<='9') {
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=rd();
	if(n&1) printf("%d\n",(n<<1));
	else printf("%d\n",n);
	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 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);}
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int &a : A) cin >> a;
    sort(REV_WHOLE(A));
    int p;
    for(int i = 0; i <= N; i++) {
        if(i + 1 <= A[i]) {
            p = i;
        } else break;
    }
    bool ans;
    ans = (A[p] - p + 1) % 2 == 1;
    int x = 0;
    for(int i = p + 1; i < N && A[i] == p + 1; i++, x++);
    ans |= x % 2 == 1;
    cout << (ans ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 640
tscore = hscore = 0
n = gets.to_i
n.times {
	tcard, hcard = gets.split( " " )
	if tcard < hcard
		hscore += 3
	elsif hcard < tcard
		tscore += 3
	else
		hscore += 1
		tscore += 1
	end
}
puts( "#{tscore} #{hscore}" )

Measured memory_bytes: 6104
# using dp with memoization, TLE
from sys import stdin
N, W = map(int, input().split())
m = stdin.read().splitlines()
s = [[int(i) for i in line.split()] for line in m]

dp = [0] * (W + 1)
next_dp = [0] * (W + 1)
for n in range(1, N + 1):
    for w in range(0, W + 1):
        if w >= s[n - 1][0]:
            next_dp[w] = max(next_dp[w], dp[w - s[n - 1][0]] + s[n - 1][1])
    dp = next_dp[:]
print(dp[W])


Measured memory_bytes: 59144
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long lli;

const int MAX=1<<17,mod=1e9+7;

int main() {
	int a,b;
	scanf("%d%d",&a,&b);
	int res=0;
	int tmp=b;
	while(b) {
		a*=10;
		b/=10;
	}
	a+=tmp;

	for(int i=1;i<=400;i++) {
		if(i*i==a) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");

	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; ++i){
    cin >> h[i];
  }
  
  int res = 0;
  for(int i = 0; i < n; ++i){
    bool check = true;
    for(int j = 0; j < i; ++j){
      if(h[j] > h[i]){
        check = false;
      }
    }
    if(check){
      ++res;
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 3532
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int left = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'A') {
      left = i;
      break;
    }
  }
  int right = 0;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] == 'Z') {
      right = i;
      break;
    }
  }
  printf("%d\n", right - left + 1);
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define int long long
using namespace std;

int n,a[100005],b[100005],c[100005],dp[100005][4];


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin >> n ;
    for(int i=1;i<=n;i++) cin >> a[i] >> b[i] >> c[i];
    dp[1][1]=a[1];
    dp[1][2]=b[1];
    dp[1][3]=c[1];
    for(int i=2;i<=n;i++){
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i];
        dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
    }
    cout<<*max_element(dp[n]+1,dp[n]+4);
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,max = 0, sum = 0;
  cin >> N;
  vector<int> vec1(N);
  for (int i = 0; i < N; i++) {
  cin >> vec1.at(i);
  if (max < vec1.at(i)){
  max = vec1.at(i);
  }
  }
  for (int i = 0; i < max; i++){
   vector<int> vec2(N + 2);
   for (int n = 0; n < N; n++){
   if (vec1.at(n) > i ) {
   vec2.at(n + 1) = 1;
   }
   }
   int count = 0;
   for (int j = 0; j < N + 1 ;j++ ) {
   if (vec2.at(j) != vec2.at(j + 1)){
   count++;
   }
   }
   count = count / 2;
   sum += count;
   }
  cout << sum << endl;
}
  



Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string S;
  cin >> S;
  bool alf[26];
  rep(i,26){
    alf[i]=false;
  }
  for(int i=0;i<S.size();i++){
    alf[(int)(S[i]-'a')]=true;
  }
  int res=0;
  while(res<26){
    if(!alf[res]){
      break;
    }
    res++;
  }
  if(res!=26){cout << (char)('a'+res) << endl;}
  else{ cout << "None" << endl;}
}




Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int cnt[100005];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	REP(i, n) {
		int l, r;
		scanf("%d%d", &l, &r);
		r++;
		int ma = -1, mi = 1e9;
		FOR(jump, 1, 551) {
			int tl = (l - 1) / jump + 1;
			int tr = min((r - 1) / jump + 1, mi);
			mi = min(mi, tl);
			cnt[tl]++;
			cnt[tr]--;
		}
		FOR(d, 1, mi) {
			if (((l - 1) / d + 1) * d < r) {
				cnt[d]++;
				cnt[d + 1]--;
			}
		}
	}
	REP(i, m)cnt[i + 1] += cnt[i];
	REP(i, m)printf("%d\n", cnt[i + 1]);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    int n,m; cin >> n;
    map<int,int> mp;
    int a[n];
    vector<int> v;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    cin >> m;
    int b[m];
    for(int i = 0; i < m; i++){
        cin >> b[i];
        mp[b[i]]++;
    }
    for(int i = 0; i < n; i++){
        if (mp[a[i]] == 1){
            v.push_back(a[i]);
        }
    }

    for(int i = 0; i < m; i++){
        if (mp[b[i]] == 1){
            v.push_back(b[i]);
        }
    }
    sort(v.begin(),v.end());
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << endl;
    }
}


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

using namespace std;

using Int  = int_fast64_t;
using UInt = uint_fast64_t;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

Int pow2(int v) {
    return v * v;
}

void sub()
{
    const auto        N(cin2var<UInt>());
    std::vector<UInt> patterns;
    patterns.reserve(N);
    std::vector<tuple<Int, Int>> poss;
    poss.reserve(N);
    for (auto i = 0u; i < N; ++i) {
        const auto x(cin2var<Int>());
        const auto y(cin2var<Int>());
        poss.push_back(make_tuple(x, y));
        patterns.push_back(i);
    }
    UInt pattern_count = 0;
    double length = 0.0;
    do {
        ++pattern_count;
        double sub_len = 0.0;
        Int prev_x = 0;
        Int prev_y = 0;
        for (auto i = 0u; i < N; ++i) {
            const Int x = get<0>(poss[patterns[i]]);
            const Int y = get<1>(poss[patterns[i]]);
            if (i != 0u) {
                sub_len += sqrt(pow2(x - prev_x) + pow2(y - prev_y));
            }
            prev_x = x;
            prev_y = y;
        }
        length += sub_len;
    } while (next_permutation(patterns.begin(), patterns.end()));
    cout << length / static_cast<double>(pattern_count) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;

    int N, M;
    cin >> N >> M;
    std::vector<int> Ls, Rs;
    for (int i = 0; i < M; ++i)
    {
        int l, r;
        cin >> l >> r;
        Ls.push_back(l);
        Rs.push_back(r);
    }

    auto l_max = *max_element(Ls.begin(), Ls.end());
    auto r_min = *min_element(Rs.begin(), Rs.end());
    int count = max(r_min - l_max + 1, 0);

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int four = 0, two = 0, other = 0;
  for(int i = 0; i < n; i++){
    long long a;
    cin >> a;
    if(a%4 == 0) four++;
    else if(a%2 == 0) two++;
    else other++;
  }
  if((four+1 >= other && two == 0) || four >= other) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
int C[234567];
int las[234567];
LL dp[234567];
const LL MOD = 1000000007;

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}
	map<int, int>mp;
	for (int i = 0; i < N; ++i) {
		if (mp.count(C[i])) {
			las[i] = mp[C[i]];
		}
		else {
			las[i] = -1;
		}
		mp[C[i]] = i;
	}
	dp[0] = 1;
	for (int i = 1; i <= N; ++i) {
		if (las[i - 1] < 0) {
			dp[i] = dp[i - 1];
		}
		else if (las[i - 1] != i - 2) {
			dp[i] = dp[i - 1] + dp[las[i - 1] + 1];
			dp[i] %= MOD;
		}
		else {
			dp[i] = dp[i - 1];
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep1(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
lli ans;
lli mod = pow(10,9)+7;
lli x[200005];	
lli x_inv[200005];
lli cmb(lli a,lli b){
	return x[a]*x_inv[b]%mod*x_inv[a-b]%mod;
}
lli get_inv(lli x){
	lli m = mod-2;
	lli s = 1;
	while(m!=0){
		if(m&1)s=(s*x)%mod;
		x=(x*x)%mod;
		m>>=1;
	}
	return s;
}
int main(){
lli A,B,W,H;
cin >> H >> W >> A >> B;
x[0] = x_inv[0]=1; 
rep(i,W+H+3){
	x[i+1]=x[i]*(i+1)%mod;
	x_inv[i+1]=get_inv(x[i+1]);
}
lli ans = 0;
for(int i = 0;i<H-A;i++){
	ans +=cmb(i+B-1,B-1)*cmb(H-i+W-B-2,W-B-1);
	ans %=mod;
}
cout << ans<<endl;
}


Measured memory_bytes: 3328
//package Contest087;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
                int x = sc.nextInt(),a=sc.nextInt(),b=sc.nextInt();
                out.println(((x-a)%b));


        out.flush();
    }
}


Measured memory_bytes: 21972
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,wb;
    cin >> n>>wb;
    vll w(n),v(n);
    REP(i,n){
        cin >> w[i] >> v[i];
    }
    vvll val(4);
    REP(i,n){
        val[w[i]-w[0]].pb(v[i]);
    }
    REP(i,4){
        sort(rALL(val[i]));
    }
    vvll sval(4,vll(n+1));
    REP(i,4){
        if(!val[i].empty()){
            sval[i][0]=0;
            for(int j=0;j<(int)val[i].size();j++){
                sval[i][j+1]=sval[i][j]+val[i][j];
            }
        }
    }
    ll ans = 0;
    for(ll i=0;i<=(ll)val[0].size();i++){
        for(ll j=0;j<=(ll)val[1].size();j++){
            for(ll k=0;k<=(ll)val[2].size();k++){
                for(ll l=0;l<=(ll)val[3].size();l++){
                    if(w[0]*i+(w[0]+1)*j+(w[0]+2)*k+(w[0]+3)*l<=wb){
                        ans = max(ans,sval[0][i]+sval[1][j]+sval[2][k]+sval[3][l]);
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

pair<ll,ll> extgcd(ll a,ll b){
    
    ll s=a,sx=1,sy=0,t=b,tx=0,ty=1;
    
    while(s%t!=0){
        ll temp=s/t;
        ll u=s-t*temp;
        ll ux=sx-tx*temp;
        ll uy=sy-ty*temp;
        
        s=t;
        sx=tx;
        sy=ty;
        t=u;
        tx=ux;
        ty=uy;
    }
    
    return {tx,ty};
}

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

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int a,b,c;cin>>a>>b>>c;
        if(a+b+c==0) break;
        
        int g=gcd(gcd(a,b),c);
        a/=g;
        b/=g;
        c/=g;
        
        int ans=INF,x=INF,y=INF;
        
        pair<ll,ll> p=extgcd(a,b);
        ll d=p.first,e=p.second;
        
        d*=c;
        e*=c;
        
        ll f=d/b;
        d-=f*b;
        e+=f*a;
        
        //cout<<p.first<<" "<<p.second<<endl;
        
        if(ans>abs(d)+abs(e)){
            ans=abs(d)+abs(e);
            x=abs(d);
            y=abs(e);
        }
        
        d-=b;
        e+=a;
        
        if(ans>abs(d)+abs(e)){
            ans=abs(d)+abs(e);
            x=abs(d);
            y=abs(e);
        }
        
        f=e/a;
        d+=f*b;
        e-=f*a;
        
        if(ans>abs(d)+abs(e)){
            ans=abs(d)+abs(e);
            x=abs(d);
            y=abs(e);
        }
        
        d+=b;
        e-=a;
        
        if(ans>abs(d)+abs(e)){
            ans=abs(d)+abs(e);
            x=abs(d);
            y=abs(e);
        }
        
        cout<<x<<" "<<y<<endl;
    }
}






Measured memory_bytes: 3116