akhauriyash/Code-Regression huggingface dataset:
import scala.collection.mutable.{TreeSet, TreeMap}

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h, w = sc.nextInt()
  val ab = Array.fill(h)((sc.nextInt()-1, sc.nextInt()))

  val s = TreeMap[Int, Int]()
  val v = TreeSet[(Int, Int)]()
  for (i <- 0 until w) {
    s += i -> i
    v += ((0, i))
  }

  val pw = new java.io.PrintWriter(Console.out)
  for (k <- 0 until h) {
    val (a, b) = ab(k)
    val it = s.keysIteratorFrom(a)
    var mr = -1
    var continue = true
    while (it.hasNext && continue) {
      val e = it.next()
      if (e > b) {
        continue = false
      } else {
        mr = mr.max(s(e))
        v -= ((e - s(e), e))
        s -= e
      }
    }

    if (mr != -1 && b < w) {
      s += b -> mr
      v += ((b - mr, b))
    }

    if (v.isEmpty) {
      pw.println(-1)
    } else {
      pw.println(v.head._1 + k + 1)
    }
  }
  pw.flush()
}


Measured memory_bytes: 107860
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

int main()
{
  unsigned long long n, m;
  cin >> n >> m;
  if(min(n, m) == 1) cout << 1 << endl;
  else cout << ((n + 1) / 2) * ((m + 1) / 2) + (n / 2) * (m / 2) << endl;
  return 0;
}


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

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

using namespace std;

int h, w;
int c[10][10];
int p[10];

int main(){
    cin >> h >> w;
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j];
        }
    }
    rep(i, h){
        rep(j, w){
            int a;
            cin >> a;
            if(a >= 0){
                ++p[a];
            }
        }
    }
    rep(k, 10){
        rep(i, 10){
            rep(j, 10){
                c[i][j] = min(c[i][k] + c[k][j], c[i][j]);
            }
        }
    }
    int ans = 0;
    rep(i, 10){
        ans += c[i][1] * p[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
 string s;
  cin >> s ;
  
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)){
    cout << "Yes"<< endl;
  }
    
    else{
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

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

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

ll powll ( ll x, ll n ) {
    if ( n == 0 ) return 1ll;
    return x*powll(x, n-1);
}

int dp[100100];
int main()
{
    int n;

    cin >> n;

    set<ll> v;
    rep(i, 12) {
        v.insert(powll(6, i));
        v.insert(powll(9, i));
    }
    
    rep(i, n+10) dp[i] = IINF;

    dp[0] = 0;
    rep(i, n) {
        for( auto l : v ) {
            if ( i+l <= 100010 ) {
                dp[i+l] = min(dp[i+l], dp[i]+1);
            }
        }
    }

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
struct rect{
  int l,t,r,b;
  rect(){}
  rect(int l,int t,int r,int b):l(l),t(t),r(r),b(b){}
};
typedef pair<int,int> P;
int main(){
  int n;
  while(cin>>n,n){
    int i,j,k=0,a,b,c,f,inf=1<<25;
    vector<int> xs,ys;
    vector<rect> v;
    rect r;
    for(i=0;i<n;i++){
      cin>>r.l>>r.t>>r.r>>r.b;
      xs.push_back(r.l);
      xs.push_back(r.r);
      ys.push_back(r.t);
      ys.push_back(r.b);
      v.push_back(r);
    }
    xs.push_back(-inf);xs.push_back(inf);
    ys.push_back(-inf);ys.push_back(inf);
    sort(xs.begin(),xs.end());
    sort(ys.begin(),ys.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    ys.erase(unique(ys.begin(),ys.end()),ys.end());
    map<int,int> xm,ym;
    for(i=0;i<xs.size();i++) xm[xs[i]]=i;
    for(i=0;i<ys.size();i++) ym[ys[i]]=i;
    bool ex[xs.size()+1][ys.size()+1],ey[xs.size()+1][ys.size()+1];
    memset(ex,0,sizeof(ex));
    memset(ey,0,sizeof(ey));
    for(i=0;i<n;i++){
      r=v[i];
      for(j=xm[r.l];j<xm[r.r];j++) ex[j][ym[r.b]]=ex[j][ym[r.t]]=1;
      for(j=ym[r.b];j<ym[r.t];j++) ey[xm[r.l]][j]=ey[xm[r.r]][j]=1;
    }
    bool u[xs.size()+1][ys.size()+1];
    memset(u,0,sizeof(u));
    for(i=0;i<xs.size();i++){
      for(j=0;j<ys.size();j++){
	if(u[i][j]) continue;
	queue<P> q;
	q.push(P(i,j));
	while(!q.empty()){
	  a=q.front().first;b=q.front().second;q.pop();
	  if(a<0||a>=xs.size()||b<0||b>=ys.size()||u[a][b]) continue;
	  u[a][b]=1;
	  if(!ex[a][b]) q.push(P(a,b-1));
	  if(!ex[a][b+1]) q.push(P(a,b+1));
	  if(!ey[a][b]) q.push(P(a-1,b));
	  if(!ey[a+1][b]) q.push(P(a+1,b));
	}
	k++;
      }
    }
    cout << k << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int count =0;
  if(n%2!=0){
    cout << "No" << endl;
  }
  else {
    for(int i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        count++;
      }
    }
    if(count==0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
      
}

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

using namespace std;

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

    int ans = 0;
    int bx = 0, xa = 0, ba = 0;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < s.length() - 1; ++j) {
            if (s[j] == 'A' and s[j + 1] == 'B') ans++;
        }

        if (s[0] == 'B' and s[s.size() - 1] == 'A') {
            ba++;
        } else if (s[0] == 'B') {
            bx++;
        } else if (s[s.size() - 1] == 'A') {
            xa++;
        }
    }

    ans += min(bx, xa) + ba;
    if (bx == 0 and xa == 0 and ba != 0) ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

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

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

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


int main() {
	ll i, j;
	ll N;
	cin >> N;
	vll A(N);
	for (auto& e : A)cin >> e;
	ll tmp = 0;
	for (i = 0; i < N; i++) {
		tmp += A[i] * pow(-1, i);
	}
	ll x = tmp / 2;
	cout << tmp;
	for (i = 0; i < N - 1; i++) {
		x = A[i] - x;
		cout << " " << x * 2;
	}

	return 0;
}


Measured memory_bytes: 2048
import fractions
  
A,B,C,D= map(int,input().split())
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
CD=lcm(C, D)
 
dc =  B//C -  (A-1)//C
dd = B//D - (A-1)//D
dcd = B//CD - (A-1)//CD
 
print(B-A+1-dc-dd+dcd)

Measured memory_bytes: 5048
function main(input) {
  input=input.trim();
  const x = parseInt(input.split(" ")[0], 10);
  const t = parseInt(input.split(" ")[1], 10);
  if(t>=x){
    console.log(0);
  }else{
    console.log(x-t);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7620
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


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

	rep(i, M) {
		int a;
		cin >> a;
		N -= a;
	}

	if (N < 0) co(-1);
	else co(N);


	Would you please return 0;
}

Measured memory_bytes: 3652
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    
    odd = {'R', 'U', 'D'}
    even = {'L', 'U', 'D'}
    
    ans = 'Yes'
    for i, c in enumerate(S):
        if not i % 2 and c not in odd:
            ans = 'No'
        elif i % 2 and c not in even:
            ans = 'No'
    
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8996
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 3*100000;

int N;
string S;
int ans = kMaxN;

// w_count[i] = [0, i]までに存在する'W'の数
// e_count[i] = [i, N-1]までに存在する'E'の数
int w_count[kMaxN], e_count[kMaxN];

signed main() {
  cin >> N;
  cin >> S;

  w_count[0] = (S[0] == 'W') ? 1 : 0;
  e_count[N-1] = (S[N-1] == 'E') ? 1 : 0;
  FOR(i, 1, N) {
    w_count[i] = w_count[i-1];
    if (S[i] == 'W') { w_count[i] += 1; }
    e_count[N-1-i] = e_count[N-1-(i-1)];
    if (S[N-1-i] == 'E') { e_count[N-1-i] += 1; }
  }

  REP(i, N) {
    if (i == 0) {
      ans = MIN(ans, e_count[i+1]);
    } else if (i == N-1) {
      ans = MIN(ans, w_count[i-1]);
    } else {
      ans = MIN(ans, w_count[i-1]+e_count[i+1]);
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5380
#include<algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include  <stdio.h>
#include   <math.h>
#include   <time.h>
#include   <vector>
#include   <bitset>
#include    <queue>
#include      <set>
#include      <map>
using namespace std;

const char s[]="RYGB";

int main()
{
	int n,m,d;
	cin>>n>>m>>d;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			putchar(s[(i+j)/d%2*2+(i-j+10000)/d%2]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

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

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


int main(){
    int N, L; cin >> N >> L;
    vector<string> s(N);
    rep(i, N) cin >> s[i];
    sort(all(s));
    rep(i, N) cout << s[i];
    cout << endl;
}

Measured memory_bytes: 3596
#include <iostream>

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0

using namespace std;

lli min(lli a,lli b){
	return a <= b ? a : b;
}

int main(){

	lli a,b;
	cin>>a>>b;

	lli ans = min(a,b/2);

	if(DEBUG)cout<<ans<<endl;

	a -= ans;
	b -= ans*2;

	ans += b/4;

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define endl '\n' 
typedef long long int lli ; 
using namespace std; 

int main(int argc, char const *argv[])
{	
	vector<int> a(3); 
	for(int i = 0; i<3; ++i){
		int a_; 
		cin >> a_; 
		a.push_back(a_); 
	}
	sort(a.rbegin(), a.rend()); 
	int ans = abs(a[1] - a[0]) + abs(a[2] - a[1]); 
	cout <<ans; 
	return 0;
}

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

int l, n, a[200005], mx;

int main(){
    cin >> l >> n;
    cin >> a[0];
    for (int i = 1; i < n; i++){
        cin >> a[i];
        mx = max(mx, a[i]-a[i-1]);
    }
    mx = max(mx, l-a[n-1]+a[0]);
    cout << l-mx << "\n";
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAX=200004;
int cnt[MAX],fin,n,c;
main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",&cnt[i]);
        if(cnt[i]==i) c++;
        else fin+=(c+1)/2, c=0;
    }
    fin+=(c+1)/2;
    printf("%d\n",fin);
}


Measured memory_bytes: 640
from collections import deque
n=int(input())
uv=[[] for _ in range(n+1)]
for i in range(n-1):
    u,v,w=map(int,input().split())
    uv[u].append([v,w])
    uv[v].append([u,w])
stack=[1]
ans=[-1]*(n+1)
ans[1]=0
while stack:
    x=stack.pop()
    for j in uv[x]:
        if ans[j[0]]==-1:
            if j[1]%2==0:
                ans[j[0]]=ans[x]
            else:
                ans[j[0]]=(ans[x]+1)%2
            stack.append(j[0])

for k in range(1,n+1):
    print(ans[k])


Measured memory_bytes: 45720
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt(), m=fsc.nextInt();
        long[] a=new long[n];
        for(int i=0;i<n;i++) a[i]=fsc.nextLong();
        fsc.close();
        PriorityQueue<Integer> pq=new PriorityQueue<>((u,v)->a[u]<a[v]?1:a[u]>a[v]?-1:0);
        for(int i=0;i<n;i++) pq.add(i);
        for(int l=0;l<m;l++){
            int k=pq.poll();
            a[k]/=2;
            pq.add(k);
        }
        long ans=0;
        for(int i=0;i<n;i++) ans+=a[i];
        System.out.println(ans);
    }
    static 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());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}

Measured memory_bytes: 30416
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
   int A, B, C, D, E, F;
   cin >> A >> B >> C >> D >> E >> F;

   int maxA = F / (100 * A);
   int maxB = F / (100 * B);
   int maxC = F * E / (100 + E);
   double ansR = -1;
   int ansS, ansW;
   for (int a = 0; a <= maxA; a++) {
      for (int b = 0; b <= maxB; b++) {
         int water = 100 * A * a + 100 * B * b;
         int maxS = E * A * a + E * B * b;
         int rest = F - water;
         if (water == 0) continue;
         if (water > F) continue;
         if (rest < 0) continue;
         // cout << "-------" << endl;
         // cout << water << " " << min(maxS, rest) << endl;
         for (int c = 0; c <= maxC; c++) {
            if (min(maxS, rest) - c * C < 0) continue;
            int d = (min(maxS, rest) - c * C) / D;
            int sugar = c * C + d * D;
            if (water + sugar == 0) continue;
            // cout << a << " " << b << " " << c << " " << d << " " << sugar << " " << water << endl;
            double tmp = (double) sugar / (water + sugar);
            // cout << tmp << endl;
            if (tmp > ansR) {
               ansR = tmp;
               ansS = sugar;
               ansW = water;
            }
         }
      }
   }
   // cout << ansR << " " << ansS << " " << ansW << endl;
   cout << ansS + ansW << " " << ansS << endl;
   return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

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

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x, y;
	cin >> x >> y;
	ll ans = 1;
	while (true) {
		if (x * 2 <= y) {
			ans++;
			x *= 2;
		}
		else {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def sign(x):
    if x == 0:
        return 0
    return x // abs(x)


def main():
    n = int(input())
    a = list(map(int, input().split()))

    if n == 1:
        print(1)

    else:
        cnt = 1
        d = sign(a[1]-a[0])
        for i in range(n-1):
            dd = sign(a[i+1]-a[i])
            if d == 0:
                d = dd

            if d != 0 and dd != 0 and d != dd:
                cnt += 1
                if i < n-2:
                    d = sign(a[i+2]-a[i+1])

        print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14436
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#define NUM_PROBLEMS_MAX 100
#define NUM_DRINKS_MAX   100

typedef struct
{
	unsigned int num_problems;
	unsigned int num_drinks;
	unsigned int took_time_normal [NUM_PROBLEMS_MAX];
	unsigned int index_doped      [NUM_DRINKS_MAX  ];
	unsigned int took_time_doped  [NUM_DRINKS_MAX  ];
} abc050b_t;

void abc050b_get_data (      abc050b_t       * test_data);
void abc050b_answer   (const abc050b_t const * test_data);

int main (void)
{
	// variables for `main`
	abc050b_t test_data;

	// STEP.01
	// read out the given data
	abc050b_get_data(&test_data);

	// STEP.02
	// calculate & output the points
	abc050b_answer(&test_data);

	// STEP.END
	return EXIT_SUCCESS;
}

void abc050b_get_data (abc050b_t * test_data)
{
	// local variables for this function
	int retval_scanf;

	retval_scanf = scanf( "%d", &(*test_data).num_problems );

	for (unsigned int iter = 0; iter < (*test_data).num_problems; ++iter)
	{
		retval_scanf =
			scanf(
				"%d",
				&(*test_data).took_time_normal[iter]
			);
	}

	retval_scanf = scanf( "%d", &(*test_data).num_drinks );

	for (unsigned int iter = 0; iter < (*test_data).num_drinks; ++iter)
	{
		retval_scanf =
			scanf(
				"%d %d",
				&(*test_data).index_doped    [iter],
				&(*test_data).took_time_doped[iter]
			);
	}
}

void abc050b_answer (const abc050b_t const * test_data)
{
	// local variables for this function
	unsigned int sum_took_time = (unsigned int)0;

	// STEP.01
	// calculate the summation of the time it task to solve individual problems
	for (unsigned int iter = 0; iter < (*test_data).num_problems; ++iter)
	{
		sum_took_time += (*test_data).took_time_normal[iter];
	}

	// STEP.02
	// print the answer of this task to the console
	for (unsigned int iter = 0; iter < (*test_data).num_drinks; ++iter)
	{
		printf( "%d\n", sum_took_time - (*test_data).took_time_normal[ (*test_data).index_doped[iter] - 1 ] + (*test_data).took_time_doped[iter] );
	}
}

Measured memory_bytes: 128
import sys
import pdb
input = sys.stdin.readline

S = input()
T = input()

# print(S, T)

# lcs[Sのi文字目まで][Tのj文字目まで]
# 求める答えはlcs[len(S)][len(T)]
lcs = [[0 for _ in range(len(T)+1)] for __ in range(len(S)+1)]

for i in range(1, len(S)+1):
  for j in range(1, len(T)+1):
    if S[i-1] == T[j-1]:
      lcs[i][j] = max(lcs[i-1][j-1] + 1, lcs[i-1][j], lcs[i][j-1])
    else:
      # print(i,j)
      lcs[i][j] = max(lcs[i][j-1], lcs[i-1][j])

# print(lcs)
# print(lcs[len(S)][len(T)])

lcs_string = ""

i, j = len(S), len(T)

while i > 0 and j > 0:
  if lcs[i][j] == lcs[i-1][j]:
    i -= 1
  elif lcs[i][j] == lcs[i][j-1]:
    j -= 1
  else:# lcs[i][j] == lcs[i-1][j-1] + 1:
    lcs_string = S[i-1] + lcs_string
    i -= 1
    j -= 1

print(lcs_string)


Measured memory_bytes: 124508
package main

import "fmt"

func main() {
	// Code for B - ATCoder
	var S string
	fmt.Scanf("%s", &S)

	var answer int = 0
	var max int = 0
	for i := 0; i < len(S); i++ {
		if S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T' {
			answer++
		} else {
			if max < answer {
				max = answer
			}
			answer = 0
		}
	}
	if answer != 0 {
		if max < answer {
			max = answer
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 1828
<?php
  list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));

  $alen = strlen($a);
  $blen = strlen($b);
  $clen = strlen($c);

  if($a[$alen-1] == $b[0] && $b[$blen-1] == $c[0]){
    echo "YES";
  }else{
    echo "NO";
  }

Measured memory_bytes: 16144
#include <cassert>
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;


double xs[100000+5];
double ys[100000+5];
char ds[100000+5];
int n;

double calc(double t) {
  double x1 = 1e10;
  double x2 = -1e10;
  double y1 = 1e10;
  double y2 = -1e10;
  REP(i, n) {
    double x, y;
    if(ds[i] == 'U') {
      x = xs[i];
      y = ys[i] + t;
    } else if(ds[i] == 'D') {
      x = xs[i];
      y = ys[i] - t;
    } else if(ds[i] == 'L') {
      x = xs[i] - t;
      y = ys[i];
    } else if(ds[i] == 'R') {
      x = xs[i] + t;
      y = ys[i];
    } else {
      assert(false);
    }
    x1 = min(x1, x);
    y1 = min(y1, y);
    x2 = max(x2, x);
    y2 = max(y2, y);
  }
  double res = (x2-x1)*(y2-y1);
  // cerr << t << " " << res << endl;
  return res;
}

int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lf%lf %c", &xs[i], &ys[i], &ds[i]);
  }
  double left = 0;
  double right = 1e9;
  REP(t, 200) {
    double m1 = (left*2+right) / 3.0;
    double m2 = (left+right*2) / 3.0;
    double v1 = calc(m1);
    double v2 = calc(m2);
    if(v1 < v2) {
      right = m2;
    } else {
      left = m1;
    }
  }
  printf("%.10f\n", calc(left));
  
  return 0;
}


Measured memory_bytes: 1920
N = int(input())
A = list(map(int, input().split()))

ans = 0
pc, zc, mc = 0, 0, 0
s = 0
min_abs = 10**9
for a in A:
    abs_a = abs(a)
    min_abs = min(min_abs, abs_a)
    s += abs_a
    if a>0:
        pc += 1
    elif a==0:
        zc += 1
    else:
        mc += 1

if zc>0 or mc%2==0:
    print(s)
else:
    print(s-2*min_abs)


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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int n;
int a[1 << 17];
ll tot[1 << 17];

void prt(__int128 x) {
	if (x >= 10) prt(x / 10);
	putchar(x % 10 + '0');
}

int main() {
	scanf("%d", &n);
	rep(i, n + 1) scanf("%d", &a[i]);
	for (int i = n; i; -- i) tot[i] = tot[i + 1] + a[i];
	tot[0] = 1;
	rep(i, n + 1) if (i) {
		if (tot[i - 1] < a[i - 1]) { puts("-1"); return 0; }
		tot[i] = min(tot[i], (tot[i - 1] - a[i - 1]) * 2);
	}
	if (tot[n] < a[n]) { puts("-1"); return 0; }
	__int128 ans = 0;
	rep(i, n + 1) ans += tot[i];
	prt(ans); puts("");
	return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N, K;
  cin >> N >> K;

  cout << N-K+1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	int n;
	while(~getI(n)){
		int ans=48-n;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
a, b = map(int, input().split())

large_num = 0
small_num = 0
if a > b:
  large_num = a
  small_num = b
else:
  large_num = b
  small_num = a

div_result = 0

for n in range(large_num):
  result1 = large_num%(n+1)
  result2 = small_num%(n+1)
  if result1==0 and result2 ==0:
    div_result = n+1

result = int(large_num/div_result*small_num)
print(result)

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	ll sum = 0;
	rep(i,n){
		int tmp; cin >> tmp;
		sum += tmp;
		a.at(i) = tmp;
	}
	sum /= 2;

	for(int i = n - 2; i >= 1; i -= 2){
		sum -= a.at(i);
	}
	vector<ll> ans(n);
	ans.at(0) = 2 * sum;
	for(int i = 1; i < n; i++){
		ans.at(i) = 2*(a.at(i-1)-ans.at(i-1)/2);
	}
	for(int i = 0; i < n; i++){
		cout << ans.at(i) << " ";
	}
} 

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

int main(){
    int N;
    int ans =0;
    cin >>N;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >>vec[i];
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<=vec[N-1];i++){
        if(vec[N/2-1] <i && vec[N/2] >= i){
            ans++;
        }
    } 
  	cout << ans << endl;
}

Measured memory_bytes: 640
from collections import deque

d,q=list(map(int,input().split()))

name=deque()
time=deque()

for n in range(d):
    a,b=input().split()
    name.append(a)
    time.append(int(b))
    
ans=0
    
while name:
    n=name.popleft()
    t=time.popleft()
    if t>q:
        name.append(n)
        time.append(t-q)
        ans=ans+q
    else:
        ans=ans+t
        print(n,ans)
        


Measured memory_bytes: 9884
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 100005
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin>>n;
    int ar[n];
    map<int,int> m;
    
    ll sum=0;
    rep(i,0,n)
    {
    	cin>>ar[i];
    	m[ar[i]]++;
	}
	for( auto i: m)
	{
		ll a=i.S;
		sum+=a*(a-1)/2;
	}
	rep(i,0,n)
	{
		ll b=m[ar[i]];
		if(b>=2)
		{
			ll ans=sum-(b*(b-1)/2-(b-1)*(b-2)/2);
			cout<<ans<<endl;
		}
		else
		cout<<sum<<endl;
	}
  
}

Measured memory_bytes: 8320
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include <set>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n,T;
  int c[1001];
  int t[1001];
  scanf("%d%d",&n,&T);
  for(int i=0;i<n;i++){
    scanf("%d%d",&c[i],&t[i]);
  }
  int ans = 10000000;
  for(int i=0;i<n;i++){
    if(t[i]<=T){
      if(c[i] < ans) ans =c[i];
    }
  }
  if(ans == 10000000){
    puts("TLE");
  }else{
    printf("%d\n",ans);
}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

template <typename T>
class Vec2 {
 public:
  Vec2(){};
  Vec2(T x, T y) : x(x), y(y){};
  Vec2<T> operator+(Vec2<T> p);
  Vec2<T> operator-(Vec2<T> p);
  Vec2<T> operator*(T t);
  T norm();
  T dot(Vec2<T> p);
  bool is_paralell(Vec2<T> p);
  bool is_vertical(Vec2<T> p);
  T x, y;
};

template <typename T>
Vec2<T> Vec2<T>::operator+(Vec2<T> p) {
  return Vec2(x + p.x, y + p.y);
}

template <typename T>
Vec2<T> Vec2<T>::operator-(Vec2<T> p) {
  return Vec2(x - p.x, y - p.y);
}

template <typename T>
Vec2<T> Vec2<T>::operator*(T t) {
  return Vec2(t * x, t * y);
}

template <typename T>
T Vec2<T>::norm() {
  return hypot(x, y);
}

template <typename T>
T Vec2<T>::dot(Vec2<T> p) {
  return x * p.x + y * p.y;
}

template <typename T>
bool Vec2<T>::is_paralell(Vec2<T> p) {
  return x * p.y == y * p.x;
}

template <typename T>
bool Vec2<T>::is_vertical(Vec2<T> p) {
  return this->dot(p) == (T)0;
}

int main() {
  Vec2<double> s, seg, p;
  int q;
  cin >> s.x >> s.y >> seg.x >> seg.y;
  seg.x -= s.x;
  seg.y -= s.y;
  cin >> q;
  REP(i, q) {
    cin >> p.x >> p.y;
    auto r = (p - s).dot(seg) / pow(seg.norm(), 2);
    auto out = s + seg * r;
    cout << std::setprecision(15) << out.x << " " << out.y << endl;
  }
}


Measured memory_bytes: 3352
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
import java.lang.Object;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new A().doIt();
    }
    class A{
    	void doIt(){
    		String str = sc.next();
    		char ctr[] = str.toCharArray();
    		int U = 0,D = 0,L = 0,R = 0;
    		for(int i = 0;i < str.length();i++){
    			if(ctr[i] == 'S'){
    				D = 1;
    			}else if(ctr[i] == 'N'){
    				U = 1;
    			}else if(ctr[i] == 'W'){
    				L = 1;
    			}else{
    				R = 1;
    			}
    		}
    		boolean ok = true;
    		if((D + U) % 2 == 1)ok = false;
    		if((L + R) % 2 == 1)ok = false;
    		if(ok)System.out.println("Yes");
    		else System.out.println("No");
    	}
    }
}

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

int main(){
  int n; cin >> n;
  int t[n+1], x[n+1], y[n+1];
  for(int i=1; i<=n; i++){
    cin >> t[i] >> x[i] >> y[i];
  }
  t[0] = x[0] = y[0] = 0;

  for(int i=1; i<=n; i++){
    int dt = t[i]-t[i-1], dx =x[i]-x[i-1], dy=y[i]-y[i-1];
    int d = abs(dx) + abs(dy);
    if(dt < d or (dt-d) % 2){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

ll inf = 1e18L + 5;

ll dig(ll x)
{
    ll cnt = 0;
    while (x) {
        cnt++;
        x /= 10;
    }

    return cnt;
}

ll fnc(ll N)
{
    ll ans = inf;
    for (ll i = 1; i <= sqrt(N); i++) {
        if (N % i == 0) {
            ll a = i;
            ll b = N / i;

            ans = min(ans, max(dig(a), dig(b)));
        }
    }

    return ans;
}

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

    cout << fnc(N);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int a, b;
long long arra[99999], arrb[99999];
int main()
{
	cin >> a >> b;
	for(int i=1; i<=a; i++)
		cin >> arra[i];
	for(int i=1; i<=b; i++)
		cin >> arrb[i]; 
	long long dp[a + 100][b + 100];
	for(int i=0; i<=a; i++)
		for(int j=0; j<=b; j++)
			dp[i][j] = 0;
	for(int i=1; i<=a; i++)
	{
		for(int j=1; j<=b; j++)
		{
			dp[i][j] += (long long)dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
			if(arra[i] == arrb[j])
				dp[i][j] += (long long)dp[i-1][j-1] + 1;
			dp[i][j] %= mod;
			dp[i][j] += mod;
			dp[i][j] %= mod;
		}
	}
	printf("%lld\n",dp[a][b] + 1);
	return 0;
}

Measured memory_bytes: 33792
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
$S = $key->X[0][0];
$base = $S;
while(1) {
  $s = str_replace("()","",$base);
  if (strpos($s,"()")===false) {
    break;
  }
  $base = $s;
}
$len = strlen($s);
$ins=0;
$aft=0;
for($i=0;$i<$len;$i++) {
  if ($s[$i]==')') {
    $ins++;
  }
  else {
    $aft++;
  }
}
$insstr="";
$aftstr="";
for($i=0;$i<$ins;$i++) {
  $insstr=$insstr."(";
}
for($i=0;$i<$aft;$i++) {
  $aftstr=$aftstr.")";
}
printf("%s%s%s\n",$insstr,$S,$aftstr);


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

int main()
{
	long long a, b, c, d;    cin >> a >> b >> c >> d;

	long long x = a * c, y = a * d, j = b * c, k = b * d;
	cout << max(x, max(y, max(j, k))) << endl;
	return 0;
}

Measured memory_bytes: 3644
n = int(input())
a = [0 for i in range(n)]
b = list(map(int,input().split()))
a[0] = b[0]
a[n-1] = b[n-2]
for i in range(n-2):
    a[i+1] = min(b[i],b[i+1])
print(sum(a))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
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;
}
long long dp[100010];
 
int main()
{
  int N;
  cin >> N;
  vector<ll> h(N);
  REP(i, N) cin >> h[i];
  

  REP(i,100010){
    dp[i] = INF;
  }

  //dp[i] = i番目に到達するまでの最小コスト
  dp[0] = 0;

  FOR(i,1,N){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    if(i>1){
      chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
  }

  cout << dp[N-1] << endl;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

void pre(){

    

}


void solve(){

    ll n;
    cin >> n;
    ll ans=0;
    for(ll l=1;l<=n;l++){
        ans += l*(n-l+1);
    }
    for(ll i=0;i<n-1;i++){
        ll s,d;
        cin >> s >> d;
        ll mn = min(s,d);
        ll mx = max(s,d);
        ans -= mn*(n-mx+1);
    }
    cout << ans;


}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin >> n;
    ll a[n];
    rep(i,0,n) cin >> a[i];
    int cnt=0;
    rep(i,0,n)
    {
        if(a[i]<0) cnt++;
    }
    ll ans = 0;
    if(cnt%2 == 0)
    {
        rep(i,0,n) ans += abs(a[i]);
    }
    if(cnt%2 == 1)
    {
        rep(i,0,n) ans += abs(a[i]);
        rep(i,0,n) a[i] = abs(a[i]);
        sort(a, a+n);
        ans -= a[0]*2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#ABC057
import math
n = int(input())
#print(math.sqrt(n))
m = len(str(n))
for i in range(1,int(math.sqrt(n))+1):
    if n % i == 0:
        #print(i,n//i)
        #print(len(str(i)),len(str(n//i)))
        if m > len(str(n//i)):
            m = len(str(n//i))
print(m)



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n;
long long m;
int x,y;
vector<int> ga[100100];
vector<int> ch[100100];
long long dp[100100];
long long res[100100];
long long pref[100100],suff[100100];
long long aaa[100100];
void do_dp(int u,int p){
	dp[u]=1LL;
	for(int i=0;i<ga[u].size();i++){
		int v=ga[u][i];
		if(v==p)
			continue;
		ch[u].push_back(v);
		do_dp(v,u);
		dp[u]=(dp[u]*((dp[v]+1LL)%m))%m;
	}
}
long long abov;
void do_res(int u,int p){
	abov=aaa[u];
	res[u]=(dp[u]*abov)%m;
	pref[0]=abov;
	for(int i=0;i<ch[u].size();i++)
		pref[i+1]=(pref[i]*(dp[ch[u][i]]+1LL)%m)%m;
	suff[ch[u].size()]=1LL;
	for(int i=ch[u].size()-1;i>=0;i--)
		suff[i]=(suff[i+1]*(dp[ch[u][i]]+1LL)%m)%m;
	for(int i=0;i<ch[u].size();i++){
		int v=ch[u][i];
		aaa[v]=(1LL+(pref[i]*suff[i+1]))%m;
	}
	for(int i=0;i<ch[u].size();i++){
		int v=ch[u][i];
		do_res(v,u);
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<n;i++){
		cin>>x>>y;
		ga[x].push_back(y);
		ga[y].push_back(x);
	}
	aaa[1]=1LL;
	do_dp(1,-1);
	do_res(1,-1);
	for(int i=1;i<=n;i++)
		cout<<res[i]<<endl;
	return 0;
}


Measured memory_bytes: 21120
import java.util.*;
import java.util.stream.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = IntStream.range(0, 3 * n).map(i -> scanner.nextInt()).sorted().skip(n).toArray();
        System.out.println(IntStream.range(0, n).mapToLong(i -> a[i * 2]).sum());
    }
}

Measured memory_bytes: 94176
import java.util.*;

import java.io.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = 1000000007;
	static int inf = (int) 1e15;
	static ArrayList<Integer>[] adL, adH;
	static int n, m, k, total;
	static int[] ans;
	static boolean[] vis,vis1;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		m = sc.nextInt();
		k = sc.nextInt();
		adL = new ArrayList[n];
		for (int i = 0; i < n; i++)
			adL[i] = new ArrayList<>();
		adH = new ArrayList[n];
		for (int i = 0; i < n; i++)
			adH[i] = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			adL[a].add(b);
			adL[b].add(a);
		}
		for (int i = 0; i < k; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			adH[a].add(b);
			adH[b].add(a);
		}
		vis=new boolean [n];
		vis1=new boolean [n];
		ans=new int [n];
		for (int i = 0; i < n; i++) {
			if (!vis[i]) {
				total = 0;
				hs = new HashSet<>();
				dfs(i);
				dfs1(i);
			}
		}
		for(int i=0;i<n;i++)
			out.print(ans[i]+" ");
		out.flush();
	}

	static HashSet<Integer> hs;

	static void dfs(int u) {
		total++;
		hs.add(u);
		vis[u] = true;
		for (int v : adL[u])
			if (!vis[v])
				dfs(v);
	}

	static void dfs1(int u) {
		vis1[u] = true;
		int h=0;
		for (int v : adL[u])
			if (!vis1[v])
				dfs1(v);
		for(int v:adH[u])
			if(hs.contains(v))
				h++;
		ans[u]=-1+total-adL[u].size()-h;
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 91496
#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) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,a,cnt = 0,ans = 0;
    cin >> n;
    vector<bool> vec(8,false);
    rep(i, n){
        cin >> a;
        if (a < 400) {
            vec[0] = true;
        }
        else if (a < 800){
            vec[1] = true;
        }
        else if (a < 1200){
            vec[2] = true;
        }
        else if (a < 1600){
            vec[3] = true;
        }
        else if (a < 2000){
            vec[4] = true;
        }
        else if (a < 2400){
            vec[5] = true;
        }
        else if (a < 2800){
            vec[6] = true;
        }
        else if (a < 3200){
            vec[7] = true;
        }
        else{
            ++cnt;
        }
    }
    rep(i, 8)if(vec[i])++ans;
    cout << max((int)ans,1) << " " << ans + cnt << endl;
    return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do
    [x,a,b] <- (map read) . words <$> getLine
    putStrLn $ solve x a b

solve :: Int -> Int -> Int -> String
solve x a b | a - b >= 0 = "delicious"
            | x + a - b >= 0 = "safe"
            | otherwise = "dangerous"


Measured memory_bytes: 508