akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

struct Union_find
{
    vector<int> par;
    vector<int> rank;

    Union_find(int n) : par(n), rank(n)
    {
        for (int i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
        }
    }

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

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

    void unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        //根にのみランクが保持されればいい
        if (rank[x] < rank[y])
            par[x] = y;
        else
        {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
        return;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    Union_find uf(n);
    int x, y;
    rep(i, m){
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }
    int count = 0;
    rep(i, n){
        if (uf.same(i, p[i]-1))
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main() {
  int a, b;
  char op;
  while (scanf("%d %c %d", &a, &op, &b), op != '?') {
    if (op == '+') printf("%d\n", a + b);
    else if (op == '-') printf("%d\n", a - b);
    else if (op == '*') printf("%d\n", a * b);
    else printf("%d\n", a / b);
  }
}


Measured memory_bytes: 2640
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import defaultdict

    n, m, p = map(int, readline().split())
    edge = defaultdict(list)

    for _ in range(m):
        a, b, c = map(int, readline().split())
        edge[a - 1].append((b - 1, -c + p))

    dist = [INF] * n
    dist[0] = 0

    for _ in range(n - 1):
        for u in range(n):
            for v, w in edge[u]:
                dist[v] = min(dist[v], dist[u] + w)

    for _ in range(n):
        for u in range(n):
            for v, w in edge[u]:
                if dist[v] > dist[u] + w:
                    dist[v] = -INF

    if dist[n - 1] == -INF:
        print(-1)
    else:
        print(max(-dist[n - 1], 0))


if __name__ == '__main__':
    main()


Measured memory_bytes: 75400
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
void ABC157(void);

int main(void){
    ABC157();
}

void ABC157(){
    int bingo[3][3];
    int n,i,j,k,ans=0;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin>>bingo[i][j];
        }
    }
    cin>>n;
    vector<int>vec(n);
    for(i=0;i<n;i++){
        cin>>vec.at(i);
    }
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            for(k=0;k<n;k++){
                if(bingo[i][j]==vec.at(k))bingo[i][j]=0;
            }
        }
    }
    for(i=0;i<3;i++){
        if(bingo[0][i]==0&&bingo[1][i]==0&&bingo[2][i]==0)ans=1;
        if(bingo[i][0]==0&&bingo[i][1]==0&&bingo[i][2]==0)ans=1;
    }
    if(bingo[0][0]==0&&bingo[1][1]==0&&bingo[2][2]==0)ans=1;
    if(bingo[0][2]==0&&bingo[1][1]==0&&bingo[2][0]==0)ans=1;
    if(ans==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end() 
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
using namespace std;

int main()
{
	string s; cin >> s;
	int ans = 0, i = 0, j = s.length() - 1;
	while(i <= j)
	{
		ans += (s[i] != s[j]);
		i++; j--;
	}
	cout << ans;
	return 0;
}

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,a,n) for(ll i=a;i<(ll)(n);i++)

int main(){
   int N; cin>>N;
   N %= 1000;
   if(N != 0) N = 1000 - N;
   cout << N << endl;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
    ll n;
    cin>>n;
    vector<ll> v;
    rep(i,0,n){
      ll a;
      cin>>a;
      v.pb(a);
    }
    ll ans = 0;
    rep(i,0,n){
      rep(j,i+1,n){
        ans += v[i]*v[j];
      }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main ()
{
	string a,b,c;
	int d,e;
	cin>>a>>b>>c;
	d=a.size();
	e=b.size();

	if(a[d-1]==b[0]&&b[e-1]==c[0])
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}



Measured memory_bytes: 256
W, H, c = input().split(); W = int(W); H = int(H)
print("+" + "-"*(W-2) + "+")
for i in range((H-3)//2):
    print("|" + "."*(W-2) + "|")
print("|" + "."*((W-3)//2) + c + "."*((W-3)//2) + "|")
for i in range((H-3)//2):
    print("|" + "."*(W-2) + "|")
print("+" + "-"*(W-2) + "+")


Measured memory_bytes: 5592
import java.util.*;


class Main {
    public static void main(String args[]) {
        try (Scanner sc = new Scanner(System.in)) {
            while (true) {
                int H = sc.nextInt(), W = sc.nextInt();
                if (H == 0 && W == 0) {
                    break;
                }
                for (int i = 0; i < H; i++) {
                    for (int j = 0; j < W; j++) {
                        if (i == 0 || j == 0 || i == H - 1 || j == W - 1) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                    System.out.println("");
                }
                System.out.println("");
            }
        }
    }
}


Measured memory_bytes: 32680
n = int(input())
l = [int(i) for i in input().split()]

nl = sorted(l, reverse=True)

a = 0
b = 0

for i in range(n):
  if i % 2 == 0:
    a += nl[i]
  else:
    b += nl[i]
    
print(a - b)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(" ").map(String::toInt)
    val tn = readLine()!!.split(" ").map(String::toInt)

    var sum = t
    for (i in 1 until tn.size) {
        val previous = tn[i - 1] + t
        if (tn[i] <= previous) {
            sum += (tn[i] + t) - previous
        } else {
            sum += t
        }
    }
    println(sum)
}



Measured memory_bytes: 80712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CManagement solver = new CManagement();
        solver.solve(1, in, out);
        out.close();
    }

    static class CManagement {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            a[0] = -1;
            HashMap<Integer, Integer> bossNb = new HashMap<>();
            for (int i = 1; i < n; i++) {
                a[i] = in.nextInt() - 1;
                int tmp = bossNb.getOrDefault(a[i], 0);
                bossNb.put(a[i], tmp + 1);
            }

            for (int i = 0; i < n; i++) {
                out.println(bossNb.getOrDefault(i, 0));
            }
            //out.print("Case #"+ testNumber + ": ");
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

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

    }
}



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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
   int n; cin >> n;
   int a[n];
   rep(i,0,n) cin >> a[i];

   int ans = 0;
   rep(i,0,n){
      rep(j,i+1,n){
         rep(k,j+1,n){
            if(a[i] != a[j] && a[j] != a[k] && a[i] != a[k]
               && a[i]+a[j] > a[k]
               && a[j]+a[k] > a[i]
               && a[k]+a[i] > a[j]
            ) ans++;
         }
      }
   }
   cout << ans << "\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define N 100055
#define ll long long
int dp[N],ar[N];
int main() {
    for(auto &i : dp){
        i = 2e9;
    }
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1; i<=n; ++i)
        scanf("%d",&ar[i]);
    dp[0] = dp[1] = 0;
    for(int i=2; i<=n; ++i) {
        for(int j = 1 ; i-j>=1 && j <= k ; ++j){
            dp[i] = min(dp[i], dp[i-j] + abs(ar[i-j] - ar[i] ) );
        }
    }
    printf("%d",dp[n]);
    return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

double area(double a, double b, double c) {
	return sin((b-a)*2*M_PI)/2 + sin((c-b)*2*M_PI)/2 + sin((a-c)*2*M_PI)/2;
}

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

	int n, m;
	while(cin >> n >> m, n|m) {
		double dp[40][40][40] = {};
		double p[n];
		REP(i, n)
			cin >> p[i];
		REP(i, m-2) {
			REP(j, n-2) {
				FOR(k, j+2, n) {
					FOR(l, j+1, k) {
						if(i)
							dp[i][j][k] = max(dp[i][j][k], dp[i-1][j][l] + area(p[j], p[l], p[k]));
						else
							dp[i][j][k] = max(dp[i][j][k], area(p[j], p[l], p[k]));
					}
				}
			}
		}
		double ans = -1;
		REP(i, n) REP(j, n)
			ans = max(ans, dp[m-3][i][j]);
		cout << fixed << setprecision(6) << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1864
import sys

a, b, c, d, e, f = map(int, sys.stdin.readline().split())

def main():
    w = set()
    s = set()
    for i in range(0, f + 1, 100 * a):
        for j in range(0, f - i + 1, 100 * b):
            w.add(i + j)
    for i in range(0, f + 1, c):
        for j in range(0, f - i + 1, d):
            s.add(i + j)
    w = sorted(w)[1:]
    s = sorted(s)
    y = x = 0
    for i in w:
        for j in s:
            if i + j > f: break
            if j * (100 + e) > e * (i + j): break
            if (j * y >= x * (i + j)):
                y = i + j
                x = j
    print(y, x)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
  int n;
  string s;
  cin>>n;
  for(int i=0; i<n; i++) {
    cin>>s;
    vector<char> v;
    for(int j=0; j<s.length(); j++)
      v.push_back(s[j]);
    sort(v.begin(), v.end());
    string min,max;
    for(int j=0; j<v.size(); j++) {
      min += string(1,v[j]);
      max += string(1,v[v.size()-j-1]);
    }
    int ma=atoi(max.c_str()),mi=atoi(min.c_str());
    cout<<ma-mi<<endl;
  }
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

N = int(input())
A = np.array(input().split(),dtype=np.int64)
B = np.array(input().split(),dtype=np.int64)

diff = A-B
lack = -diff[diff<0]
remain = diff[diff>0]

x = lack.sum()
remain.sort()
cum = remain[::-1].cumsum()
y = 0 if x == 0 else np.searchsorted(cum,x) + 1

answer = len(lack) + y if y <= len(remain) else -1

print(answer)

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

using namespace std;

//#define FILE_IO

const int mod = 1e9 + 7;

int N;
int dp[1000005];
int sum[1000005];
int ans;

int add(int x, int y) {x += y; if(x >= mod) x -= mod; return x;}
int mul(int x, int y) { return (1LL * x * y) % mod; }

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

    int inv2 = 500000004;
    scanf("%d", &N);
    dp[0] = 1;
    sum[0] = 1;
    for(int i = 1; i <= N; i++)
    {
        dp[i] = dp[i - 1];
        if(i >= 3)  dp[i] = add(dp[i], sum[i - 3]);
        sum[i] = (sum[i - 1] + dp[i]) % mod;
    }

    ans = dp[N];
    ans = add(ans, mul(dp[N - 1], N - 1));
    for(int i = N - 1; i >= 1; i--)
    {
        int lgt = N - i + 1;
        int cnt = N - lgt + 1;
        int cnt2 = N - 1 - cnt;
        ans = add(ans, mul(dp[i - 1], mul(cnt, N)));
        ans = add(ans, mul(dp[i - 1], mul(cnt2, N - 1)));
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll dp[105][200005]={0};
ll solve(ll i,ll n,ll w[200005],ll v[200005],ll s)
{
  if(s==0)
    return dp[i][s]=0;
   if(i==0)
   {
     if(v[0]==s)
     return dp[i][s]=w[i];
     return dp[i][s]=1000000007;  
   }
 if(dp[i][s]!=-1)
   return dp[i][s];
  dp[i][s]=solve(i-1,n,w,v,s);
  if(s<w[i])
    return dp[i][s];
  dp[i][s]=min(dp[i][s],w[i]+solve(i-1,n,w,v,s-w[i]));
  return dp[i][s];
}
int main()
{
  for(int i=0;i<105;i++)
    for(int j=0;j<200005;j++)
      dp[i][j]=-1;
  ll n,w[200005],wei,v[200005];
  cin>>n>>wei;
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>v[i]; 
  }
 ll maxval=n*1000,i;
  for(i=0;i<=maxval;i++)
  {
       dp[0][i]=1e9+7;
  }
  dp[0][v[0]]=w[0];
  dp[0][0]=0;
  for(int i=1;i<n;i++)
  {
    for(int j=0;j<=maxval;j++)
    {
      dp[i][j]=dp[i-1][j];
      if(v[i]>j)
        continue;
      dp[i][j]=min(dp[i][j],w[i]+dp[i-1][j-v[i]]);
    }
  }
  ll ans=0;
  for(i=0;i<=maxval;i++)
  {
    if(dp[n-1][i]<=wei)
      ans=i;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 167684
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n;
    cin >> n;
    if(n < 1200){
        cout << "ABC";
    }else if(n < 2800){
        cout << "ARC";
    }else{
        cout << "AGC";
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int A[200100];
int index[200100];
int main(){
    int N;
    cin >> N;
    ll ans = 0;
    REP(i,N){
        int a;
        cin >> a;
        A[i] = a;
        a--;
        index[a] = i;
    }
    
    set<int> s;
    s.insert(N);
    s.insert(-1);
    REP(i,N){
        int ind = index[i];
        set<int>::iterator itr = s.lower_bound(ind);
        ll right = *itr - ind;
        itr--;
        ll left = ind - *itr;
        ans += A[ind]*left*right; 
        s.insert(ind);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N;
  cin>>N;
  map A;
  rep(i,0,N) {
    string S;
    cin>>S;
    A[S]++;
  }
  cout<<A.size()<<endl;
}
      

Measured memory_bytes: 19116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;
#define int long long
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n;
    vector<int> q;
    map<int,int> mp;
    for(int i=0;i<n;i++) {
        cin >> a;
        q.push_back(a);
    }
    int ans=0;
    vector<int> e;
    e.push_back(0);
    for(int i=0;i<n;i++){
        e.push_back(e[i]+q[i]);
    }
    for(int i=0;i<e.size();i++){
        mp[e[i]]++;
    }
    for(auto e : mp){
        ans+=(e.second*(e.second-1))/2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15856
// #include <boost/multiprecision/cpp_int.hpp> 
// using namespace boost::multiprecision; 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define REP(i,a,b) for(long long int i=a ; i<b ; i++)
#define mp make_pair
#define INF 1000000000000000000
#define mod 1000000007
#define pi pair<ll,ll>
#define pd pair<ld,ld>
#define vi vector<ll>
#define vd vector<ld>
#define vvi vector<vi>
#define vvd vector<vd>
#define vpi vector<pi>
#define vpd vector<pd>
#define us unordered_set<ll>
#define um unordered_map<ll,ll>
#define sortA(a) sort(a.begin(),a.end())
#define sortD(a) sort(a.begin(),a.end(),greater<ll>())
#define all(a) a.begin(),a.end()
#define N 100005


#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define in insert
#define fbo find_by_order
#define ook order_of_key


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll powmod(ll x,ll y)
{
	if(x==0)
		return 0;
	if(y==0 || x==1)
		return 1;
	if(y%2==0)
		return powmod((x*x)%mod,y/2)%mod;
	return (x*powmod(x,y-1)%mod)%mod;
}
void print1D(vi a)
{
	for(ll i=0;i<a.size();++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
void print2D(vector<vi> a)
{
	for(ll i=0;i<a.size();++i)
	{
		for(ll j=0;j<a[i].size();++j)
		{
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}
void solve()
{
	ll n,m;
	cin>>n>>m;
	vi a(m);
	ll sum=0;
	for(ll i=0;i<m;++i)
	{
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)
	{
		cout<<-1;
	}
	else
	{
		cout<<n-sum;
	}
}
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
	ll t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3740
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;
ll mod;
ll add(ll x,ll y){return (x+y)%mod;}
ll mul(ll x,ll y){return (x*y)%mod;}
ll pow(ll x,ll y){
  ll v=1;
  for(;y;x=mul(x,x),y>>=1)
    if(y&1)v=mul(v,x);
  return v;
}
ll divi(ll x,ll y){return mul(x,pow(y,mod-2));}

string s;
int pos,flg;
ll calc();

ll getNum(){
  if(s[pos]=='('){
    pos++;
    return calc();
  }
  ll res=0;
  while('0'<=s[pos]&&s[pos]<='9'){
    res=mul(res,10);
    res=add(res,s[pos]-'0');
    pos++;
  }
  return res;
}

ll calc(){
  stack<ll> st;
  st.push(getNum());
  while(1){
    char ch=s[pos++];
    if(ch==')'||ch==' ')break;
    ll num=getNum();
    if(ch=='+')st.push(num);
    else if(ch=='-')st.push(mod-num);
    else if(ch=='*'){
      ll x=st.top();st.pop();
      st.push(mul(x,num));
    }else if(ch=='/'){
      ll x=st.top();st.pop();
      if(num==0)flg=1;
      st.push(divi(x,num));
    }
  }
  ll res=0;
  while(!st.empty()){
    res=add(res,st.top());
    st.pop();
  }
  return res;
}

int main(){
  string str;
  while(1){
    getline(cin,str);
    int k;
    mod=0;
    for(k=0;k<(int)str.size();k++){
      if(str[k]==':')break;
      mod*=10LL;
      mod+=(str[k]-'0');
    }
    if(mod==0)break;
    s="";
    for(k=k+1;k<(int)str.size();k++){
      if(str[k]==' ')continue;
      s.push_back(str[k]);  
    }
    s.push_back(' ');
    pos=flg=0;
    ll ans=calc();
    if(flg==0){
      cout<<s<<"= "<<ans<<" (mod "<<mod<<")"<<endl;
    }else{
      cout<<"NG"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1324
using System;
using System.Collections.Generic;
using System.Linq;
namespace KCLC
{
  class Program
  {
    static void Main()
    {
      int Input = int.Parse(Console.ReadLine());
      if(Input >= 30){Console.WriteLine("Yes");}
      else{Console.WriteLine("No");}
    }
  }
}


Measured memory_bytes: 27328
#include<stdio.h>
int main(){
	int i,j,N;
	int A[100];
	int v;
	
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	for(j=0;j<N;j++){
		printf("%d",A[j]);
		if(j!=N-1)printf(" ");
	}
	printf("\n");
	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=v;
		
		for(j=0;j<N;j++){
			printf("%d",A[j]);
			if(j!=N-1)printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  rep(i,5) {
    int a;
    cin >> a;
    if(a == 0) cout << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
n,=list(map(int, input().split())) 
A = list(map(int, input().split())) 
count=0
ma = A[0]
for i in range(1,n):
  if A[i]<= ma:
    count += ma - A[i]
  else:
    ma = A[i]
print(count)    
    

Measured memory_bytes: 32252
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin>>
#define co cout<<
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{


long long x;
cin>>x;
std::vector<int> v(x);
long long rahul;
cin>>rahul;

long long count=0;
for (int i = 0; i < x; ++i)
{
	/* code */
	cin>>v[i];
	if (v[i]>=rahul)
	{
count++;		/* code */
	}
}

cout<<count<<endl;

return 0;
}



Measured memory_bytes: 3636
import math

nyan = []
sum = 0
for i in range(5):
  nyan.append(int(input()))

min = nyan[0]
num = 0
for i in range(5):
  if (min%10) > (nyan[i]%10) and (nyan[i]%10) != 0 or (min %10) == 0:
    min = nyan[i]
    num = i

for i in range(5):
  if num != i:
    nyan[i] = math.ceil(nyan[i]/10)*10
    sum += nyan[i]
sum += nyan[num]
print(sum)

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

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    ll now = 1, ans = 0;
    rep(i, N) {
        if (now == a[i]) {
            now++;
        } else {
            ans++;
        }
    }
    if (now == 1) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


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

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

typedef long long ll;

int main() {
    ll l, k;
    cin >> l >> k;
    if (k == 1) {
        ll p = l / 2;
        if (p % 2 == 0) p--;
        cout << p << endl;
    } else {
        ll dp[100][l];
        rep(i, 100)rep(j, l) dp[i][j] = 0;
        dp[0][0] = 1;
        rep(i, 99)rep(j, l) {
            if (j + 2 < l) dp[i + 1][j + 2] += dp[i][j];
            if (j + k + 1 < l) dp[i + 1][j + k + 1] += dp[i][j];
        }
        ll cnt = 0;
        rep(i, 100)rep(j, l) {
            if (j <= l - k) cnt += dp[i][j] * 2;
            else cnt += dp[i][j];
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        if(((bit>>i)&1)==0||ok(i,bit)==false)continue;
        for(int j=i+1;j<n;j++){
            if(((bit>>j)&1)==0)continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(c[i]==c[j]&&ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}



int main(){
    while(input())solve();
    return 0;
}

Measured memory_bytes: 17544
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
   
int main() {
    ios::sync_with_stdio(false);
    cin.tie();
    int n , k , c = 0;
    cin >> n >> k;
    int a[n];
    for( int i = 0 ; i < n ; i++ ) cin >> a[i];
    sort( a , a + n );
    for( int i = 0 ; i < n ; i++ ) if ( a[i] != a[i + 1] ) c++;
    int b[c] , x = 0;
    for( int i = 0 ; i < c ; i++ ) b[i] = 0;
    for( int i = 0 ; i < n ; i++ ) {
        b[x]++;
        if ( a[i] != a[i + 1] ) x++;
    }
    if( c <= k ) {
        cout << 0;
    } else {
        sort( b , b + c );
        int ans = 0;
        for( int i = 0 ; i < c - k ; i++ ) ans += b[i];
        cout << ans;
    }
}


Measured memory_bytes: 5124
sameElem::[Char]->[Char] -> [Char]
sameElem a b = [x|x<-['a'..'z'], elem x a && elem x b]
sameCount::[Char]->Int->Int
sameCount xs n = do
    let (a, b) = splitAt n xs
    length $ sameElem a b
mapdeath::[Char]->[Int]->[Int]
mapdeath s= map (sameCount s)
abc098b = do
    n <- readLn::IO Int
    s <- getLine::IO [Char]
    let res = mapdeath s [0..n]
    print $ maximum res
main = abc098b

Measured memory_bytes: 1020
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

  ll dp[K+1][K+1] = {};
  dp[0][0] = 1;
  repi(b, 1, K+1){
    repi(i, 1, b+1){
      dp[b][i] = ((b+i-1) * dp[b-1][i] + (N-K-i+2) * dp[b-1][i-1]) % MOD;
      // printf("b:%lld i:%lld dp:%lld\n", b, i, dp[b][i]);
    }
  }
  ll fact = 1;
  repi(i, 1, K+1) fact = (fact * i) % MOD;
  ll factinv = modinv(fact, MOD);
  repi(i, 1, K+1){
    ll ans = factinv * dp[K][i] % MOD;
    cout << ans << endl;
  }
  return 0;
}


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

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

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

//C++14 (GCC 5.4.1)
int main() {
    int N,K;
    cin >>N>>K;

    vector<int> h(N);
    rep(i,N) cin >> h[i];
    
    sort(h.begin(),h.end());
    //-----------------------------------
    int ans=h[N-1]-h[0];
    rep(i,N-K+1){
        chmin(ans,h[i+K-1]-h[i]);
    }

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

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;

int main() {
char c;
cin >> c;
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
}
else cout << "consonant" << endl;
}


Measured memory_bytes: 256
import math
a,b = map(str, input().split())
ab = int(a+b)
sq = math.sqrt(ab)
if sq % 1 < 0.01:
  sq2 = sq**2
  if sq2 == ab:
    ans = 'Yes'
  else:
    ans = 'No'
else:
  ans = 'No'
print(ans)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int m = max(max(A, B), C);
	int ans = A + B + C + 9*m;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner

object Main extends App  {
  val sc = new Scanner(System.in)

  val iS = sc.next

  val s = iS.toVector :+ 'Z'

  val res =
    s.foldLeft((0L,0L)){case ((strL, stackL), ch) =>
        ch match{
          case 'S'                => (strL, stackL + 1L)
          case 'T' if stackL > 0 => (strL, stackL - 1L)
          case 'T'                => (strL + 1L, stackL)
          case _                  => (strL + stackL, 0L)
        }
    }._1

  println(res)
}


Measured memory_bytes: 36488
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

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

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

long a[100001];
long b[100000];

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


	for (int i = 0; i < n + 1; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	int long long toubatu = 0;
	for (int i = 0; i < n; i++)
	{
		int mm = min(a[i], b[i]);
		a[i] -= mm;
		b[i] -= mm;
		toubatu += mm;

		if (a[i] == 0)
		{
			//次の村の退治もできる
			int mm2 = min(a[i + 1], b[i]);
			a[i + 1] -= mm2;
			b[i] -= mm2;
			toubatu += mm2;
		}
	}
	cout << toubatu;
}


Measured memory_bytes: 33024
S=input()
count=0
s=list(S)
for i in range(len(S)):
    if (i+1)%2!=0:
        if s[i]=='R' or s[i]=='U' or s[i]=='D':
            count+=1
    else:
        if s[i]=='L' or s[i]=='U' or s[i]=='D':
            count+=1
if count==len(S):
    print('Yes')
else:
    print('No')

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

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

  string s; cin >> s;
  int a = 0;
  int k = 1000;
  for(int i = 0; i < 4; i++){
    a += (int)(s[i]-'0') * k;
    k /= 10;
  }

  int b = 0;
  k = 10;
  for(int i = 5; i < 7; i++){
    b += (int)(s[i]-'0') * k;
    k /= 10;
  }

  int c = 0;
  k = 10;
  for(int i = 8; i < 10; i++){
    c += (int)(s[i]-'0') * k;
    k /= 10;
  }

  //cout << a << " " << b << " " << c << endl;
  if(a <= 2019 && b <= 4 && c <= 30){
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 4000 + 5;

int n;
char s[N];
set<int> ss[3];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>s+1;
	ll res=0;
	vector<int> G[3];
	for(int i=1;i<=n;i++){
		if(s[i]=='R') G[0].push_back(i),ss[0].insert(i);
		if(s[i]=='G') G[1].push_back(i),ss[1].insert(i);
		if(s[i]=='B') G[2].push_back(i),ss[2].insert(i);
	}
	for(int i=1;i<=n-3;i++){
		for(int j=i+3;j<=n;j++){
			if(s[i]==s[j]) continue;
			char x=s[i],y=s[j];
			int u,v,w;
			if(x=='R') u=0;
			else if(x=='G') u=1;
			else if(x=='B') u=2;
			if(y=='R') v=0;
			else if(y=='G') v=1;
			else if(y=='B') v=2;
			w=3-u-v;
			int L=upper_bound(G[w].begin(),G[w].end(),i)-G[w].begin();
			int R=upper_bound(G[w].begin(),G[w].end(),j)-G[w].begin();
			res+=(R-L);
		}
	}
	for(int i=1;i<=n-3;i++){
		for(int j=i+3;j<=n;j++){
			if((i+j)%2!=0) continue;
			if(s[i]==s[j]) continue;
			char x=s[i],y=s[j];
			int u,v,w;
			if(x=='R') u=0;
			else if(x=='G') u=1;
			else if(x=='B') u=2;
			if(y=='R') v=0;
			else if(y=='G') v=1;
			else if(y=='B') v=2;
			w=3-u-v;
			int k=(i+j)/2;
			if(ss[w].find(k)!=ss[w].end()) res--;
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 3808
///.....FROG-1....///

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return (Long.parseLong(next()));
        }

        String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return s;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n = in.nextInt();
        int h[] = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }
        int dp[] = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
           // System.out.println(Math.abs(h[i] - h[i - 1]) + dp[i - 1]+" "+Math.abs(h[i] - h[i - 2]) + dp[i - 2]);
            dp[i] = Math.min(Math.abs(h[i] - h[i - 1]) + dp[i - 1], Math.abs(h[i] - h[i - 2]) + dp[i - 2]);
        }
        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 42728
#include<stdio.h>
int main(){
	int a[4],b[4];
	while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])){
		
		scanf("%d%d%d%d",&b[0],&b[1],&b[2],&b[3]);
		int hit=0,blow=0;
		if(a[0]==b[0])hit++;
		if(a[1]==b[1])hit++;
		if(a[2]==b[2])hit++;
		if(a[3]==b[3])hit++;
		if(a[0]==b[1])blow++;
		if(a[1]==b[2])blow++;
		if(a[2]==b[3])blow++;
		if(a[1]==b[0])blow++;
		if(a[2]==b[1])blow++;
		if(a[2]==b[0])blow++;
		if(a[3]==b[2])blow++;
		if(a[3]==b[1])blow++;
		if(a[3]==b[0])blow++;
		if(a[0]==b[2])blow++;
		if(a[1]==b[3])blow++;
		if(a[0]==b[3])blow++;
		printf("%d %d\n",hit,blow);
	}
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;

int main()
{
	while (true){
		int n;
		cin >> n;
		if (!n) break;
		int ans = 0, rem = 0;
		for (int i = 0; i < n; i++){
			int in;
			cin >> in;
			if (in >= 1) ans++;
			if (in >= 2) rem++;
		}
		if (rem) cout << ans + 1 << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    ll ans = s.size(), cnts = 0, cntt = 0;
    bool flag = true;
    for(int i = 0; i < s.size(); i++){
        if(flag){
            if(s[i] == 'S')cnts++;
            else flag = false;
        }
        if(!flag){
            if(s[i] == 'T')cntt++;
            else{
                ans -= 2 * min(cnts, cntt);
                int a = cnts;
                cnts = 1;
                if(cntt <= a)cnts += a-cntt;
                cntt = 0;
                flag = true;
            }
        }
    }
    cout << ans - 2 * min(cnts, cntt) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/
template<typename T=lnt>
struct RangeSum
{
	T v;
	static RangeSum I() { return RangeSum(0); }
	RangeSum(T v) : v(v) {}
	static RangeSum f(const RangeSum& lhs, const RangeSum& rhs) { return lhs+rhs; }
	operator T() const { return v; }
};

template<typename M>
struct SegmentTree
{
	const int n;
	std::vector<M> data;
	SegmentTree(int n) : n(n),data(n<<1,M::I()) {}
	M& operator[](int i) { return data[i+n]; } // pair with update/build
	void update(int i) { for(i+=n;i>1;i>>=1) data[i>>1]=M::f(data[i],data[i^1]); }
	void build() { for(int i=n-1;i>0;i--) data[i]=M::f(data[i<<1],data[i<<1|1]); }
	M fold(int l, int r) const {
		M L=M::I(),R=M::I();
		for(l+=n,r+=n;l<r;l>>=1,r>>=1) {
			if(l&1) L=M::f(data[l++],L);
			if(r&1) R=M::f(R,data[--r]);
		}
		return M::f(L,R);
	}
};


template <typename T>
std::vector<int> sort_indexes(const std::vector<T> &v) {
	std::vector<int> idx(v.size());
	std::iota(idx.begin(), idx.end(), 0);
	std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) {return v[i1] < v[i2];});
	return idx;
}

int main() {
	lnt n,q;
	std::cin >> n >> q;
	std::vector<lnt> c(n);
	rep(i,n) std::cin >> c[i];
	std::vector<std::pair<lnt,lnt> > qu;
	rep(i,q) {
		lnt l,r;
		std::cin >> l >> r;
		qu.emplace_back(l-1,r);
	}
	auto idx = sort_indexes<std::pair<lnt,lnt> >(qu);
	using M=RangeSum<lnt>;
	SegmentTree<M> seg(n+1);
	std::map<lnt,std::vector<lnt> > map;
	rep(i,n) {
		map[c[i]].emplace_back(i);
		if(map[c[i]].size()==1) seg[i]=1;
	}
	seg.build();
	lnt j=0;
	std::vector<lnt> ans(q);
	rep(i,n) {
		while(j<q&&qu[idx[j]].first==i) {
			ans[idx[j]]=seg.fold(i,qu[idx[j]].second);
			j++;
		}
		// c[i] disappears
		auto& v = map[c[i]];
		auto ub = std::upper_bound(all(v),i);
		if(ub!=v.end()) {
			seg[*ub]=1; seg.update(*ub);
		}
	}
	debug("?");
	rep(i,q) print(ans[i]);
}


Measured memory_bytes: 83964
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  cout << (n + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;

const int INF = 1e18;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    int x;
    cin >> x;
    int ans = 0;
    int tmp = 0;
    for (int i = 1; i < 5e4; i++)
    {
        if (x <= tmp)
            break;
        tmp += i;
        ans++;
    }

    cout << ans << endl;
}

signed main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256