akhauriyash/Code-Regression huggingface dataset:
fun main(args : Array<String>) {
    val n = readLine()!!

    if (n.toLong() < 10) {
        println(n)
        return
    }

    if (n.all { it == '9' }) {
        println(9 * n.length)
        return
    }

    if (n.takeLast(n.length-1).all { it == '9' }) {
        println(n[0].toString().toInt() + 9*(n.length-1))
        return
    }

    println(n[0].toString().toInt()-1 + 9*(n.length-1))
}

Measured memory_bytes: 33460
#include <stdio.h>

int main(){
  char s[100];
  int i=0;
  int flag;

  scanf("%s",&s);
  while(s[i]!='\0'){
    flag=0;
    if((i+1)%2){
      if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
        flag=1;
      }
    }else{
      if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
        flag=1;
      }
    }
    if(!flag){
      printf("No\n");
      return 0;
    }
    i++;
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
using namespace std;
int main()
{
	vector<int> b;
	set<int> a;
	int  c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r=0, s, t, u;
	for (int x = 0; 28>x; x++)
	{
		cin >> u;
		a.insert(u);
	}
	set<int>::iterator it = a.begin();
	for (int z = 0; 30>z; z++)
	{
		b.push_back(z);
	}
	d = min(d, e);

	while (it != a.end())
	{
		r++;
		it = a.find(r);
		//a.erase(r-1);
	}
	cout << r << endl;
	it--;
	k = r;
	while (it != a.end())
	{
		it = a.find(k+1);
		k++;

	}
	cout << k << endl;

	return 0;
}

Measured memory_bytes: 1220
import heapq
import math

N,M = map(int, input().split())
A = list(map(lambda x : int(x) * -1, input().split()))

heapq.heapify(A)
 
for i in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, int(tmp / 2))
print(-sum(A))

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

#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, n, m) for(int (i) = (n); (i) <= (m); ++(i))

int main(){
  int N;
  cin >> N;
  cout << (N+1) / 2 << endl;
  return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  
  vector<int>c(N);
  int a,b;
  for(int i=0; i<M; i++){
  cin>>a>>b;
    c[a-1]++;
    c[b-1]++; }
  for(int i=0; i<N; i++){
   cout<<c[i]<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N, M;
  cin >> N >> M;
  vvll G(N, vll(0));
  for(int i = 0; i < M; i++){
    ll a, b;
    cin >> a >> b;
    a--; b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  vector<bool> flag(N, false);
  vll d(N);
  flag.at(0) = true;
  d.at(0) = 0;
  queue<ll> que;
  que.push(0);
  while(!que.empty()){
    ll x = que.front(); que.pop();

    for(int i = 0; i < G.at(x).size(); i++){
      if(flag.at(G.at(x).at(i))) continue;
      d.at(G.at(x).at(i)) = d.at(x) + 1;
      flag.at(G.at(x).at(i)) = true;
      que.push(G.at(x).at(i));
    }
  }
  if(d.at(N-1) == 2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  map<long, long> MA;
  for (long i = 0; i < N; i++) {
    MA[A.at(i)]++;
  }
  long sum = 0;
  for (auto ma : MA) sum += ma.second * (ma.second - 1) / 2;
  for (long i = 0; i < N; i++) {
    long tmp = MA[A.at(i)];
    long tmp1 = tmp * (tmp - 1) / 2;
    long tmp2 = (tmp - 1) * (tmp - 2) / 2;
    cout << sum - tmp1 + tmp2 << "\n";
  }
}

Measured memory_bytes: 11008
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		
		String S = sc.next();
		String T = sc.next();
		
		sc.close();
		
		for (int i = 0; i < N; i++) {
			
			System.out.print(S.charAt(i));
			System.out.print(T.charAt(i));
		}
	}

}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }

struct unionfind {
    vector<int> par;
    vector<int> sizes;

    unionfind(int n) : par(n),sizes(n,1){
        rep(i,0,n) par[i] = i;
    }

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

    void unite(int x,int y){
        x = root(x);
        y = root(y);

        if(x == y) return;

        if(sizes[x] < sizes[y] ) swap(x,y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;

        return;
    }

    bool same(int x,int y){
        return root(x) == root(y);
    }

    int size(int x){
        return sizes[root(x)];
    }
};

int main(){
    ll n;
    cin >> n;
    ll a[n] = {};
    P b[n] = {};
    rep(i,0,n){
        cin >> a[i];
        b[i] = P(a[i],i);
    }
    sort(b,b+n);
    vector<P> vec;
    if(b[n-1].fs < 0){
        rep(k,0,n-1){
            ll i = n-k-1;
            if(a[i] < a[i-1]){
                a[i-1] += a[i];
                vec.push_back(P(i,i-1));
            }
        }
    }
    else if(b[0].fs >= 0){
        rep(i,0,n-1){
            if(a[i+1] < a[i]){
                a[i+1] += a[i];
                vec.push_back(P(i,i+1));
            }
        }
    }
    else if(abs(b[0].fs) > abs(b[n-1].fs)){
        P temp = b[0]; // < 0

        rep(i,0,n){
            vec.push_back(P(temp.sc,i));
            a[i] += a[temp.sc];
        }

        rep(k,0,n-1){
            ll i = n-k-1;
            if(a[i] < a[i-1]){
                a[i-1] += a[i];
                vec.push_back(P(i,i-1));
            }
        }
    }
    else{
        P temp = b[n-1];
        rep(i,0,n){
            vec.push_back(P(temp.sc,i));
            a[i] += a[temp.sc];
        }
        rep(i,0,n-1){
            if(a[i+1] < a[i]){
                a[i+1] += a[i];
                vec.push_back(P(i,i+1));
            }
        }
    }

    cout << sz(vec) << endl;
    rep(i,0,sz(vec)){
        cout << vec[i].fs + 1 << " " << vec[i].sc + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,X;
  cin >> K >> X;
  
  int min = X - K + 1,max = X + K - 1;
  for(int i = min; i <= max;  i++){
  	cout << i << " ";
  }
  
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

vector<int> loop;
int check[1001];
bool isEnd = false;

int dfs(vector<vector<int>>& E, int node){
    check[node] = 1;

    for(int nextNode: E[node]){

        if(isEnd){
            break;
        }

        if(check[nextNode] == -1){
            int goal = dfs(E, nextNode);
            if(goal != -1){
                loop.push_back(node);
                if(node == goal){
                    isEnd = true;
                    return -1;    
                }
                return goal;
            }
        }
        else if(check[nextNode] == 1){
            loop.push_back(node);
            return nextNode;
        }
    }

    check[node] = 0;
    return -1;
}

int main(){

    int N, M;
    cin >> N >> M;

    vector<vector<int>> E(N);

    int a, b;
    for(int i = 0; i < M; i++){
        cin >> a >> b;
        E[a - 1].push_back(b - 1);
    }

    for(int i = 0; i < N; i++){
        loop.clear();
        memset(check, -1, sizeof(check));
        dfs(E, i);

        if((int)loop.size() != 0){
            break;
        }
    }

    if((int)loop.size() == 0){
        cout << -1 << endl; 
    }
    else{

        int loopSize = (int)loop.size();

        reverse(loop.begin(), loop.end());
        vector<int> nextLoopNode(N, -1);
        for(int i = 0; i < loopSize; i++){
            nextLoopNode[loop[i]] = loop[(i + 1) % loopSize];
        }

        int loopStart = loop[0];
        int tempPos = loop[1];
        while(loopStart != tempPos){
            int nextPos = nextLoopNode[tempPos];
            for(int nextNode: E[tempPos]){
                if(nextLoopNode[nextNode] == -1){
                    continue;
                }

                if(nextPos == nextNode){
                    continue;
                }

                int deletePos = nextLoopNode[tempPos];
                while(deletePos != nextNode){
                    int temp = nextLoopNode[deletePos];
                    nextLoopNode[deletePos] = -1;
                    deletePos = temp;
                }
                loopStart = tempPos;
                nextLoopNode[tempPos] = nextNode;
            }

            tempPos = nextLoopNode[tempPos];
        }

        vector<int> ans;
        ans.push_back(loopStart);
        tempPos = nextLoopNode[loopStart];
        while(tempPos != loopStart){
            ans.push_back(tempPos);
            tempPos = nextLoopNode[tempPos];
        }

        cout << (int)ans.size() << endl;
        for(int num: ans){
            cout << num + 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

bool solve(int n, int m) {
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  for (int i = 0; i < n; i++) {
    if (g[i].size() % 2) {
      return false;
    }
  }
  vector<int> big;
  for (int i = 0; i < n; i++) {
    if (g[i].size() >= 6) {
      return true;
    }
    if (g[i].size() == 4) {
      big.push_back(i);
    }
  }
  if (big.size() <= 1) return false;

  for (int i = 0; i < n; i++) {
    if (g[i].size() == 2) {
      int a = g[i][0];
      int b = g[i][1];
      *find(g[a].begin(), g[a].end(), i) = b;
      *find(g[b].begin(), g[b].end(), i) = a;
    }
  }

  for (int v : big) {
    if (find(g[v].begin(), g[v].end(), v) != g[v].end()) {
      return true;
    }
    if (big.size() > 2) {
      sort(g[v].begin(), g[v].end());
      if (unique(g[v].begin(), g[v].end()) != g[v].end()) {
        return true;
      }
    }
  }

  if (big.size() == 2) {
    return false;
  }

  vector<int> d(n, -1);
  vector<int> p(n, -1);
  queue<int> q;
  d[big[0]] = 0;
  q.push(big[0]);

  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int to : g[v]) {
      if (d[to] == -1) {
        d[to] = d[v] + 1;
        q.push(to);
      } else if (to != p[v] && d[to] + d[v] + 1 < (int)big.size()) {
        return true;
      }
    }
  }

  return false;
}

int main() {
#ifdef LOCAL
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif

  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    if (solve(n, m)) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }
  return 0;
}


Measured memory_bytes: 5760
(defun split (string &key (delimiterp #'(lambda (c) (char= c #\Space))))
  (loop :for beg = (position-if-not delimiterp string)
        :then (position-if-not delimiterp string :start (1+ end))
        :for end = (and beg (position-if delimiterp string :start beg))
        :when beg :collect (subseq string beg end)
        :while end))

(defun calc-area-diff-1 (h w)
  (case (mod h 3)
    (0 0)
    (t w)))

(defun calc-area-diff-2 (h w)
  (loop :for i :from 1 :to (floor (+ 1/2 (/ h 2)))
        :for hb = (- h i)
        :with wb = (floor (/ w 2))
        :for s1 = (* i w)
        :for s2 = (* hb wb)
        :for s3 = (* hb (- w wb))
        :minimizing (- (max s1 s2 s3) (min s1 s2 s3))))

(destructuring-bind (h w) (mapcar #'parse-integer (split (read-line)))
  (format t "~a~%"
          (min (calc-area-diff-1 h w)
               (calc-area-diff-1 w h)
               (calc-area-diff-2 h w)
               (calc-area-diff-2 w h))))


Measured memory_bytes: 18660
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=924844033;
#define N 1055050

ll n,m,k,l;
ll a[N];
ll r[N];
ll suf[N],pre[N];
ll dp[4000][4000];
main(){
    string s;
    cin>>s;
    n=s.size();
    rep2(i,1,n){
        a[i]=(s[i-1]-'0');
        r[i]+=r[i-1]+a[i];
    }
    rep2(i,n+1,2*n+1)r[i]=r[i-1];
    dp[0][0]=1;
    rep2(i,1,n*2){
        rep(j,i+1){
            if(r[i]>=j&&i*2-r[i]>=i-j)
            dp[i][j]=dp[i-1][j]+(j-1ll>=0ll?dp[i-1][j-1]:0);
            dp[i][j]%=998244353ll;
        }
    }
    ll sum=0;
    cout<<dp[n*2][r[n]];
}   

Measured memory_bytes: 129536
S=int(input())

Thou=S//1000
tmp=S-Thou*1000
Hund=tmp//100
tmp=tmp-Hund*100
Ten=tmp//10
One=tmp%10

if Thou==Hund:
  print("Bad")
else:
  if Hund == Ten:
    print("Bad")
  else:
    if Ten==One:
      print("Bad")
    else:
      print("Good")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;


int main(){


    int N;
    cin >> N;

    ll minId = -1;
    ll minP = 1e10;
    ll maxId = -1;
    ll maxP = 0;



    for(int i = 0; i < N; i++){
        ll a, b;
        cin >> a >> b;
        if(b > maxP){
            maxP = b;
            maxId = a;
        }
        if(b <= minP){
            minP = b;
            minId = a;
        }

    }

    cout << minId + minP << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>p(N);
	for (int i = 0;i < N;++i) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());
	int ans = 0;
	p[N - 1] /= 2;
	for (int i = 0;i < N;++i) {
		ans += p[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
   
// ここから
function main(){
  var primeNumbers = calcPrimeNumbers();
  for(var i = 0, len = input.length - 1; i < len; i++){
    console.log(primeNumbers[input[i] - 0]);
  }
  
    
}
  
function calcPrimeNumbers(){
  var max = 999999;
  var primeNumbers = new Int8Array(max + 1);
  
  // 除外
  primeNumbers[0] = primeNumbers[1] = 1;
  for(var i = 2, maxI = ~~Math.sqrt(max); i <= maxI; i++){
    if(primeNumbers[i]){
      continue;
    }
      
    for(var j = (i<<1); j <= max; j+=i){
      primeNumbers[j] = 1;
    }
  }
  
  var primeNums = new Int32Array(max + 1);
  var sum = 0;
  for(var i = 1; i <= max; i++){
    sum = primeNums[i] += sum + (!primeNumbers[i]);
  }
    
  return primeNums;
}

Measured memory_bytes: 13636
x,y = map(int,input().split())

def divs(n:int):
    divs = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    return divs

print (max(set(divs(x))&set(divs(y))))



Measured memory_bytes: 5652
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(void){
    ll n;cin >> n;
    if(n%2==1){
        cout << 0 << endl;
    }else{
        ll t = 0,f = 0;
        ll c = 1;
        for(ll i = 2;i <= n;i*=2){
            t += (n / i);
        }
        c = 1;
        for(ll i = 10;i <= n;i*= 5){
            f += n/i;
        }
        //cout << t << "  " << f << endl;
        cout << min(t,f) << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
 
using namespace std;
const double EPS = 1e-10;
int q;
int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
 
struct Point {
    double x, y;
    Point(double x = 0, double y = 0) : x(x), y(y) { }
    Point operator+(Point p) {
        return Point(x + p.x, y + p.y);
   }
    Point operator-(Point p) {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(double k) {
        return Point(x * k, y * k);
    }
    Point operator/(double k) {
        return Point(x / k, y / k);
    }
    bool operator==(Point p) {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
};
typedef Point Vector;
int dcmp(double x) {
    if (fabs(x) < EPS) return 0;
    return x < 0 ? -1 : 1;
}
double Dot(Vector a, Vector b) {
    return a.x * b.x + a.y * b.y;
}
double Cross(Vector a, Vector b) {
    return a.x * b.y - a.y * b.x;
}
double Length(Vector a) {
    return sqrt(Dot(a, a));
}
double DistancePS(Point p, Point a, Point b) {
    if (a == b) return Length(p - a);
    Vector v1 = b - a, v2 = p - a, v3 = p - b;
    if (Dot(v1, v2) < 0) return Length(v2);
    if (Dot(v1, v3) > 0) return Length(v3);
    return fabs(Cross(v1, v2)) / Length(v1);
}
bool IntersectSS(Point a1, Point a2, Point b1, Point b2) {
    double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1);
    double c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
    return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
 double DistanceSS(Point a1, Point a2, Point b1, Point b2) {
    if (IntersectSS(a1, a2, b1, b2)) return 0.0;
    return min(min(DistancePS(a1, b1, b2), DistancePS(a2, b1, b2)),
               min(DistancePS(b1, a1, a2), DistancePS(b2, a1, a2)));
}
 
int main() {
    cin >> q;
    while (q--) {
        cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;
        Point a1(xp0, yp0);
        Point a2(xp1, yp1);
        Point b1(xp2, yp2);
        Point b2(xp3, yp3);
        printf("%.10lf\n", DistanceSS(a1, a2, b1, b2));
    }
    return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main(){
    int h, w;
    cin>>h>>w;
    vector<vector<bool> > v(h, vector<bool>(w));
    int n = h*w;
    for(int i = 0; i<h; i++){
        for(int j = 0; j<w; j++){
            char c;
            cin>>c;
            if(c == '.')v[i][j] = true;
            else v[i][j] = false;
        }
    }
    vector<vector<int> > dist(n, vector<int> (n, INT_MAX));
    for(int i = 0; i<n; i++){
        dist[i][i] = 0;
    }
    for(int i = 0; i<n;i++){
        int row = i/w;
        int col = i%w;
        if(!v[row][col])continue;
        if(row > 0 && v[row-1][col]){
            dist[i][i-w] = 1;
            //dist[i-w][i] = 1;
        }
        if(row < h-1 && v[row + 1][col]){
            dist[i][i+w] = 1;
            //dist[i+w][i] = 1;
        }
        if(col > 0 && v[row][col-1]){
            dist[i][i-1] = 1;
            //dist[i-1][i] = 1;
        }
        if(col < w-1 && v[row][col+1]){
            dist[i][i+1] = 1;
            //dist[i+1][i] = 1;
        }
    }
    for(int k = 0; k<n; k++){
        for(int i = 0; i<n; i++){
            for(int j = 0;j<n; j++){
                if(dist[i][k] == INT_MAX || dist[k][j] == INT_MAX)continue;
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int max1 = 1;
    for(int i = 0; i<n; i++){
        for(int j = 0; j<n; j++){
            if(dist[i][j] == INT_MAX)continue;
            max1 = max(max1, dist[i][j]);
        }
    }
    cout<<max1<<endl;
    return 0;
}

Measured memory_bytes: 896
N = int(input())
A = sorted(list(map(int, input().split())))
m = A[-1]
B = [0] * m
for a in A:
  B[a - 1] += 1
  if B[a - 1] == 1:
    for j in range(a * 2, m + 1, a):
      B[j - 1] = 2
print(B.count(1))

Measured memory_bytes: 32384
n = int(input())
lists = [list(input()) for _ in range(n)]
lists_2 = [lists[0]]
for i in range(1,n):
  if lists[i-1][-1] == lists[i][0]:
    if lists[i] in lists_2:
      print("No")
      exit()
    else:
      lists_2.append(lists[i])
    if i == n-1:
      print("Yes")
    else:
      continue
  else:
    print("No")
    exit()

Measured memory_bytes: 9140
#include <stdio.h>
 
int main(){
    int x, y, s, d, p[10][10] = {0};

    while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
        switch(s){
            case 3 :
                if(x - 2 >= 0) p[x - 2][y]++;
                if(x + 2 <= 9) p[x + 2][y]++;
                if(y - 2 >= 0) p[x][y - 2]++;
                if(y + 2 <= 9) p[x][y + 2]++;
                
            case 2 :
                if(x - 1 >= 0 && y - 1 >= 0) p[x - 1][y - 1]++;
                if(x - 1 >= 0 && y + 1 <= 9) p[x - 1][y + 1]++;
                if(x + 1 <= 9 && y - 1 >= 0) p[x + 1][y - 1]++;
                if(x + 1 <= 9 && y + 1 <= 9) p[x + 1][y + 1]++;
                
            case 1 :
                if(x - 1 >= 0) p[x - 1][y]++;
                if(x + 1 <= 9) p[x + 1][y]++;
                if(y - 1 >= 0) p[x][y - 1]++;
                if(y + 1 <= 9) p[x][y + 1]++;
                p[x][y]++;
        }
    }
    
    s = d = 0;
    
    for(x = 0; x < 10; x++)
        for(y = 0; y < 10; y++)
            if     (p[x][y] == 0) s++;
            else if(p[x][y] > d)  d = p[x][y];
            
    printf("%d\n%d\n", s, d);
 
    return 0;
}

Measured memory_bytes: 600
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, k int
	Fscan(in, &n, &k)
	to := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &to[i])
	}

	before := []int{}
	cycle := []int{}
	vis := make([]int, n+1)
	for v := 1; vis[v]<2; v = to[v] {
		if vis[v] == 1 {
			cycle = append(cycle, v)
		} else {
			before = append(before, v)
		}

		vis[v]++
	}
	if k <len(before) {
		Fprintln(out, before[k])
	} else {
		k-=len(before)
		Fprintln(out, cycle[k%len(cycle)])

	}

}

func main() { run(os.Stdin, os.Stdout) }


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string s, t;
	cin >> s >> t;

	if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

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

const ll MAX_N = 200;
int n, W;
ll w[MAX_N], v[MAX_N];

void solve() {
    ll dp[n + 100][half_inf + 10];
    rep(i, n) {
        rep(j, W + 1) {
            if (j >= w[i]) {
                chmax(dp[i + 1][j], max(dp[i][j], dp[i][j - w[i]] + v[i]));
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][W] << endl;
}

int main() {
    cin >> n >> W;
    rep(i, n)cin >> w[i] >> v[i];
    solve();
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long N, W, ans[100002] = {0}, i, j, V[101] = {0}, wet[100001] = {0};
	cin >> N >> W;
	for(i = 0; i < N; i++)
		cin >> wet[i] >> V[i];
	for(i = 0; i <= W; i++)
	    ans[i] = -1;
	ans[0] = 0;
	for(i = 0; i < N; i++)
	{
		for(j = W; j >= 0; j--)
		{
		    if(j - wet[i] >= 0 && ans[j - wet[i]] != -1)
		    ans[j] = max(ans[j], ans[j - wet[i]] + V[i]);
		}
	}
	sort(ans, ans + W + 1);
	cout << ans[W];
	return 0;
}

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

const int N=1e5+5;
int n,par[N],r[N];
vector<tuple<int,int,int>> p;
vector<tuple<ll,int,int>> e;

int getroot(int u){
	return u==par[u]?u:par[u]=getroot(par[u]);
}

bool joint(int u,int v){
	u=getroot(u);
	v=getroot(v);
	if(u==v) return false;
	if(r[u]>r[v]) r[u]+=r[v],par[v]=u;
	else r[v]+=r[u],par[u]=v;
	return true;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		int x,y;
		cin>>x>>y;
		p.emplace_back(x,y,i);
	}
	sort(p.begin(),p.end());
	for(int i=1;i<n;++i){
		int dist=get<0>(p[i])-get<0>(p[i-1]);
		int u=get<2>(p[i]);
		int v=get<2>(p[i-1]);
		e.emplace_back(dist,u,v);
	}
	sort(p.begin(),p.end(),[](const tuple<int,int,int> &L,const tuple<int,int,int> &R){
				return get<1>(L)<get<1>(R);
			});
	for(int i=1;i<n;++i){
		int dist=get<1>(p[i])-get<1>(p[i-1]);
		int u=get<2>(p[i]);
		int v=get<2>(p[i-1]);
		e.emplace_back(dist,u,v);
	}
	for(int i=0;i<n;++i) 
		par[i]=i,r[i]=1;
	sort(e.begin(),e.end());
	ll res=0;
	for(auto it:e){
		ll d,u,v;
		tie(d,u,v)=it;
		//cerr<<d<<' '<<u<<' '<<v<<'\n';
		if(joint(u,v)) 
			res+=d;
	}
	cout<<res<<'\n';
}




Measured memory_bytes: 9432
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  string ss="abcdefghijklmnopqrstuvwxyz";
  reverse(ALL(ss));
  if(s.size()==26){
    if(s==ss)cout<<-1<<endl;
    else{
      ll po;
      for(int i=s.size()-1;i>0;i--){
	if(s[i]-s[i-1] > 0){
	  po=i-1;
	  break;
	}
      }
      char hoge='z';
      for(int i=s.size()-1;i>po;i--){
	if(s[i]>s[po]){
	  hoge=min(hoge,s[i]);
	}
      }
      for(int i=0;i<po;i++)
	cout<<s[i];
      cout<<hoge<<endl;
    }
  }else{
    bool alpha[30]={};
    for(int i=0;i<s.size();i++)
      alpha[s[i]-'a']=true;
    for(int i=0;i<26;i++)
      if(alpha[i]==false){
	cout<<s<<(char)('a'+i)<<endl;
	return 0;
      }
  }
  return 0;
}


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

typedef long long ll;
#define mod 1000000007

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpll;

ll dp[101][100001];

void solve(vector<ll> &candies, ll k, ll n) {
    for(int j=0; j<=k; j++)
        dp[0][j]=0;
    for(int i=0; i<=n; i++)
        dp[i][0]=1;

    for(int j=1; j<=k; j++){
        if(candies[0] >= j)
            dp[1][j]=1;
        else
            dp[1][j]=0;
    }

    for(int i=2; i<=n; i++) {
        for(int j=1; j<=k; j++) {
            dp[i][j] = (mod + dp[i][j-1]%mod + dp[i-1][j]%mod - ((j-1-candies[i-1])>=0 ? dp[i-1][j-1-candies[i-1]] : 0)%mod )%mod;
        }
    }

    // for(int i=0; i<=n; i++) {
    //     for(int j=0; j<=k; j++) {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    cout<<dp[n][k]<<endl;
    return;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;  cin>>n;
    ll k;  cin>>k;
    vector<ll> candies(n);
    for(int i=0; i<n; i++) {
        cin>>candies[i];
    }
	// memset(dp, -1, sizeof dp);
    solve(candies, k, n);

	return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

const int64_t mod = 1000000007;

inline int64_t aggr(const vector<int64_t> & a)
{
  const size_t size = a.size();
  int64_t out = 0;
  for(size_t i = 0; i + 1 < size; ++i)
  {
    const int64_t dx = a[i + 1] - a[i];
    const int64_t k = ((int64_t) (i + 1)) * ((int64_t) (size - i - 1)) % mod;
    const int64_t inc = dx * k % mod;
    out += inc;
    out %= mod;
  }

  return out % mod;
}

int64_t arc071b()
{
  size_t n, m;
  cin >> n >> m;
  vector<int64_t> a(n), b(m);
  cin >> a >> b;

  sort(begin(a), end(a));
  sort(begin(b), end(b));

  const auto x = aggr(a);
  const auto y = aggr(b);

  // DEBUG(x);
  // DEBUG(y);

  return x * y % mod;
}

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << arc071b() << '\n';

  return EXIT_SUCCESS;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
vector<int> vec;
bool cmp(int a,int b)
{
        return a>b;
}
int main()
{
        int N,temp,ans=0,minone,one = 0;
        cin>>N;
        for(int i=0;i<N;i++)
        {
                scanf("%d",&temp);

                if(i==0)
                {
                        vec.push_back(temp);
                        minone = temp;
                        ans++;
                }
                else
                {
                        if(temp<=minone)
                        {
                                vec.push_back(temp);
                                minone = temp;
                                one++;
                                ans++;
                        }
                        else
                        {
                                for(int i=0;i<=one;i++)
                                {
                                        if(vec[i]<temp)
                                        {
                                                vec[i] = temp;
                                                if(i==one)      minone = temp;
                                                break;
                                        }
                                }
                        }
                }

                //sort(vec.begin(),vec.end(),cmp);

        }
        cout<<ans<<endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

//-------------------ここから回答する-----------------------

void solve(void)
{
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, s.length())
    {
        mp[s[i]]++;
    }
    for (auto i : mp)
    {
        if (i.second % 2 == 1)
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    return;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3548
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var a = Read();
        var b = Read();
        Console.WriteLine(GetAccumXOR(b) ^ GetAccumXOR(a == 0 ? 0 : a - 1));
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long GetAccumXOR(long end)
    {
        return (end % 2 == 0 ? end : 0) | (((end & 1) + ((end & 2) >> 1)) & 1);
    }

    static readonly TextReader In = Console.In;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    static long Read()
    {
        long res = 0;
        int next = In.Read();
        while (48 > next || next > 57) next = In.Read();
        while (48 <= next && next <= 57)
        {
            res = res * 10 + next - 48;
            next = In.Read();
        }
        return res;
    }
}


Measured memory_bytes: 13140
from itertools import product
N = int(input())
A = list(map(int, input().split()))
r = 0
for pp in product((-1, 0, 1), repeat=N):
    s = 1
    for p, a in zip(pp, A):
        s *= a+p
    if s % 2 == 0:
        r += 1
print(r)


Measured memory_bytes: 9108
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		
		System.out.println(levenshteinDistance(sc.next().toCharArray(),sc.next().toCharArray()));
		
	}
	
	static int levenshteinDistance(char[] x, char[] y){
		int[][] dp = new int[x.length+1][y.length+1];

		for(int i=0;i<x.length+1;i++){
			dp[i][0] = i;
		}
		for(int i=1;i<y.length+1;i++){
			dp[0][i] = i;
		}
		
		for(int i=1;i<x.length+1;i++){
			for(int j=1;j<y.length+1;j++){
				if(x[i-1]==y[j-1]){
					dp[i][j] = Math.min(Math.min(dp[i-1][j-1],dp[i-1][j]+1),dp[i][j-1]+1);
				}
				else{
					dp[i][j] = Math.min(Math.min(dp[i-1][j-1]+1,dp[i-1][j]+1),dp[i][j-1]+1);
				}
			}
		}
		
		return dp[x.length][y.length];
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 29112
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<int> a(n);
  REP(i,n) a[i] = getInt();

  sort(a.begin(), a.end());

  const int t = a[n - 1];
  int b = 0;
  REP(i,n-1) if(abs(2 * b - t) >= abs(2 * a[i] - t))
    b = a[i];

  printf("%d %d\n", t, b);

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  int Ai;
  int cnt=0;
  for(int i=1;i<=N;i++){
    cin>>Ai;
    if(Ai!=i-cnt)
      cnt++;
  }
  
  if(cnt==N)
    cout<<-1<<endl;
  else
    cout<<cnt<<endl;
  
  return 0;
}

Measured memory_bytes: 256
def main():
    N,K=map(int,input().split())
    h=list(map(int,input().split()))
    dp=[10**10]*N
    dp[0]=0
    for i in range(N):
        for j in range(1,min(K+1,N-i)):
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp[N-1])

if __name__=="__main__":
    main()

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, c, d;

int main() {
	cin >> a >> b >> c >> d;
	a += b;
	c += d;
	
	
	cout << (a == c ? "Balanced" : (a > c ? "Left" : "Right")) << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { 0 }
    val data = Array(n) { mutableListOf<Pair<Int, Int>>() }
    for (i in 0 until n) {
        a[i] = sc.nextInt()
        for (j in 0 until a[i]) {
            data[i].add(sc.nextInt() - 1 to sc.nextInt())
        }
    }
    var ans = 0
    for (i in 0 until 1.shl(n)) {
        var count = 0
        val honest = Array(n) { false }
        for (j in 0 until n) {
            if ((1.shl(j) and i) != 0) {
                honest[j] = true
                count++
            }
        }
        var ok = true
        for (j in 0 until n) {
            if (!honest[j]) continue
            for ((x, y) in data[j]) {
                if ((honest[x] && y == 0) || (!honest[x] && y == 1)) {
                    ok = false
                    break
                }
            }
        }
        if (ok) {
            ans = Math.max(ans, count)
        }
    }
    println(ans)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 38932
def mul(a, b, n, m)
  c = []
  for i in 0..(n-1)
    ai = a[i]
    c.push(dot(ai, b, m))
  end
  return c
end

def dot(x, y, m)
  dot_xy_array = []
  dot_xy = 0
  for i in 0..(m-1)
    dot_xy_array.push(x[i] * y[i])
  end
  dot_xy = 0
  dot_xy_array.each do |i|
    dot_xy += i
  end
  return dot_xy
end

def mul_matrix(arrayA, arrayB, n, m, l)
  mul_matrix_array = []
  for i in 0..(l-1)
    mul_matrix_array.push(mul(arrayA, arrayB[i], n, m))
  end
  return mul_matrix_array
end

input_nml_array = gets.chomp.split.map(&:to_i)
n = input_nml_array[0]
m = input_nml_array[1]
l = input_nml_array[2]
input_a_arrays = []
n.times do
  input_a_array = gets.chomp.split.map(&:to_i)
  input_a_arrays.push(input_a_array)
end
input_b_arrays = []
m.times do
  input_b_array = gets.chomp.split.map(&:to_i)
  input_b_arrays.push(input_b_array)
end
input_b_column_vector_array = []
for i in 0..(l-1)
  tmp = []
    for j in 0..(m-1)
      tmp.push(input_b_arrays[j][i])
    end
    input_b_column_vector_array.push(tmp)
end

answers = mul_matrix(input_a_arrays, input_b_column_vector_array, n, m, l)
for i in 0..(n-1)
  for j in 0..(l-1)
    print answers[j][i]
    if j != (l-1)
      print " "
    else
      print "\n"
    end
  end
end

Measured memory_bytes: 19276
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    vector<int> c(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(v[i]>c[i])ans+=v[i]-c[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256