akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import std.regex;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;

void main() {
  long N, M;
  scanln(N, M);
  long[] as = readln.split.to!(long[]);
  long s = as.sum;
  writeln(
    as.count!(a => a*4*M >= s) >= M ? "Yes" : "No"
  );
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep);

  string line = readln.chomp;
  static if (__VERSION__ >= 2074) {
    line.formattedRead!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "line.formattedRead(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}


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

	int a, b; cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

// ■■■■■■■■■■■■■■■■headerここまで■■■■■■■■■■■■■■■■

int main() {

    ll a;
    ld b;
    cin >> a >> b;

    ll prod = (ll)floor(a * b);
    cout << prod << endl;

    return 0;

}

Measured memory_bytes: 3724
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


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

    if(N==25){
        cout << "Christmas" << endl;
    } else if(N==24){
        cout << "Christmas Eve" << endl;
    } else if(N==23){
        cout << "Christmas Eve Eve" << endl;
    } else if(N==22){
        cout << "Christmas Eve Eve Eve" << endl;
    } 
    return 0;

}

Measured memory_bytes: 768
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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 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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main()
{
	int a, b;
	cin >> a >> b;
	int n = b - a;
	cout << n * (n - 1) / 2 - a << endl;
	return 0;
}



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

int main() {
  string s;
  cin>>s;
  set<char> chars;
  for (char c: s) {
    chars.insert(c);
  }
  set<char> alphabets;
  for (int i=0; i<26; i++) {
    alphabets.insert('a' + i);
  }
  if (chars.size() != 26) {
    for (char c: alphabets) {
      if (chars.find(c) == chars.end()) {
        cout<<s<<c<<endl;
        return 0;
      }
    }
  }

  for (int i=s.length()-1; i>0; i--) {
    if (s[i] > s[i-1]) {
      for (int j=0;j<i-1; j++) {
        cout<<s[j];
      }
      set<char> tmp;
      for (int j=i; j<s.length(); j++) {
        if (s[j] > s[i-1]) {
          tmp.insert(s[j]);
        }
      }

      cout<<*tmp.begin()<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <unistd.h>

static const unsigned char TABLE_BITS_COUNT[] = {
  0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
  2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6
};

static const unsigned char TABLE_TRAILING_ZEROS[] = { 0, 1, 6, 2, 7, 5, 4, 3 };

static unsigned int
fold_bitflag_func(
  unsigned int  acc,
  unsigned int  x,
  unsigned char *ary,
           int  col)
{
  unsigned char i = TABLE_TRAILING_ZEROS[((x * 0x1d) >> 5) & 0x07];
  return acc + TABLE_BITS_COUNT[ary[i] & col];
}

static unsigned int
fold_bitflag(
  unsigned int  n,
  unsigned int  init,
  unsigned int  (*func)(unsigned int, unsigned int, unsigned char *, int),
  unsigned char *data0,
           int  data1)
{
  unsigned int flg;

  while (1) {
    flg = n & ((~n) + 1);
    if (flg == 0) {
      break;
    }
    init = func(init, flg, data0, data1);
    n ^= flg;
  }

  return init;
}

static void
abc173_c(void)
{
  unsigned int h, w, k;
  unsigned char ary[6];

  if (scanf("%d %d %d\n", &h, &w, &k) == EOF) {
    perror("scanf()");
    return;
  }

  for (int i = 0; i < h; i++) {
    unsigned char buf[8];
    if (scanf("%s\n", buf) == EOF) {
      perror("scanf()");
      return;
    }

    unsigned char c = 0;
    for (int j = 0; j < w; j++) {
      if (buf[j] == '#') {
        c |= (1 << j);
      }
    }
    ary[i] = c;
  }

  unsigned int ans = 0;
  for (int row = 0; row < 1 << h; row++) {
    for (int col = 0; col < 1 << w; col++) {
      unsigned int cnt = fold_bitflag(row, 0, fold_bitflag_func, ary, col);
      if (cnt == k) {
        ans += 1;
      }
    }
  }
  printf("%d\n", ans);
}

int
main(void)
{
  abc173_c();
  return 0;
}


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

#define M_PI 3.14159265358979323846

using namespace std;

//typedef
//-------------------------#include <bits/stdc++.h>

#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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const int INF = 2147483647;

int a[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int N, A, B;

    cin >> N >> A >> B;

    int ans = 0;
    for (int i = 1; i <= N; i++)
    {

        int ct = 0;
        int tmp = i;
        while (tmp)
        {
            ct += tmp % 10;
            tmp /= 10;
        }
        if (ct >= A && ct <= B)
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.PriorityQueue
import java.util.Comparator

object MainKt {
  @JvmStatic fun main(args:Array<String>) {
    val N=readLine()!!.toInt()
    val a=readLine()!!.split(" ").map(String::toInt)
    assert(a.size==N)
    
    val front_queue = PriorityQueue<Int>()
    val last_queue=PriorityQueue<Int>(N,object: Comparator<Int> {
      override fun compare(a:Int,b:Int) = b-a
    })
    
    var front_acc=0L
    var last_acc=0L
    var front_sum=Array(N+1) {0L}
    var last_sum=Array(N+1) {0L}

    a.slice(0.until(N)).forEach{
          front_acc+=it
          front_queue.add(it)
          }
       a.slice((2*N).until(3*N)).forEach{ 
         last_acc+=it
         last_queue.add(it)
         }
    front_sum[0]=front_acc
    last_sum[N]=last_acc
    (N.until(2*N)).forEach{
      front_queue.add(a[it])
      front_acc+=a[it]-front_queue.poll()
      front_sum[it-N+1]=front_acc
    }
    (2*N-1 downTo N).forEach {
      last_queue.add(a[it])
      last_acc+=a[it]-last_queue.poll()
      last_sum[it-N]=last_acc
    }
    println((0..N).map{ front_sum[it]-last_sum[it]}.max()!!)
  }
}


Measured memory_bytes: 106660
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# N=20000のとき，2の倍数と3の倍数を全て採用
# 6の倍数をペアにして適当に削る

N = I()

def output(X,Y):
    for y in Y:
        X.append(y[0])
        X.append(y[1])
    print(*X)
    return

X = []
Y = []
y2 = []
y3 = []
for i in range(2,30001):
    if i%6 == 0:
        X.append(i)
    else:
        if i%2 == 0:
            y2.append(i)
        elif i%3 == 0:
            y3.append(i)
        else:
            pass
        if len(y2) == 2:
            Y.append(y2)
            y2 = []
        if len(y3) == 2:
            Y.append(y3)
            y3 = []

a = 20000-N

if a == 19997:
    print(2,5,63)
elif a == 19996:
    print(2,5,20,63)
else:
    if a >= 5000:
        if a%2 == 0:
            for _ in range((a-5000)//2):
                Y.pop()
            output([],Y)
        else:
            for _ in range((a-4999)//2):
                Y.pop()
            output([6],Y)
    else:
        for _ in range(a-a//2*2):
            X.pop()
        for _ in range(a//2):
            Y.pop()
        output(X,Y)

Measured memory_bytes: 46960
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class TSort
{
public:
  int solve();
  void dfs( vector<vector<int>>& adj, vector<bool>& vd, vector<int>& rt, int u );
};

int TSort::solve()
{
  int nv, ne;
  cin >> nv >> ne;

  vector<vector<int>> adj(nv);
  vector<bool> visited(nv, false);
  vector<int> ret;

  for ( auto i = 0; i < ne; ++i )
    {
      int s, t;
      cin >> s >> t;
      adj[s].push_back( t );
    }

  for ( auto i = 0; i < nv; ++i )
    {
      if ( ! visited[i] )
        dfs( adj, visited, ret, i );
    }

  for ( auto i = 0; i < nv; ++i )
    cout << ret[nv - 1 - i] << endl;
  
  return 0;
}

void TSort::dfs( vector<vector<int>>& adj, vector<bool>& vd, vector<int>& rt, int u )
{
  vd[u] = true;

  int n = adj[u].size();
  
  for ( auto i = 0; i < n; ++i )
    {
      int v = adj[u][i];
      
      if ( ! vd[v] )
        {
          dfs( adj, vd, rt, v );
        }
    }

  rt.push_back( u );
}

int main()
{
  TSort ts;

  ts.solve();

  return 0;
}

Measured memory_bytes: 1948
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        mut k: i64,
    }

    let mut ans: i64 = 0;
    let t = a.min(k);
    k -= t;
    ans += t * 1;
    let t = b.min(k);
    k -= t;
    ans += t * 0;
    let t = c.min(k);
    k -= t;
    ans += t * -1;

    println!("{}", ans);
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
struct node{
	int a,b;
}c[maxn];
bool cmp(node x,node y)
{
	return x.b<y.b;
}
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].a>>c[i].b;
	}
	sort(c,c+n,cmp);
	int tim=0;
	for(int i=0;i<n;i++)
	{
		if(tim+c[i].a<=c[i].b)
		{
			tim+=c[i].a;
		}
		else
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1792
# ABC 166 C
# https://atcoder.jp/contests/abc166/tasks/abc166_c

n, m = gets.split(/ /).map(&:to_i)
h = gets.split(/ /).map(&:to_i)
ab_s = Array.new(m) { gets.split(/ /).map(&:to_i) }

ab_h = Hash.new
ab_s.each do |ab|
  a, b = ab
  ab_h[a] ||= []
  ab_h[b] ||= []
  ab_h[a].push(b)
  ab_h[b].push(a)
end

count = 0
h.each.with_index(1) do |observatory, i|
  other_observatories_ids = ab_h[i]
  if other_observatories_ids.nil? || other_observatories_ids.map { |id| h[id - 1] }.all? { |height| height < observatory }
    count += 1
  end
end

puts count


Measured memory_bytes: 32492
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		long[] branch = new long[16];
		branch[1] = 1;
		for (int i = 2; i < branch.length; ++i) {
			branch[i] = branch[i - 1] * 3 + 1;
		}
		while (sc.hasNext()) {
			int N = sc.nextInt();
			long ans = N;
			for (int i = 1; i < N - 1; ++i) {
				ans += 2 * branch[Math.min(i, N - 1 - i)];
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
using namespace std;
int count[52];
int n,m,a,b;
int main(void){
    // Here your code !
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&a,&b);
        count[a-1]++;
        count[b-1]++;
    }
    for(int i=0;i<n;i++){
        printf("%d\n",count[i]);
    }
    return 0;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,q=map(int,input().split())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))

node=[[] for _ in range(n)]
d=deque()
d.append(0)
for pair in v:
    node[pair[0]].append(pair[1])
    node[pair[1]].append(pair[0])
ans=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    ans[p-1]+=x
seen=[0]*n
seen[0]=1
while d:
   
    i=d.pop()
    for j in node[i]:
        if seen[j]==0:
            d.append(j)
            seen[j]=1
            ans[j]+=ans[i]
print(*ans)

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

int main(){
    int h,w,x,y;
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(10) << double(w) * double(h) / 2; 
    cout << " " <<(x + x == w && y + y == h) << endl;
    return 0;
}


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

#define fread freopen("in.txt","r",stdin)
#define ll long long int

using namespace std;

void in(int arr[], int n)
{
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
}

int main()
{
    //fread;
    int n;
    cin >> n;
    int arr1[n - 1], i, sum = 0;
    in(arr1, n - 1);
    for(i = 0; i < n - 2; i++)
    {
        sum += min(arr1[i], arr1[i + 1]);
    }
    sum += arr1[n - 2];
    sum += arr1[0];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int a, b, c, d;
    std::scanf("%d %d %d %d", &a, &b, &c, &d);
    int x = std::max(a, c), y = std::min(b, d);
    if (x <= y) {
        std::printf("%d\n", y - x);
    }
    else {
        std::puts("0");
    }
    return 0;
}

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

int main() {
  int n,d;
  cin >> n >> d;
  vector<vector<int>> v(n, vector<int>(d));
  rep(i,n) rep(j,d) cin >> v[i][j];

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double distanse = 0.0, total = 0.0;
      for (int k = 0; k < d; k++) {
        total += pow(v[i][k]-v[j][k],2);
      }
      distanse = pow(total,0.5);
      if (distanse == float(distanse)) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4036
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\,
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> cnt(n+1,0);
    for(int x = 1;x<=100;x++){
        for(int y = 1;y<=100;y++){
            for(int z = 1;z<=100;z++){
                int s = x*x + y*y + z*z + x*y + y*z + z*x;
                if(s <= n) cnt[s]++;
            } 
        }
    } 
    for(int i=1;i<=n;i++) cout << cnt[i] << endl;

}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

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

    long long n;
    cin >> n;

    if (n % 2 == 1) {
        cout << 0 << endl;
    } else {
        long long ans = n / 10;

        n /= 10;
        while (n > 0) {
            ans += n / 5;
            n /= 5;
        }

        cout << ans << endl;
    }

    return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)


const ll MAX = 2e6 + 1;
ll MOD = 1e9+7;
ll INV[MAX] = {}, FACTORIAL[MAX] = {}, FACTORIAL_INV[MAX] = {};

void calc_init() {
  INV[1] = 1;
  FACTORIAL[0] = FACTORIAL[1] = 1;
  FACTORIAL_INV[0] = FACTORIAL_INV[1] = 1;

  rep(i, 2, MAX + 1) {
    ll q = MOD / i, r = MOD % i;
    INV[i] = (-INV[r] * q) % MOD;
    INV[i] = (INV[i] + MOD) % MOD;
    FACTORIAL[i] = (i * FACTORIAL[i - 1]) % MOD;
    FACTORIAL_INV[i] = (INV[i] * FACTORIAL_INV[i - 1]) % MOD;
  }
}

ll nCk(ll n, ll k) {
  ll ans = FACTORIAL[n];
  ans = (ans * FACTORIAL_INV[k]) % MOD;
  ans = (ans * FACTORIAL_INV[n - k]) % MOD;
  return ans;
}

int main() {
  ll X, Y;
  cin >> X >> Y;

  if ((X + Y) % 3 != 0) {
    cout << 0 << BR;
    return 0;
  }
  calc_init();

  ll n = (X + Y) / 3;
  ll k = X - n;
  if (X < n || Y < n) {
    cout << 0 << BR;
    return 0;
  }

  cout << nCk(n, k) << BR;
  return 0;
}

Measured memory_bytes: 47104
# AOJ ALDS1_11_D Connected Components
# Python3 2018.6.23 bal4u

# UNION-FIND library
class UnionSet:
	def __init__(self, nmax):
		self.size = [1]*nmax
		self.id = [i for i in range(nmax+1)]
	def root(self, i):
		while i != self.id[i]:
			self.id[i] = self.id[self.id[i]]
			i = self.id[i]
		return i
	def connected(self, p, q): return self.root(p) == self.root(q)
	def unite(self, p, q):
		i, j = self.root(p), self.root(q)
		if i == j: return
		if self.size[i] < self.size[j]:
			self.id[i] = j
			self.size[j] += self.size[i]
		else:
			self.id[j] = i
			self.size[i] += self.size[j]
# UNION-FIND library

n, m = map(int, input().split())
u = UnionSet(n)
for i in range(m):
	s, t = map(int, input().split())
	u.unite(s, t)
q = int(input())
for i in range(q):
	s, t = map(int, input().split())
	print("yes" if u.connected(s, t) else "no")


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

// author : LCA

ll N;
map<ll, ll> mp;

void prime_decomposition(int n) {	
  int i = 2;

  while (i * i <= n) {
    if (n % i == 0) {
      n /= i;
      mp[i]++;
    } else {
      i++;
    }
  }
  mp[n]++;

  return;
}

void solve() {
  ll num2 = 0, num4 = 0, num14 = 0, num24 = 0, num74 = 0;
  ll res = 0;
  if (N == 1) {
    cout << res << "\n";
    return;
  }

  for (int i = 2; i <= N; i++) {
    prime_decomposition(i);
  }

  ll tmp1 = 0, tmp2 = 0, tmp3 = 0, tmp4 = 0;

  for (auto p : mp) {
    for (auto q : mp) {
      if (p.first == q.first) {
        continue;
      }
      if (p.second >= 24 && q.second >= 2) {
        tmp1++;
      }
    }
  }

  for (auto p : mp) {
    for (auto q : mp) {
      if (p.first == q.first) {
        continue;
      }
      if (p.second >= 14 && q.second >= 4) {
        tmp2++;
      }
    }
  }

  for (auto p : mp) {
    if (p.second >= 74) {
      tmp3++;
    }
  }

  for (auto p : mp) {
    for (auto q : mp) {
      for (auto r : mp) {
        if (p.first == q.first || q.first == r.first || r.first == p.first) {
          continue; // all should be different
        }
        if (p.second >= 4 && q.second >= 4 && r.second >= 2) {
          tmp4++;	
        }
      }
    }
  }

  res += (tmp1 + tmp2 + tmp3 + tmp4 / 2); // tmp4 / 2 bcuz 2 3 or 3 2 have to be included only once
  cout << res << "\n";
  return;
}

int main() {
  cin >> N;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int n, A[50];

//入力値の M から選んだ要素を引いていく再帰関数
int solve(int i, int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1, m) || solve(i+1, m-A[i]);
    return res;
}

int main(){
    int q, M, i;

    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(solve(0, M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 2692
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  string T,S;
  cin>>S>>T;
  
  cout<<T+S<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

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

	return 0;
}

Measured memory_bytes: 384
N = int(input())

X = [list(map(int,input().split())) for _ in range(N)]

t,a,b = 0,0,0
for i in range(N):
	d = abs(a-X[i][1]) + abs(b-X[i][2])
	if d > (X[i][0]-t):
		print("No")
		exit()
	else:
		if ((X[i][0]-t)-d)%2 == 1:
			print("No")
			exit()
		else:
			t = X[i][0]
			a = X[i][1]
			b = X[i][2]
print("Yes")

Measured memory_bytes: 27300
object Main {
  def main (args: Array[String]) {
    val Array(width, height, x, y, r) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
 
    width match{
      case w if (x-r >= 0) && (y-r >=0) && (x+r <= width) && (y+r <= height)  => println("Yes")
      case _     => println("No")
    }
  }
}

Measured memory_bytes: 43988
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <queue>
#include <vector>

#define rep(i,min,max) for(int i=min;i<max;i++)
#define rrep(i,min,max) for(int i=max;i>=min;i--)

using namespace std;

int main(){
  string S;
  int tmp = 0;
  int ans = 0;
  cin >> S;
  for(char c: S){
    if(c == 'A' || c == 'T' || c == 'C' || c == 'G'){
      tmp++;
    }else{
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int G = sc.nextInt();
		int p[] = new int[D];
		int c[] = new int[D];
		for(int i = 0; i < D; i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		int ans = Integer.MAX_VALUE;
		out : for (int i = 0; i < (Math.pow(2, D)); i++) {
			int temp_ans = 0;
			boolean flag[] = new boolean[D];
			Arrays.fill(flag, false);
			int sum = 0;
			for (int j = 0; j < D; j++) {
				if ((1&i>>j) == 1) {
					sum += p[j] * (j + 1) * 100;
					sum += c[j];
					flag[j] = true;
					temp_ans += p[j];
				}
			}
			if(sum >= G) {
				ans = Math.min(ans, temp_ans);
				continue out;
			}
			in : for(int j = 0; j < D; j++) {
				if(!flag[D - 1 - j]) {
					for(int k = 0; k < p[D - 1 - j]; k++) {
						sum += 100 * (D - j);
						temp_ans++;
						if(sum >= G) {
							ans = Math.min(ans, temp_ans);
							break in;
						}
					}
					//break in;
				}
			}
		}
		System.out.println(ans);
	}
}

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

int main()
{
	int64_t h, n;
	cin >> h >> n;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	cout << ((h <= accumulate(as.begin(), as.end(), int64_t(0))) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll res = N;
  for (int i = 0; i <= N; i++) {
    ll count = 0;
    ll t = i;
    while (t > 0) count += t % 6, t /= 6;
    t = N - i;
    while (t > 0) count += t % 9, t /= 9;
    res = min(res, count);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 10005;

vector<int> G[MAX_N];
int kind[MAX_N];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	int t[3];
	cin >> n >> t[0] >> t[1] >> t[2];
	int mn[3];
	vi vec[3];
	rep(i,3){
		vec[i].resize(t[i]);
	}
	rep(i,n){
		kind[i] = -1;
	}
	rep(i,3){
		mn[i] = INF;
		rep(j,t[i]){
			cin >> vec[i][j];
			vec[i][j]--;
			kind[vec[i][j]] = i;
			cmn(mn[i],vec[i][j]);
		}
	}
	int m;
	cin >> m;
	rep(i,m){
		int a,b;
		cin >> a >> b;
		--a,--b;
		if(kind[a] >= 0){
			a = mn[kind[a]];
		}
		if(kind[b] >= 0){
			b = mn[kind[b]];
		}
		G[a].pb(b),G[b].pb(a);
	}
	vp d[3];
	rep(i,3){
		queue<int> que;
		d[i].resize(n,P(INF/10,INF/10));
		d[i][mn[i]] = P(0,mn[i]);
		que.push(mn[i]);
		while(!que.empty()){
			int p = que.front();
			que.pop();
			each(v,G[p]){
				if(d[i][p].fi+1 < d[i][v].fi){
					d[i][v] = P(d[i][p].fi+1,min(d[i][p].se,v));
					que.push(v);
				}else if(d[i][p].fi+1 == d[i][v].fi && d[i][v].se > d[i][p].se){
					d[i][v].se = d[i][p].se;
					que.push(v);
				}
			}
		}
	}
	P ans = P(INF,INF);
	rep(i,n){
		cmn(ans,P(d[0][i].fi+d[1][i].fi+d[2][i].fi,min({d[0][i].se,d[1][i].se,d[2][i].se})));
	}
	cout << ans.fi << " " << ans.se+1 << "\n";
	return 0;
}


Measured memory_bytes: 9068
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner x=new Scanner(System.in);
		int y=x.nextInt();
		int z=x.nextInt();
		int w=x.nextInt();
		if(y==5&&z==7&&w==5) {
			System.out.println("YES");
		}
		else if(y==7&&z==5&&w==5)
		{
			System.out.println("YES");
		}

		else if (y==5&&z==5&&w==7)
		{
			System.out.println("YES");
		}
		else
		{
			System.out.println("NO");
}}}

Measured memory_bytes: 23764
S = gets
A = S[0..1]
B = S[2..3]

month = ['01','02','03','04','05','06','07','08','09','10','11','12']

if month.include?(A)
  if month.include?(B)
    print 'AMBIGUOUS'
  else
    print 'MMYY'
  end
else
  if month.include?(B)
    print 'YYMM'
  else
    print 'NA'
  end
end


Measured memory_bytes: 1788
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		boolean c = false;
		for(int i =0;i<s.length();i++){
			if(s.charAt(i)=='C'){
				c = true;
				continue;
			}
			if(c==true && s.charAt(i)=='F'){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 9044
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
		for(int i=a; i<=b; i++){
			if(Math.abs(i-a)<k || Math.abs(i-b)<k){
				System.out.println(i);
			}else{
				i = b-k;
			}
		}
	}
}

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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    vi a;
    REPR(i, 1, 100) if (A % i + B % i == 0) a.pb(i);

    cout << a[a.size() - K] << endl;

    return 0;
}


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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<vi> a(n, vi(m));
	rep(i, n) rep(j, m) cin >> a[i][j], a[i][j]--;;
	LINE;
	vi curr(n);
	set<int> st;
	int ans = 1e9;
	while (st.size() < m) {
		vi cnt(m);
		rep(i, n) {
			while (st.count(a[i][curr[i]])) curr[i]++;
			cnt[a[i][curr[i]]]++;
		}
		int idx = 0;
		REP(i, 1, m) if (cnt[i] > cnt[idx]) idx = i;
		ans = min(ans, cnt[idx]);
		st.insert(idx);
		dump(idx);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
/*
https://atcoder.jp/contests/dp/tasks/dp_a
*/

#include <iostream>

using namespace std;

int dp[100000];

int h_diff(int*arr, int N,int h){
	if( N == 0 ) {
		dp[N]=0;
		return dp[N];
	}

	if( N == 1 )  {
		dp[N] = abs(arr[N]-arr[N-1]);
		return dp[N];
	}

	int s1 = abs(arr[N] - arr[N-1]) + abs(arr[N-1] - arr[0]);
	int s2 = abs(arr[N] - arr[N-2]) + abs(arr[N-2] - arr[0]);

	if(dp[N-1] == -1)
		dp[N-1] = h_diff(arr,N-1,h);
	if(dp[N-2] == -1)
		dp[N-2] = h_diff(arr,N-2,h);

	dp[N] = min(abs(arr[N] - arr[N-1]) + dp[N-1],abs(arr[N] - arr[N-2])+ dp[N-2]);
	
	return dp[N];

}


int main(){

	int N;
	cin >> N;
	int arr[N];

	for(int i=0;i<N;i++){
		cin >> arr[i];
		dp[i] = -1;
	}
	
	
	cout << h_diff(arr,N-1,0)<< endl;


	return 0;
}

Measured memory_bytes: 13776
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(x) sort(x, x+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
#define pi 3.14159265358979323846
#define REP(i,j,n) for (int i = (int)j; i <=(int)n; i++)
#define REPD(i,n,j) for (int i = (int)n; i>=(int)j; i--)
#define all(vv) vv.begin(),vv.end()
//priority_queue <int, vector<int>, greater<int>> mnheap;

ll arr[200005],brr[200005];
ll ans=0;
int n;
void dfs(int id)
{
    ll val[3];
    REP(i,-1,1)
    {
        val[i+1]=brr[(id+i+n)%n];
    }
    ll used=val[1]/(val[0]+val[2]);
    used=min(used,(brr[id]-arr[id])/(val[0]+val[2]));
    if(used==0)
        return;
    ans+=used;
    brr[id]-=(used*(val[0]+val[2]));
    dfs((id-1+n)%n);
    dfs((id+1+n)%n);
}
int main()
{
    sync;
    cin>>n;
    REP(i,0,n-1)
        cin>>arr[i];
    REP(i,0,n-1)
        cin>>brr[i];
    for(int itr=0;itr<1;itr++)
    {
        REP(i,0,n-1)
            dfs(i);
    }
    REP(i,0,n-1)
    {
        if(arr[i]!=brr[i])
            ans=-1;
    }
    cout<<ans<<endl;
}
/*
3
RRRGGGBBB
*/

Measured memory_bytes: 3328
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	char a,b;
	cin>>a>>b;
	string s1,s2;
	for(int i=0;i<(a-'0');i++){
		s1.pb(b);
	}
	for(int i=0;i<(b-'0');i++){
		s2.pb(a);
	}
	cout<<min(s1,s2);
    return 0;
}
//.........

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

int main()
{
  string s;
  cin >> s;
  int n = s.length();
  vector<int> a(n, 1);

  int i = 0;
  int x = 0;
  int y = 0;

  while (i < n) {
    x = y = 0;

    while (s[i] == 'R') {
      if (i % 2 == 0) {
        x += a[i];
      } else {
        y += a[i];
      }
      a[i] = 0;
      i++;
    }

    if (i % 2 == 0) {
      a[i - 1] += y;
      a[i] += x;
    } else {
      a[i - 1] += x;
      a[i] += y;
    }

    x = y = 0;
    int j = i;

    while (i < n && s[i] == 'L') {
      int t = a[i];
      a[i] = 0;
      if ((i - j) % 2 == 0) {
        a[j] += t;
      } else {
        a[j - 1] += t;
      }
      i++;
    }
  }

  for (int k = 0; k < n; k++) {
    cout << a[k];
    cout << (k == n - 1 ? '\n' : ' ');
  }
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Util{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		int[] XN = ria();
        int X = XN[0];
        int N = XN[1];

        if(N == 0) {
            Console.ReadLine();
            Console.WriteLine(X);
            Console.ReadLine();
            return;
        }

        int[] pArray = ria();
        Array.Sort(pArray);

        List<int> numList = new List<int>();
        int pArrayIndex = 0;
        for(int i = -1; i <= 101; i++){
            if(pArrayIndex < pArray.Length){
                if(i == pArray[pArrayIndex]) {
                    pArrayIndex++;
                    continue;
                }
            }

            numList.Add(i);
        }

        int ans = -1; 
        for(int i = numList.Count - 1; i >= 0; i--)
        {
            if(Math.Abs(X - numList[i]) <= Math.Abs(X - ans)) ans = numList[i];
        }

		Console.WriteLine(ans);
		Console.ReadLine();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
    static int[] generateNums(int num, int N){return Enumerable.Repeat(num, N).ToArray();}
    static int[] generateSuretsu(int N){return Enumerable.Range(0, N).ToArray();}
}

public static class Combination {
	//使い方:int[][] Is = Combination.Enumerate(nums, k, withRepetition:false).ToArray();
    public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> items, int k, bool withRepetition) {
        if (k == 1) {
            foreach (var item in items)
                yield return new T[] { item };
            yield break;
        }
        foreach (var item in items) {
            var leftside = new T[] { item };

            // item よりも前のものを除く （順列と組み合わせの違い)
            // 重複を許さないので、unusedから item そのものも取り除く
            var unused = withRepetition ? items : items.SkipWhile(e => !e.Equals(item)).Skip(1).ToList();

            foreach (var rightside in Enumerate(unused, k - 1, withRepetition)) {
                yield return leftside.Concat(rightside).ToArray();
            }
        }
    }
}


Measured memory_bytes: 27844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll k;
    string s;
    cin>>k>>s;
    
    ll a=0,b=0;
    for(ll i=0;i<k;++i){
        if(s[i]=='R'){
            a++;
        }
    }
    
    for(ll i=0;i<a;++i){
        if(s[i]=='R'){
            b++;
        }
    }
    cout<<a-b;
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main()
{
    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
            
        }
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    } 
    
}



Measured memory_bytes: 3112
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  vector<ll> S(n+1, 0);
  rep(i, n) {
    ll len; cin >> len;
    S[i+1] = S[i] + len;
  }
  ll ans = linf;
  ll L = S[n];
  rep(i, n+1) {
    ll left = S[i];
    ll right = L - S[i];
    chmin(ans, abs(left - right));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792