akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.NoSuchElementException

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val pqr = sc.nextIntArray(3).sortedArray()
    println(pqr[0] + pqr[1])
}

class Scanner(private val `in`: InputStream) {
    private val buffer = ByteArray(1024)
    private var ptr = 0
    private var buflen = 0

    companion object {
        private fun isPrintableChar(b: Byte): Boolean = b in 33..126
        private fun isNumericChar(b: Byte): Boolean = b in 48..57
        private fun digit(b: Byte): Int = b - 48
    }

    fun hasNextByte(): Boolean {
        if (ptr < buflen) return true
        ptr = 0
        try {
            buflen = `in`.read(buffer)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return 0 < buflen
    }

    private fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        return buildString {
            var b = readByte()
            while (isPrintableChar(b)) {
                appendCodePoint(b.toInt())
                b = readByte()
            }
        }
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextInts(n: Int): Array<Int> = Array(n) { nextInt() }

    fun nextIntArray(n: Int): IntArray = IntArray(n) { nextInt() }

    fun nextIntArrays(n: Int, m: Int): Array<IntArray> {
        val arrays = Array(m) { IntArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextInt() } }
        return arrays
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        val minus = b.toChar() == '-'
        if (minus) b = readByte()
        if (!isNumericChar(b)) throw NumberFormatException()
        do {
            n *= 10
            n += digit(b)
            b = readByte()
        } while (isNumericChar(b))
        return if (minus) -n else n
    }

    fun nextLongs(n: Int): Array<Long> = Array(n) { nextLong() }

    fun nextLongArray(n: Int): LongArray = LongArray(n) { nextLong() }

    fun nextLongArrays(n: Int, m: Int): Array<LongArray> {
        val arrays = Array(m) { LongArray(n) }
        repeat(n) { i -> repeat(m) { j -> arrays[j][i] = nextLong() } }
        return arrays
    }

}

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

using namespace std;

int main()
{
    char s[100001];
    int n,c=0;
    cin>>n;
    cin>>s;
    for(int i=0;i<strlen(s);i++)
    {
        if(s[i]!=s[i+1])
            c++;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
  
#define INF 10000000
#define NIL -1
  
struct Node{int parent,left,right;};

Node T[INF];
int n,D[INF];
  
void print(int u){
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";
  
  if(T[u].parent==NIL) cout << "root, ";
  else if(T[u].left == NIL) cout << "leaf, ";
  else cout << "internal node, ";
  
  cout << "[";
  for(i=0,c=T[u].left;c!=NIL;i++,c=T[c].right){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}
  
void rec(int u,int p){
  D[u] = p;
  if(T[u].right != NIL) rec(T[u].right,p);
  if(T[u].left != NIL) rec(T[u].left,p+1);  
}
  
int main(void){
  int i,j,d,v,c,left,right;
  
  cin >> n;
  for(i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = NIL;
  
  for(i=0;i<n;i++){
    cin >> v >> d;
    for(j=0;j<d;j++){
      cin >> c;
      if(j==0) T[v].left = c;
      else T[left].right = c;
      left = c;
      T[c].parent = v;
    }
  }
  
  for(i=0;i<n;i++) if(T[i].parent==NIL) right = i;
  rec(right,0);
  
  for(i=0;i<n;i++) print(i);
}

Measured memory_bytes: 7684
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
const int D = 12;
int n , m;
int a , b;
vector < int > v[N];
int q;
int start[N] , far[N] , colour[N];
int dist[N][D];
queue < pair < int , int > > que;
int main(){
	scanf("%d %d" , &n , &m);
	while(m--){
		scanf("%d %d" , &a , &b);
		v[a].emplace_back(b);
		v[b].emplace_back(a);
	}
	scanf("%d" , &q);
	for(int i = 1 ; i <= q ; ++i){
		scanf("%d %d %d" , start + i , far + i , colour + i);
		dist[start[i]][far[i]] = i;
		que.push({start[i] , far[i]});
	}
	while(!que.empty()){
		int node = que.front().first;
		int level = que.front().second;
		int cost = dist[node][level];
		que.pop();
		if(level){
			--level;
			for(int next : v[node]){
				if(dist[next][level] < cost){
					dist[next][level] = cost;
					que.push({next , level});
				}
			}
		}
	}
	for(int i = 1 ; i <= n ; ++i){
		int val = 0;
		for(int j = 0 ; j < D ; ++j){
			val = max(val , dist[i][j]);
		}
		printf("%d\n" , colour[val]);
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int kou_n = 1;

    for(int i = a.at(0);i > 1;i --){
        for(int j = 0;j < n;j ++){
            if(a.at(j) % i != 0){
                break;
            }else if(j == n-1){
                kou_n = i;
                break;
            }
        }
        if(kou_n == 1){
            continue;
        }else{
            break;
        }
    }
    
    int kou_n_1 = kou_n;
    int cnt;
    for(int i = a.at(1);i >= kou_n;i --){
        cnt = 0;
        for(int j = 0;j < n;j ++){
            if(a.at(j) % i != 0){
                cnt ++;
            }
            if(cnt > 1){
                break;
            }else if(j == n-1){
                kou_n_1 = i;
            }
        }
        if(kou_n_1 > kou_n){
            break;
        }
    }

    cout << kou_n_1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(void){
int A, B;
scanf("%d%d", &A, &B);
if(A+B >= A-B && A+B >= A*B){
    printf("%d", A+B);
}else if(A-B >= A+B && A-B >= A*B){
    printf("%d", A-B);
}else{
    printf("%d", A*B);
}
return 0;
}

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

using namespace std;

int main() {
  long double A, B, C, D;
  cin >> A >> B >> C >> D;
  
  long double first = ceil(C / B);
  long double second = ceil(A / D);
  
  if (first <= second) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3728
import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B

main=do
    n<-readLn
    as<-sortBy(flip compare).unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine
    print$sol 0 n as
sol c 0 _ = c
sol c n (a:b:r) = sol (c+b) (n-1) r

Measured memory_bytes: 51580
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	lint a, b, c;
	cin >> a >> b >> c;

	lint d = c - a - b;

	if (d > 0 && 4 * a * b < d * d) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}



Measured memory_bytes: 3656
#include <stdio.h>
#include <math.h>


int main(int argc, char const *argv[])
{
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i=0; i < n; i++){
        scanf("%d", &a[i]);
    }
    
    int b[n];
    for (int i=0; i < n; i++){
        b[a[i]-1] = i+1;
    }

    for (int i=0; i < n; i++){
        printf("%d ", b[i]);
    }
    printf("\n");
    
    return 0;
} 


Measured memory_bytes: 1536
#include <iostream>

int main()
{
    int m, f, r;
    char Grade;

    while(true){
        std::cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1){
            break;
        } else if (m == -1 || f == -1){
            Grade = 'F';
        } else if (m + f >= 80){
            Grade = 'A';
        } else if (m + f >= 65){
            Grade = 'B';
        } else if (m + f >= 50){
            Grade = 'C';
        } else if (m + f >= 30){
            if (r >= 50){
                Grade = 'C';
            } else {
                Grade = 'D';
            }
        } else {
            Grade = 'F';
        }
        std::cout << Grade << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

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

  int d [N];
  for(int i = 0; i < N; i++) {
    cin >> d[i];
  }

  int total = 0;
  for(int i = 0; i < N - 1; i++) {
    for(int j = i + 1; j < N; j++) {
      total += d[i] * d[j];
    }
  }

  cout << total;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;


void solve(){
	int n; cin>>n;
	map<string, ll> mp;
	ll ans= 0;
	for(int i=0; i<n; i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		ans += mp[s];
		mp[s]++;
	}
	cout<<ans;


}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  ll r,d,x0;
  cin>>r>>d>>x0;
  rep(t,10) {
    x0=r*x0-d;
    cout << x0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String [] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt();
    int div=0;
    while(a<=b){
      if(c%a==0){
        div=div+1;
      }
      a++;
    }
    System.out.println(div);
  }
}


Measured memory_bytes: 26428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<pair<int,int> > red(N);
    vector<pair<int,int> > blue(N);
    rep(i,N){
        cin >> red[i].second >> red[i].first;
    }
    rep(i,N){
        cin >> blue[i].first >> blue[i].second;
    }
    sort(all(red));
    sort(all(blue));
    int ans = 0;
    rep(i,N){
        int len = red.size();
        for (int j = len - 1; j >= 0; j--){
            if (blue[i].first > red[j].second && blue[i].second > red[j].first){
                ans++;
                red.erase(red.begin() + j);
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        long[] map = new long[5];

        for (int i = 0; i < N; i++) {
            String s = scanner.next();

            if(s.charAt(0) == 'P')map[0]++;
            if(s.charAt(0) == 'Y')map[1]++;
            if(s.charAt(0) == 'W')map[2]++;
            if(s.charAt(0) == 'G')map[3]++;
        }

        long ans = 0;
        for (int i = 0; i < 4; i++) {
            if(map[i] > 0)ans++;
        }
        if(ans == 3){
            System.out.println("Three");
        }else{
            System.out.println("Four");
        }
    }



}




Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 18;
int n, a[1 << maxn];
pair<int, int> b[1 << maxn];

void Get(pair<int, int> &a, int b) {
  if (b > a.first) {
    a.second = a.first;
    a.first = b;
  } else if (b > a.second) {
    a.second = b;
  }
}

pair<int, int> Combine(pair<int, int> a, pair<int, int> b) {
  Get(a, b.first);
  Get(a, b.second);
  return a;
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < 1 << n; ++i) {
    scanf("%d", a + i);
    b[i] = {a[i], 0};
  }
  for (int i = 0; i < n; ++i) {
    for (int s = 0; s < 1 << n; ++s) {
      if (~s >> i & 1) {
        b[s | 1 << i] = Combine(b[s | 1 << i], b[s]);
      }
    }
  }
  for (int s = 1; s < 1 << n; ++s) {
    int ans = b[s].first + b[s].second;
    for (int i = 0; i < n; ++i) {
      if (s >> i & 1) {
        int s2 = s & ~(1 << i) | (1 << i) - 1;
        ans = max(ans, b[s2].first + b[s2].second);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}


Measured memory_bytes: 6016
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vl n(s.size());
  rep(i, s.size()) n[i] = s[i] - '0';
  ll k;
  cin >> k;
  vvvl dp(n.size(), vvl(k + 1, vl(2, 0)));
  rep(d, 10) {
    if (n[0] == d) {
      dp[0][1][0]++;
    } else if (d < n[0]) {
      if (d == 0)
        dp[0][0][1]++;
      else
        dp[0][1][1]++;
    }
  }
  REP(i, 1, n.size()) {
    rep(j, k + 1) {
      rep(d, 10) {
        if (n[i] == d) {
          if (d == 0) {
            dp[i][j][0] += dp[i - 1][j][0];
            dp[i][j][1] += dp[i - 1][j][1];
          } else {
            if (0 < j) {
              dp[i][j][0] += dp[i - 1][j - 1][0];
              dp[i][j][1] += dp[i - 1][j - 1][1];
            }
          }
        } else if (d < n[i]) {
          if (d == 0) {
            dp[i][j][1] += dp[i - 1][j][1] + dp[i - 1][j][0];
          } else {
            if (0 < j) {
              dp[i][j][1] += dp[i - 1][j - 1][1] + dp[i - 1][j - 1][0];
            }
          }
        } else {
          if (0 < j) {
            dp[i][j][1] += dp[i - 1][j - 1][1];
          }
        }
      }
    }
  }
  ll ans = 0;
  rep(l, 2) { ans += dp[n.size() - 1][k][l]; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
a,b = map(int,input().split())
import math
c = 0
for i in range(10*b,10*b+10):
    if math.floor(i*0.08)>=a and math.floor(i*0.08)<a+1:
        print(i)
        c = 1
        break
if c == 0:
    print(-1)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = LLONG_MAX;

#define ARRAY_MAX 100005
#define INF 1e9+7


/*nまでの素数を列挙して配列に保持*/
vector<ll> Eratosthenes(ll n,vector<ll>& arr){
    
    for(ll i = 0; i < n;i++){
        arr[i] = 1;
    }
    arr[1] = arr[0] = 0;
    for(ll i = 2; i < sqrt(n); i++){
        if(arr[i]){
            for(ll j = 0; i * (j + 2) < n; j++){
                arr[i *(j + 2)] = 0;
            }
        }
    }
    return arr;
}


int main(){


    int q;
    cin >> q;
    vector<ll> arr(ARRAY_MAX);/*素数判定用配列*/
    arr = Eratosthenes(ARRAY_MAX,arr);/*エラトステネスのふるいで素数判定*/
    vector<ll> prime(ARRAY_MAX,0);/*2017に似た整数の累積和*/

    for(int i = 3; i < arr.size(); i += 2){
        /*奇数のみ調べる*/
        if(arr[i] == 1 && arr[(i+1)/2] == 1){
            /*2017に似た整数であれば1を格納、つまり１つある*/
            prime[i] = 1;
        }else{
            prime[i] = 0;
        }
    }
    /*
    REP(i,15){
        cout << prime[i] << " "; 
    }
    cout << endl;
    */
    for(int i = 0;i < arr.size()-1;i++){
        /*2017に似た整数の累積和を求める*/
        prime[i+1] += prime[i];
    }

    /*REP(i,15){
        cout << prime[i] << " "; 
    }
    cout << endl;
    */
    ll l,r;
    REP(i,q){
        /*q個のクエリに対して処理*/
        cin >> l >> r;
        cout << prime[r] - prime[l-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,a,b;
  cin>>n>>a>>b;
  if((a - b)% 2 == 0){
    cout<<abs(a-b)/2<<endl;}
else{cout << min((a+b-1)/2,(n*2-a-b+1)/2) << endl;}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
 int i,H,N[251];

  scanf("%d",&H);

  for(i = 1; i <= H; i++){
    scanf("%d",&N[i]);
  }

  for(i = 1; i <= H; i++){
    printf("node %d: key = %d, ",i,N[i]);
    if(i != 1) printf("parent key = %d, ",N[i/2]);
    if(2 * i <= H) printf("left key = %d, ",N[2*i]);
    else{
      printf("\n");
      continue;
    }
    if((2 * i + 1) <= H) printf("right key = %d, ",N[2*i+1]);
      printf("\n");
  }
   return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    int level = (X-200)/200;
    int ans = 9-level;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#import<cstdio>
#import<map>
#define I(M,A)for(i=0;i<M;i++)scanf("%d",&x),A[i+1]=A[i]+x;
main(){for(int n[1501],m[1501],o,a,b,i,j,x;scanf("%d%d",&a,&b),a;printf("%d\n",o)){std::map<int,int>z;*n=*m=o=0;I(a,n)I(b,m)for(i=0;i<=a;i++)for(j=0;j<=b;)z[n[i]+m[j++]]++;for(typeof(z.begin())p=z.begin();p!=z.end();p++)o+=p->second*(p->second-1)/2;}}

Measured memory_bytes: 18000
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
	int n,a;
    cin >> n >> a;
  	
  	if(n%500>a)
      cout<<"No";
    else
      cout<<"Yes";

	return 0;
	// BYE BYE 
}


Measured memory_bytes: 256
def main(n,s):
    s.sort()
    val = s[0]
    idx = 0
    maxcount = 1
    lst = [[1, val]]
    for i in range(1,len(s)):
        if s[i] == val:
            lst[idx][0] += 1
            maxcount = max(maxcount, lst[idx][0])
        else:
            idx += 1
            val = s[i]
            lst.append([1,val])
    res = []
    for i in range(len(lst)):
        if lst[i][0] == maxcount:
            res.append(lst[i][1])
    res.sort()
    for i in range(len(res)):
        print(res[i])
    
n = int(input())
s = [input() for _ in range(n)]
main(n,s)

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

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

using ll = long long;

ll dp[3100][3100];
bool memo[3100][3100];

ll f(const vector<ll> &v, int x, int y) {
  if(memo[x][y]) return dp[x][y];
  memo[x][y] = true;
  if(x==y) dp[x][y]=v.at(x);
  else {
    dp[x][y] = max(v.at(x)-f(v,x+1,y), v.at(y)-f(v,x,y-1));
  }
  return dp[x][y];
}

int main() {
  int N;
  cin >> N;
  vector<ll> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    memo[i][i+1] = true;
    dp[i][i+1] = abs(v.at(i) - v.at(i+1));
  }
  cout << f(v,0,N-1) << endl;
}
  

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

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  if(an[0]){
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  for(int i=1; i<n; ++i){
    if(an[i] > an[i-1] +1){
      cout << -1 << endl;
      return 0;
    }
    else if(an[i] == an[i-1] +1) ++ans;
    else{
      ans += an[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4060
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

struct cake {int w, h, area;};

bool operator< (const cake &lhs, const cake &rhs)
{
    return lhs.area < rhs.area;
}

vector<cake> cakes;

int main()
{
    int n, w, d;
    while(cin >> n >> w >> d && w && d) {
        cakes.push_back((cake){w, d, w * d});
        for(int i = 0; i < n; i++) {

            int p, s;
            cin >> p >> s;
            cake c = cakes[p - 1];
            cakes.erase(cakes.begin() + p - 1);
            s %= (c.w + c.h);
            if(s < c.w) {
                cakes.push_back((cake){c.w - s, c.h, (c.w - s) * c.h});
                cakes.push_back((cake){s, c.h, s * c.h});
            } else if (s > c.w){
                s -= c.w;
                cakes.push_back((cake){c.w, c.h - s, c.w * (c.h - s)});
                cakes.push_back((cake){c.w, s, c.w * s});
            } else {
                cakes.push_back(c);
            }
            sort(cakes.begin() + i, cakes.begin() + i + 2);
        }
        sort(cakes.begin(), cakes.end());
        for(unsigned int i = 0; i < cakes.size(); i++)
            if(i == cakes.size() - 1)
                cout << cakes[i].area << endl;
            else 
                cout << cakes[i].area << " ";

        cakes.clear();
    }
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<55)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

int main(){

    lli n;
    cin>>n;

    vector<lli> a(n);
    REP(i,0,n)cin>>a[i];
    lli ansNum;
    lli ansSum = INF;

    REP(i,-200,200){
        lli sum = 0;
        REP(j,0,n){
            lli t = (a[j]-i);
            sum += t*t;
        }
        if(sum<ansSum){
            ansSum = sum;
            ansNum = i;
        }
    }

    cout<<ansSum<<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

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

int N;
ll M, A[100000 + 100];

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++)cin >> A[i];

	if (N == 1) {
		if (M >= A[0] / 2)cout << 1 + (M - A[0] / 2) / A[0] << endl;
		else cout << 0 << endl;
		return 0;
	}

	ll G = A[0];
	for (int i = 1; i < N; i++) {
		G = gcd(G, A[i]);
	}
	for (int i = 0; i < N; i++) {
		A[i] /= G;
		if (A[i] % 2 == 0) {
			//2で割り切れる数が全部で一致しないのなら
			cout << 0 << endl;
			return 0;
		}
	}

	ll ans = A[0];
	bool overflg = false;
	for (int i = 1; i < N; i++) {
		ans *= (A[i] / gcd(ans, A[i]));
		if (ans * G / 2 >= M)overflg = true;
	}
	ans *= G;
	if (M >= ans / 2 && !overflg) cout << (M - ans / 2) / ans + 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1024
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 1024;

int main(void) {
	// in = fopen("A.in", "rt");
	
	int x;
	fscanf(in, "%d", &x);
	if (x == 3 || x == 5 || x == 7) {
	    fprintf(out, "YES\n");
    } else {
	    fprintf(out, "NO\n");
    }
	
	return 0;
}

Measured memory_bytes: 128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
s = [inpl() for i in range(m)]
p = inpl()
res = 0
for flag in itertools.product([0,1], repeat=n):
    on = set()
    for i,j in enumerate(flag):
        if j: on.add(i+1)
    ok = True
    for i,j in enumerate(s):
        cnt = 0
        for k,l in enumerate(j):
            if k == 0: continue
            if l in on: cnt += 1
        if cnt%2 != p[i]:
            ok = False
            break
    if ok: res += 1
print(res)


Measured memory_bytes: 68332
#include "bits/stdc++.h"
#include <iostream>
using namespace std;
#define ll = long long;
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main()
{
	int n,ans =0;
	vector <int> x;
	cin >>n;
	rep(i, n) {
		int a;
		cin >> a;
		ans -= a * a;
		x.push_back(a);
	}
	rep(i, n) {
		rep(j, n) {
			ans += x.at(i) * x.at(j);
		}
	}
	cout << ans/2 << endl;
}
/*


  　　　 _」_
　 　×´　　　  _,,..-──-､,_ｧo､__　　  ｀メ.
　　/　    ,  '"´　 　　　   （-､__oヽ　　　_|__
　 　　　／　　　　　　　　 　 ｀ヽ.ヽﾊ）　 　ﾉ
　　　 ／　　　　　　　　　　　  　 Y⌒ヽ.
　　  /　　 /　　　　　　     ヽ.　 |　　',
　　 ,'　　!　　,　 /!　,| ＿   !.　|　　 !　　
　　　|　  |.__/|_ ,'| / ! __｀./! /|　　 |
　　　|　　|´/ |_/  ﾚ' ｧ'´￣` |／､ﾄ、 　|　　奇跡を起こして計算量をO(N)にします!
　　  '､　 |/ｧ'´￣`  　　　,,　|　|ｿ   　ﾊ　　
　　 　 ＼,ハ ,,　　 '　   　（ ＼|　 / .|
　　　 　 | ﾊ、　i7´￣｀i  ,/ ＼_）,'　 |
　　　　 ,'/｀＞ ､,｀   ,.イ/＼＿_! !　  !　　|
　　 　　/　 /｀     T7´／/ヽ､_＿ﾉ_| 　 |__,メ
　　 　　|  .|r/´`ｰ'-､／　,'./  /::/｀ヽ /
　　　　 八　i/      rﾉ,!￣ヽ､| /:/ 　  i_
　　  　,' X`;くﾄ  ､ノ､　/ﾍ｀ヽ．Y    ／::>
　　　　!　// |::|/.|::|＼/ﾉ 八__ノr:':::／/
　　　　|／　 |::|./|::|/　 ）'ﾉ:/--‐'','
　  　  /　　 八:' _ﾉ::ﾉ　 _,.ｲ／　　　　|
　　 　,'　　　 ＼_ ／,|　 　／　　　 　 !
　　　 |　　　　　　  /|　 ／ 　　　/ 　 |
*/


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	reader io.Reader = os.Stdin
	writer io.Writer = os.Stdout
)

func main() {
	run()
}

func run() {
	var N int
	fmt.Fscan(reader, &N)

	nums := make(map[int]bool)
	{
		scanner := bufio.NewScanner(reader)
		scanner.Scan()
		line := scanner.Text()

		for _, str := range strings.Split(line, " ") {
			num, _ := strconv.Atoi(str)

			if num&1 == 1 {
				fmt.Fprintln(writer, 0)
				return
			}

			nums[num/2] = true
		}
	}

	count := 1

	for ; len(nums) > 0; count++ {
		nextNums := make(map[int]bool)

		for num, _ := range nums {
			if num&1 == 1 {
				fmt.Fprintln(writer, count)
				return
			}

			nextNums[num/2] = true
		}
		nums = nextNums
	}

	fmt.Fprintln(writer, count)
}


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

char s[100001];
int r, sl;

int main()
{
    scanf("%s", s);
    sl = r = (int) strlen(s);
    for (int i = 1; s[i]; i++)
    {
        if (s[i] != s[i-1])
        {
            r = min(r, max(sl - i, i));
        }
    }
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 384
import math

def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

def main():
    X = int(input())

    while True:
        if is_prime(X):
            return X
        X = X + 1

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
def push(k,v):
    if k in dic:
        dic[k] = min(dic[k],v)
    else:
        dic[k] = v
n,x,y = map(int,str(input()).split(' '))
dic = {}
for i in range(0,n):
    a = list(map(int,str(input()).split(' ')))
    k,v =a[0]*y-a[1]*x,a[2]
    l = []
    for j in dic:
        l.append([j,dic[j]])
    for jj in l:
        push(jj[0]+k,jj[1]+v)
    push(k,v)
if 0 in dic:
    print(dic[0])
else:
    print('-1')

Measured memory_bytes: 3316
#include <stdio.h>
int dp[50002];
int min(int a,int b){
  if(a<b)return a;
  else return b;
}
int main(){
  int n,m;
  int i,j;
  int c[22];
  int count=0;
  int inf=10000000;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++)scanf("%d",&c[i]);

  for(i=0;i<=n;i++)dp[i]=inf;
  dp[0]=0;
  
  for(i=0;i<m;i++){
    for(j=c[i];j<=n;j++){
      dp[j]=min(dp[j],dp[j-c[i]]+1);
    }
  }
 
  printf("%d\n",dp[n]);
  return 0;
}

Measured memory_bytes: 788
import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}

    if (N == K) {
        println(1)
        return
    }

    val P = readLine()!!.split(" ").map{it.toInt()}
    val cnt = IntArray(N) { 0 }

    cnt[0] = 1

    for (i in 1 until N) {
        if (P[i - 1] < P[i]) {
            cnt[i] = cnt[i - 1] + 1
        } else {
            cnt[i] = 1
        }
    }

    val sorted = cnt.count { it >= K }

    var res = if (cnt[K - 1] >= K) 0 else 1

    val st = TreeSet<Int>()

    for (i in 0 until K) {
        st.add(P[i])
    }

    for (i in K until N) {
        st.add(P[i])
        var f = false

        if (st.first() != P[i - K] || st.last() != P[i]) {
            res++
            f = true
        }

        st.remove(P[i - K])

        if (f && cnt[i] >= K && sorted >= 2) {
            res--
        }
    }
    if (sorted >= 2) {
        res++
    }

    println(res)
}


Measured memory_bytes: 81056
import math

data = list(map(int, input().split()))
da = (data[2] + data[3] / 60) / 12
db = data[3] / 60
angle = abs(da - db) * 2 * math.pi
c = math.sqrt(data[0] * data[0] + data[1] * data[1] - 2 * data[0] * data[1] * math.cos(angle))
print(c)

Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = 10007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll a, b; cin >> a >> b;
  ll as = 1;
  ll ans = 0;
  if (b-a < 1000000) {
    rep(i, a, b+1) ans ^= i;
    cout << ans << endl;
  } else {
    while (as < a) as *= 2;
    rep(i, a, 4*(a/4+1)) ans ^= i;
    rep(i, b-b%4, b+1) ans ^= i;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

const int maxn = 402;
int dp[maxn][maxn];

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<int> v(n+1), pref(n+1, 0);
    for(int i = 1; i <= n; i++)
        cin >> v[i], pref[i] = pref[i-1] + v[i];
    for(int i = 2; i <= n; i++)
        for(int j = 1; j + i - 1 <= n; j++)
        {
            int l = j, r = j + i - 1;
            dp[l][r] = INF;
            for(int k = l; k < r; k++)
                dp[l][r] = min(dp[l][r],
                 dp[l][k] + dp[k+1][r] + pref[k] - pref[l-1]
                 + pref[r] - pref[k]);
        }
    cout << dp[1][n] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

bool isPrime(int n){
    for(int i = 2; i*i <=n ;i++){
        if(n % i == 0) return false;
    }
    return n != 1;
}

signed main(){
    int n;
    while(cin >> n, n){
        int ans = 0;
        rep(i, n + 1, 2 * n + 1){
            if(isPrime(i)) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2996
#include <stdio.h>
#include <string.h>

int main()
{
	char S[100];
	int cnt, n, i;
	
	scanf("%s", S);
	n=strlen(S);
	cnt=0;
	
	for(i=0; i<n; i++){
		if(S[i]!=S[n-1-i]) cnt++;
	}
	
	printf("%d", cnt/2);
	
return 0;
}

Measured memory_bytes: 128
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad 

main :: IO ()
main = breads >>= main'
    where
        main' [n, t] = replicateM n breads >>= putStrLn . solve t

solve :: Int -> [[Int]] -> String
solve t = judge . map head . filter (\v -> last v <= t)
    where
        judge [] = "TLE"
        judge xs = show $ minimum xs

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define LL long long

LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL N,M,a[100010];
int main(){
    cin>>N>>M;
    LL g=1,ok=1;
    for(int i=1;i<=N;++i){
        cin>>a[i];
        a[i]/=2;
        if(i==1)g=a[i];
        g=lcm(g,a[i]);
        if(g>M)ok=0;
    }
    for(int i=1;i<=N;++i){
        if(g/a[i]%2==0){ok=0;break;}
    }
    if(!ok){
        cout<<0<<endl;
        return 0;
    }
    LL ans=0;
    LL b=M/g;
    ans=b/2;
    if(b&1)ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert
#define mp make_pair

const int MAX = INT_MAX;

int main() {
	int H, W, M;
	cin>>H>>W>>M;
	map<ll, ll> r;
	map<ll, ll> c;
	map<pair<ll, ll>, bool> values;
	ll max_r = 0, max_c = 0;
	for (int i = 0;i < M;++i) {
		ll x, y;
		cin>>x>>y;
		values[mp(x, y)] = true;
		r[x] += 1;
		max_r = max(max_r, r[x]);
		c[y] += 1;
		max_c = max(max_c, c[y]);
	}

	vector<ll> max_rows;
	vector<ll> max_cols;

	for (auto& x : r) {
		if (x.second == max_r) {
			max_rows.pb(x.first);
		}
	}

	for (auto& x : c) {
		if (x.second == max_c) {
			max_cols.pb(x.first);
		}
	}

	bool f = false;
	for (int i = 0;i < max_rows.size() && !f;++i) {
		for (int j = 0;j < max_cols.size() && !f;++j) {
			if (!values[mp(max_rows[i], max_cols[j])]) {
				f = true;
				break;
			}
		}
	}

	printf("%lld\n", f ? max_r + max_c : max_r + max_c - 1);
	return 0;
}


Measured memory_bytes: 67844
#include<iostream>
using namespace std;
int main()
{
  int k; cin>>k; string s; cin>>s;
  if(s.size() <= k)
    	cout<<s;
  else 
  {
    string ans;
    for(int i = 0; i < k; i++)
      	ans+=s[i];
    ans+="...";
    cout<<ans;
  }
}

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

using namespace std;

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

	vector<int> A(N);
	bool answer = true;

	for (int i = 0; i < N; i++) 
	{
		cin >> A.at(i);

		if (A.at(i) % 2 == 0)
		{
			if (A.at(i) % 3 != 0 && A.at(i) % 5 != 0)
			{
				answer = false;
				break;
			}
		}
	}
	if (answer == true) 
	{
		cout << "APPROVED" << endl;
	}
	else 
	{
		cout << "DENIED" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n+1],b[n+1];
  
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=1;i<=n;i++)
    b[i]=INT_MAX;
  b[1]=0;
  for(int i=1;i<=n-1;i++)
  {
    for(int j=i+1;j<=i+k && j<=n;j++)
    {
      b[j]=min(b[j],b[i]+abs(a[j]-a[i]));
    }
  }
  cout<<b[n]<<endl;
}
               

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

const int kN = 5000 + 5;
const int kM = 200 + 5;
const long long kInf = 1'000'000'000;
long long s[kN];
int b[kN][kM], a[kN];

struct Sparse {
    int sp[14][kN];

    Sparse() = default;

    Sparse(const vector<int> &v) {
        for (int i = 0; i < v.size(); ++i) sp[0][i] = v[i];
        for (int i = 1; (1 << i) <= v.size(); ++i) {
            for (int j = 0; j + (1 << i) <= v.size(); ++j)
                sp[i][j] = max(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]);
        }
    }

    int Query(int l, int r) {
        int p = 31 - __builtin_clz(r - l + 1);
        return max(sp[p][l], sp[p][r - (1 << p) + 1]);
    }
} sp[kM];

long long DivideConquer(int l, int r, int fl, int fr, int m) {
    if (l > r) return -kInf;
    int md = (l + r) >> 1;
    long long kp = -kInf;
    int fm = -1;
    for (int i = fl; i <= min(fr, md); ++i) {
        long long dist = s[md] - s[i], val = 0;
        for (int j = 0; j < m; ++j) val += sp[j].Query(i, md);
        if (val - dist > kp) {
            kp = val - dist;
            fm = i;
        }
    }
    long long res = max(DivideConquer(l, md - 1, fl, fm, m), DivideConquer(md + 1, r, fm, fr, m));
    return max(res, kp);
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 0; i < n - 1; ++i) scanf("%d", &a[i]);
    for (int i = 1; i < n; ++i) s[i] = s[i - 1] + a[i - 1];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) scanf("%d", &b[i][j]);
    }
    for (int i = 0; i < m; ++i) {
        vector<int> v(n);        
        for (int j = 0; j < n; ++j) v[j] = b[j][i];
        sp[i] = Sparse(v);
    }
    printf("%lld\n", DivideConquer(0, n - 1, 0, n - 1, m));
}


Measured memory_bytes: 60672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef pair<int,float> pif;
typedef pair<float,int> pfi;
typedef pair<float,float> pff;
#define F first
#define S second
#define PB push_back
#define MP make_pair
int main(){
ios:: sync_with_stdio(0);
cin.tie(0);
int n;
std::cin >> n;
vi v(n,0);
for (int i = 0; i < n; i++) {
  std::cin >> v[i];
}
vi dp(1e5+10,1e9);
dp[0] = 0;
dp[1] = abs(v[1]-v[0]);
for (int i = 2; i < n; i++) {
  dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
}
std::cout << dp[n-1] << '\n';
return 0;
}
//to run the program use asd frog1.cpp


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

const char nl = '\n';

void solve()
{
    int n; cin >> n;
    ll sum = 0;
    unordered_map<ll, ll> count;
    int a;
    while (n--) {
        cin >> a;
        sum += a;
        ++count[a];
    }
    int q; cin >> q;
    while (q--) {
        int b, c; cin >> b >> c;
        ll valcount = count[b];
        sum -= b * valcount;
        count.erase(b);
        sum += c * valcount;
        count[c] += valcount;
        cout << sum << nl;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 6616
N,M=map(int, raw_input().split())

l_max=-1
r_min=float("inf")
for i in range(M):
	l,r=map(int, raw_input().split())
	l_max=max(l_max, l)
	r_min=min(r_min, r)

if r_min<l_max:
	print 0
else:
	print r_min-l_max+1

Measured memory_bytes: 33896
#include<stdio.h>

int cnt[221212];
int X[221212];
int main() {
	int i, j;
	for (i = -200; i <= 200; i++) {
		for (j = i; j <= 200; j++) {
			if (i == 0||j==0)cnt[i*i + j*j] += 2;
			else cnt[i*i + j*j]++;
		}
	}
	for (i = 0; i <= 20000; i++) {
		for (j = 0; i*j <= 20000&&j<=20000; j++) {
			if (cnt[i] && cnt[j])X[i*j] += cnt[i];
		}
	}
	int t, tc;
	scanf("%d", &t);
	for (tc = 0; tc < t; tc++) {
		int a, b;
		scanf("%d%d", &a, &b);
		puts(X[a*a + b*b] != 8 ? "C" : "P");
	}
	return 0;
}


Measured memory_bytes: 2972
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N,K,S = inpl()

if S != 10**9:
    ans = [S] * K + [10**9] * (N-K)
else:
    ans = [S] * K + [1] * (N-K)

print(" ".join(map(str,ans)))


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
using namespace std;

const int N = 20;
int A[N];
int x[N][N], y[N][N];

void solve() {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> A[i];
    REP(j, A[i]) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  int ans = 0;
  bool ok = true;
  REP(bits, (1 << n)) {
    ok = true;
    REP(i, n) {
      if (!(bits & (1 << i)))
        continue;
      REP(j, A[i]) {
        if (bits & (1 << x[i][j]))
          ok &= y[i][j];
        else
          ok &= !y[i][j];
      }
    }
    if (ok)
      ans = max(ans, (int)__builtin_popcount(bits));
  }
  cout << ans << endl;
}

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

  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    int n = sizeof(a)/sizeof(a[0]); 
    sort(a, a+n); 
    //a.sort();
    if(a[0]+a[1]==a[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        v: [u64;n]
    }
    let mut v = v;
    v.sort();
    let v: Vec<f64> = v.iter().map(|x| *x as f64).collect();
    let mut res = v[0];
    for x in v.iter().skip(1) {
        res = (res + x) / 2.0;
    }
    println!("{}", res);
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
x =0
for i,w in enumerate(a):
    x += (-1)**i*w
ans = [x]
for i,t in enumerate(a):
    ans.append(int(((ans[i]/2)-t)*(-2)))
print(' '.join(map(str, ans[:-1])))

Measured memory_bytes: 19912
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
// #include<dbg.h>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	int n;
	cin>>n;
	vector<vector<int>> nums(n,vector<int>(n,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) cin>>nums[i][j];
	}
	vector<int> dp(1<<n,0);
	dp[0]=1;
	for(int i=1;i<(1<<n);i++){
		int cnt = 0;
		int ti = i;
		while(ti){
			cnt+=ti%2;
			ti>>=1;
		}
		for(int j=0;j<n;j++){
			if((1<<j)&i && nums[cnt-1][j]){
				dp[i] = (dp[i]+dp[i-(1<<j)]) %MOD;
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long x;
  cin >> x;
  long year = 0;
  long money = 100;
  while (money < x) {
    year++;
    money +=money/100;
  }
  cout << year << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
char buf[20];
int main(){
  int n;
  cin >> n;
  string dup;
  getline(cin,dup);
  for(int i = 0;i < n;i++){
    string str;
    getline(cin,str);

    int j = 0;
    vector<int> array1  = vector<int>(4);
    vector<int> array2  = vector<int>(4);
    vector<int> p = vector<int>(array1);
    int keep = 1;
    for(int i = 0;i < str.length();i++){
      char a = str[i];
      if('2' <= a && '9' >= a ){
	keep = a - '0';
	//cout << a<<" " <<keep << "     dddd" <<endl;
      }
      else if('m' == a){
	p[0] = keep;
	keep = 1;
      }
      else if('c' == a){
	p[1] = keep;
	keep = 1;
      }
      else if('x' == a){
	p[2] = keep;
	keep = 1;
      }
      else if('i' == a){
	p[3] = keep;
	keep = 1;
      }
      else if(' ' == a){
	array1 = vector<int>(p);
	p = vector<int>(array2);;
	keep  = 1;
      }
	
    }
    array2 = vector<int>(p);
    int flag = 0;
    vector<int> ans = vector<int>(4);
    for(int i = 3;i >= 0;i--){
      if(flag == 1){
	if(array1[i]+array2[i]+1 >=10){
	  flag = 1;
	  ans[i] = (array1[i]+array2[i]+1)%10;
	}else{
	  flag = 0;
	  ans[i] = array1[i]+array2[i]+1;
	}
      }else{
	if(array1[i]+array2[i] >=10){
	  flag = 1;
	  ans[i] = (array1[i]+array2[i])%10;
	}else{
	  flag = 0;
	  ans[i] = array1[i]+array2[i];  
	}
      }
    }/*
    cout << "-------" << endl;
    for(int i = 0;i < 4;i++){
      cout << ans[i] << endl;
    }
    cout << "-------" << endl;*/
    for(int i = 0;i < 4;i++){
      if(ans[i] != 0){
	if(ans[i] != 1){
	  cout << ans[i];
	}
	if(i == 0){
	  cout << "m";
	}
	if(i == 1){
	  cout << "c";
	}
	if(i == 2){
	  cout << "x";
	}
	if(i == 3){
	  cout << "i";
	}
      }
    }
    cout << endl;
    
  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	bool isclear = true;
	int a = 0;
	cin >> n;
	while(n--){
		string s;
		cin >> s;
		if(isclear){
			if(s == "A")a++;
			else if(s == "Un" && a > 0)a--;
			else isclear = false;
		}
	}
	if(isclear && a == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3256