akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1000001;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1; finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];

  map<int, int> m;
  for (int x: a) {
    for (int i=2; i<=sqrt(x); i++) {
      int cnt = 0;
      while (x % i == 0) {
        ++cnt;
        x /= i;
      }
      if (m[i] < cnt) {
        m[i] = cnt;
      }
    }
    if (x > 1) {
      m[x] = max(m[x], 1);
    }
  }
  COMinit();
  long long lcm = 1;
  for (auto i: m) {
    int x = i.first;
    int y = i.second;
    for (int i=0; i<y; i++) {
      lcm *= x;
      lcm %= MOD;
    }
  }
  long long ans = 0;
  for (int x: a) {
    ans += lcm * inv[x];
    ans %= MOD;
  }
  cout<<ans<<endl;
}

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

using namespace std;
int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	long long d = c - a - b;
	if (((4 * a*b) < (d*d)) && (d > 0)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
using namespace std;
namespace rng {
    using namespace boost;
    using namespace boost::range;
}
using boost::irange;
constexpr char nl = '\n';

int main() {
    string S;
    cin >> S;
    vector<int> a(S.size() + 1);
    for (auto i : irange(0ul, a.size())) {
        if ((i == 0 || S[i-1] == '>') && (S[i] == '<' || i == a.size() - 1)) {
            for (auto j = i - 1; j >= 0 && S[j] == '>'; j--) {
                a[j] = max(a[j], a[j+1] + 1);
            }
            for (auto j = i + 1; j <= a.size() && S[j-1] == '<'; j++) {
                a[j] = max(a[j], a[j-1] + 1);
            }
        }
    }
    cout << rng::accumulate(a, 0l) << nl;
}


Measured memory_bytes: 2820
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	v := scanNums(n)
	c := scanNums(n)
	m := 0
	for i := 0; i < n; i++ {
		if v[i]-c[i] > 0 {
			m += v[i] - c[i]
		}
	}
	fmt.Println(m)
}


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

int main(){
	string s;
	cin>>s;
	int b=s.length();
	int a[b],c=1;
	for(int i=0;i<b;i++) a[i]=(int)s[i];
	sort(a,a+b);
	for(int i=0;i<b-1&&c;i++){
		if(a[i]==a[i+1]) c--;
	}
	if(c==1) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}



Measured memory_bytes: 256
N = gets.to_i
ts = gets.split.map(&:to_i)
vs = gets.split.map(&:to_i) + [0]

limit = vs.dup
N.times do |i|
    limit[i + 1] = [vs[i], vs[i + 1]].min
end
limit[0] = 0

N.times do |i|
    if limit[i + 1] - limit[i] > ts[i]
        limit[i + 1] = limit[i] + ts[i]
    end
end

N.times do |i|
    if limit[N - 1 - i] - limit[N - i] > ts[N - 1 - i]
        limit[N - 1 - i] = limit[N - i] + ts[N - 1 - i]
    end
end

sum = 0.0
N.times do |i|
    t = ts[i]
    v = vs[i]
    limit0 = limit[i]
    limit1 = limit[i + 1]
    uptime = [t, v - limit0, (t + limit1 - limit0) / 2.0].min
    downtime = [t, v - limit1, (t + limit0 - limit1) / 2.0].min
    keeptime = t - uptime - downtime
    peek = limit0 + uptime
    sum += uptime * (limit0 + peek) / 2.0
    sum += keeptime * peek
    sum += downtime * (peek + limit1) / 2.0
end

print sum

Measured memory_bytes: 1788
use std::io::BufRead;
use std::io::BufReader;

fn main() {
    let mut buf = BufReader::new(std::io::stdin());

    let mut s = String::new();
    buf.read_line(&mut s).unwrap();

    let s = s.trim();
    let ans = if s == "SUN" {
        7
    } else if s == "MON" {
        6
    } else if s == "TUE" {
        5
    } else if s == "WED" {
        4
    } else if s == "THU" {
        3
    } else if s == "FRI" {
        2
    } else {
        1
    };

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


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var KX = Io.ReadList<int>();
            var K = KX[0];
            var X = KX[1];

            var output = 500 * K >= X
                ? "Yes"
                : "No";

            Io.Write(output);
        }

        static int NumberOfDigits(long x)
        {
            if (x < 10) return 1;

            var result = 0;
            while (x > 0)
            {
                result++;
                x /= 10;
            }

            return result;
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }

        class Io
        {
            public static string Read()
            {
                return Console.ReadLine();
            }

            public static IEnumerable<string> ReadRepeat(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read());
            }

            public static T Read<T>()
            {
                return (T)Convert.ChangeType(Read(), typeof(T));
            }

            public static IEnumerable<T> ReadRepeat<T>(int count)
            {
                return Enumerable.Range(0, count).Select(_ => Read<T>());
            }

            public static string[] ReadList(char devide = ' ')
            {
                return Read().Split(devide);
            }

            public static T[] ReadList<T>(char devide = ' ')
            {
                return ReadList(devide)
                    .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                    .ToArray();
            }

            public static IEnumerable<T[]> ReadListRepeat<T>(int count, char devide = ' ')
            {
                return Enumerable.Range(0, count).Select(_ => ReadList<T>(devide));
            }

            public static void Write(string value)
            {
                Console.WriteLine(value);
            }
        }
    }
}


Measured memory_bytes: 13524
import java.util.*;

class Main{
	public static void main(String[] args){
	  Scanner scn = new Scanner(System.in);
      int k = Integer.parseInt(scn.nextLine());
      String s = scn.nextLine();
      if(s.length() < k+1){
        System.out.println(s);
        return;
      }else{
        String ans = s.substring(0,k) + "...";
        System.out.println(ans);
      }
	}
}


Measured memory_bytes: 38640
#include <stdio.h>

int main(void) {

  long n,Lw;
  scanf("%ld %ld", &n, &Lw);
  long w[n],v[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &w[i], &v[i]);
  }
  long dp[n][Lw+1];
  for (long i = 0; i <= Lw; i++) {
    dp[0][i] = 0;
  }
  dp[0][w[0]] = v[0];
  for (long i = 1; i < n; i++) {
    for (long j = 0; j <= Lw; j++) {
      dp[i][j] = dp[i-1][j];
    }
    for (long j = 0; j <= Lw; j++) {
      if (j+w[i] > Lw) {
        break;
      }
      if (dp[i-1][j]+v[i] > dp[i][j+w[i]]) {
        dp[i][j+w[i]] = dp[i-1][j]+v[i];
      }
    }
  }
  long max = -1;
  for (long i = 0; i <= Lw; i++) {
    if (dp[n-1][i] > max) {
      max = dp[n-1][i];
    }
  }
  printf("%ld\n", max);

  return 0;
}

Measured memory_bytes: 78336
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	map<int, int> pp;
	rep(i, n) {
		pp[p[i]]++;
	}
	int sa = 10001;
	int ans = 0;
	bool ok = false;
	for (int i = 0; i < 101; i++) {
		int q = x + i;
		int w = x - i;

		if (pp[q] != 1) {
			ans = q;
			ok = true;
		}
		if (pp[w] != 1) {
			ans = w;
			ok = true;
		}
		if (ok) {
			break;
		}

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

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

    public static void main(String[] args) {
        int n = sc.nextInt();
        int sum = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            if (p > max) {
                max = p;
            }
            sum += p;
        }
        System.out.println(sum - max/2);
    }

}


Measured memory_bytes: 21716
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <cmath>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mp make_pair
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int,int> P;

template<typename T>
void vdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        if(i==size-1){
            cout << da[i] << endl;
        }
        else{
            cout << da[i] << ' ';
        }
    }
}
template<typename T>
void vvdeb(vector<T> &da){
    int size=da.size();
    for(int i=0;i<size;i++){
        vdeb(da[i]);
    }
}


int main(){
    int n, t;
    cin >> n >> t;
    vector<int> a(n),b(n);
    rip(i,n,0){
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> dp(n + 1,vector<int>(t + 1,0)),dpp(n + 1,vector<int>(t+1,0));
    rip(i,n+1,1){
        rip(j,t+1,0){
            dp[i][j] = dp[i-1][j];
            if(j - a[i -1] >= 0){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i - 1]] + b[i - 1]);
                dpp[i][j] = dpp[i - 1][j - a[i - 1]] + b[i - 1];
            }
            dpp[i][j] = max(dpp[i][j],dp[i - 1][j] + b[i - 1]);
            dpp[i][j] = max(dpp[i][j],dpp[i-1][j]);
        }
    }
    int ans = 0;
    rip(i,t ,0){
        ans = max(dpp[n][i],ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 70912
/* Don't try to hack it :|
 
            _/﹋\_
            (҂`_´)
            <,︻╦╤─҉- - - - - - - - - - - - - - -
            _/﹋\_
*/

#include <bits/stdc++.h>
#define ll long long 
#define all(v) v.begin() , v.end()
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define tr(con) for(auto it = con.begin(); it!= con.end() ; it++)
#define INF 1e9+7   
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define fo(i,n) for(ll i=0;i<n;i++)
using namespace std;
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b ,a%b);
}
int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n; cin >> n ;
	string str ,ptr ; cin >> str >> ptr; 
	fo(i,n){
		cout<< str[i]<< ptr[i] ;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int dp[3002][3002];

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int n=s.size();
    int m=t.size();
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i]==t[j]){
                dp[i+1][j+1] = dp[i][j]+1;
            }else{
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    string res = "";
    while(n>0 && m>0){
        if(dp[n][m]==dp[n-1][m]){
            n--;
        }else if(dp[n][m]==dp[n][m-1]){
            m--;
        }else{
            res = s[n-1] + res;
            --n; --m;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 35456
fun main (args : Array<String>) {
	val c = readLine()!!
	val C : String = c.toString()
	val list =
		listOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
			"t", "u", "v", "w", "x", "y", "z")
	for (i in 0..25) {
		if (C == list[i]) {
			return println("${list[i + 1]}")
		}
	}
}

Measured memory_bytes: 34264
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m;
vector<int> v[100010];
vector<int> tp;
int d[100010];
bool visit[100010];
void dfs(int x)
{
	visit[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i];
		if (visit[xi]) continue;
		dfs(xi);
	}
	tp.push_back(x);
}
void tpsort()
{
	for (int i=0;i<n;i++)
	{
		if (visit[i]) continue;
		dfs(i);
	} 
	reverse(tp.begin(),tp.end());
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<m;i++)
	{
		int x,y;
		cin >>x>>y;
		v[x-1].push_back(y-1);
	}
	tpsort();
	d[tp[0]]=0;
	for (int it=0;it<n;it++)
	{
		int x=tp[it];
		for (int i=0;i<v[x].size();i++)
		{
			int xi=v[x][i];
			d[xi]=max(d[xi],d[x]+1);
		}
	} 
	cout <<*max_element(d,d+n);
	return 0;
} 

Measured memory_bytes: 8056
/*
 * Shubham Jain
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 10000000009

int main() {
    FAST_IO
    ll a,b,i,j,ok1=0,ok2=0;
    string s;
    cin>>a>>b;
    cin>>s;
    for(i=0;i<=s.length();i++){
        if(i==a){
            if(s[i]=='-')
                ok1++;
        }
        else{
            if(s[i]=='0'||s[i]=='1'||s[i]=='2'||s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'||s[i]=='7'||s[i]=='8'||s[i]=='9')
                ok2++;
               // cout<<s[i]<<endl;
        }
    }
    //cout<<s.length()<<endl;
    //cout<<ok1<<" "<<ok2<<endl;
    if(ok1==1 && ok2==a+b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='7')
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
 } 

Measured memory_bytes: 3596
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    ll k; cin>>k;
    vector<int> p(n);
    for(int &i : p) cin>>i, --i;
    vector<int> path;
    int v = 0;
    int cnt = 0;
    set<int> vis;
    int start;
    while(true){
        path.push_back(v);
        vis.insert(v);
        cnt++;
        v = p[v];
        start = v;
        if(vis.count(v))
            break;
        
    }
    if(k<cnt){
        cout<<path[k]+1<<endl;
        return 0;
    }

    int off = 0;
    for(int i = 0; i < cnt; i++){
        off = i;
        if(start == path[i])
            break;
    }
    
    k-=off;

    cout<<path[off + k%(cnt-off)]+1<<endl;
    
    return 0;
}

Measured memory_bytes: 13868
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,A,B,C,X;
    cin >> N >> A >> B >> C >> X;
    while(N != 0){
        vector<int> Y(N);
        for(int i=0; i<N; i++){
            cin >> Y[i];
        }
        int cnt = 0;
        for(int i=0; i<N; i++){
            bool ok = false;
            for(int j=0; j<C; j++){
                if(X == Y[i]){
                    ok = true;
                    break;
                }
                cnt++;
                X = (A*X+B)%C;
            }
            if(!ok){
                cnt = -1;
                break;
            }
            if(i == N-1) break;
            X = (A*X+B)%C;
            cnt++;
        }
        if(cnt > 10000){
            cout << -1 << endl;
        }else{
            cout << cnt << endl;
        }
        cin >> N >> A >> B >> C >> X;
    }
    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll H,W,K;
char field[20][1010];
ll cnt[20];

int main(){
    cin >> H >> W >> K;
    rep(i,H) rep(j,W) cin >> field[i][j];
    ll ans = INF;
    rep(i,1<<(H-1)){
        ll res = 0;
        rep(j,H-1) if((i >> j) & 1) res++;
        rep(j,20) cnt[j] = 0;
        rep(j,W){
            rep(k,H){
                if(field[k][j] == '1') cnt[k]++;
            }
            ll now = cnt[0];
            bool flag = 0;
            rep(k,H-1){
                if((i >> k) & 1){
                    if(now > K) flag = 1;
                    now = cnt[k+1];
                }else{
                    now += cnt[k+1];
                }
                
            }
            if(now > K) flag = 1;
            if(flag){
                res++;
                rep(k,H){
                    if(field[k][j] == '1') cnt[k] = 1;
                    else cnt[k] = 0;
                }
                ll now = cnt[0];
                bool flag = 0;
                rep(k,H-1){
                    if((i >> k) & 1){
                        if(now > K) flag = 1;
                        now = cnt[k+1];
                    }else{
                        now += cnt[k+1];
                    }
                }
                if(now > K) flag = 1;
                if(flag) res = INF;
            }
        }
        ans = min(ans,res);
    }
    cout << ans << endl;
}
    


Measured memory_bytes: 256
H,N =map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i],B[i] = map(int,input().split())

INF = 1<<60
dp = [[INF]*(N+1) for _ in range(H+1)]
for i in range(N+1):
    dp[0][i] = 0

tmpj = 0
for j in range(H+1): 
    for i in range(N):
        tmp = dp[j][0]+B[i]
        nxtj = min(H,A[i]+j)
        
        dp[nxtj][0] = min(dp[nxtj][0],tmp)
print(dp[H][0])
        

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  for(int i=0;i<n;i++) cin >> x.at(i);
  
  sort( x.begin(),x.end() );
  
  ll ans = 9999999999999999;
  for(int i=x.at(0);i<=x.at(n-1);i++){
    ll p=0;
    for(int j=0;j<n;j++){
      p += (x.at(j) - i )*(x.at(j) - i );
    }
    ans = min( ans,p );
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
long long n, a[100100], f[100100];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    f[2] = abs(a[1] - a[2]);
    for (int i = 3; i <= n; i++)
        f[i] = min(abs(a[i] - a[i - 1]) + f[i - 1], abs(a[i] - a[i - 2]) + f[i - 2]);
    cout << f[n];
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,L,sum=0,a[210];
  cin>>N>>L;
  for(int i=0;i<N;i++){
    a[i]=L+i;
    sum+=a[i];
   // cout<<a[i]<<endl;
  }
  int low=sum;
  for(int i=0;i<N;i++){
    if(abs(a[i])<abs(low)) low=a[i];
  }
  cout<<sum-low<<endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
using namespace std;
int main(){
	double x[4],y[4];
	while(cin>>x[0]){
		cin>>y[0];
		for(int i=1;i<4;i++)
			cin>>x[i]>>y[i];
		if(x[0]<=x[3]&&y[1]>=y[2]&&x[1]>=x[2]&&y[0]<=y[3])
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nab = scanner.nextLine().split(" ", 3);
        int n = Integer.parseInt(nab[0]);
        int a = Integer.parseInt(nab[1]);
        int b = Integer.parseInt(nab[2]);

        System.out.printf("%d %d\n", Math.min(a, b), Math.max(0, a + b - n));
    }
}


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

using ll = long long;
using namespace std;

int n, m;
int x[(int)1e5];
vector<int> diff;

ll ans;

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i) cin >> x[i];
	
	if(n - m >= 0){
		cout << 0 << endl;
		return 0;
	}
	
	sort(x, x + m);
	
	int t = m - n;
	
	for(int i = 0; i < m - 1; ++i) diff.push_back(x[i+1] - x[i]);
	
	sort(diff.begin(), diff.end());
	
	for(int i = 0; i < t; ++i) ans += diff[i];
	
	cout << ans << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define rep(i,n) for (int i=0; i<(n); ++i)
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

int N;
void dfs(string s, char c){
    if (s.length() == N){
        cout << s <<endl;
    }
    else {
        for(char i='a'; i<=c;i++){
            if(i==c){
                dfs(s+i,(char)(c+1));
            }
            else {
                dfs(s+i,c);
            }
        }
    }
}

int main(){
    
    cin >> N;
    dfs("",'a');

    return 0;
}

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

using namespace std;

using ll = long long;

// O(|V|+|E|)
class Graph{
    public:
    ll size;
    vector<vector<ll> > g;
    vector<bool> visited;
    vector<ll> indeg;

    // sorted by topological sort
    vector<ll> sorted;

    Graph(ll n){
        size = n;
        g = vector<vector<ll> >(size);
        visited = vector<bool>(size);
        indeg = vector<ll>(size);
    }

    void add_edge(ll x, ll y){
        g[x].push_back(y);  // x -> y
        indeg[y]++;
    }

    void bfs(ll s){
        queue<ll> Q; // v, dist
        visited[s] = true;
        Q.push(s);
        while(!Q.empty()){
            ll u = Q.front(); Q.pop();
            sorted.push_back(u);
            for(ll v: g[u]){
                indeg[v]--;
                if(indeg[v] == 0 && !visited[v]){
                    visited[v] = true;
                    Q.push(v);
                }
            }
        }
    }

    // O(|E|log|V|)
    vector<ll> topological_sort(){
        for(ll s=0;s<size;s++){
            if(indeg[s] == 0 && !visited[s]) bfs(s);
        }
        return sorted;
    }
};

// GRL_4_B: verified
int main(){
    ll V, E; cin >> V >> E;
    Graph graph(V); 
    for(ll i=0;i<E;i++){
        ll s, t; cin >> s >> t;
        graph.add_edge(s, t);
    }
    vector<ll> sorted = graph.topological_sort();
    for(ll v: sorted) cout << v << endl;
}



Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

ll dp[1110][5000];

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

    for (int i = 0; i < 1100; i++)
    {
        for (int j = 0; j < 5000; j++)
        {
            dp[i][j] = LINF;
        }
    }
    dp[0][0] = 0;

    for (int i = 0; i < M; i++)
    {
        for (int j = 0; j < (1 << N); j++)
        {
            // i番目の鍵を使わない場合
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);

            // i番目の鍵を使う場合(jの状態から鍵を使った結果)
            int nj = j | c[i];
            dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + a[i]);
        }
    }
    cout << (dp[M][(1 << N) - 1] < INF ? dp[M][(1 << N) - 1] : -1) << endl;
    return 0;
}


Measured memory_bytes: 46632
#include <bits/stdc++.h>
using namespace std;
int main (){
	int n,l[200],ans=0;
	cin>>n;
	for(int a=0;a<n*2;a++){
		cin>>l[a];
		}
	sort(l,l+n*2);
	for(int i=0;i<n*2;i+=2){
		ans=ans+l[i];
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
program main
implicit none
integer :: n, l, i, b
integer , allocatable :: a(:)

read(*,*) n, l
allocate( a(n) )
b= n+l-1
do i = 1, n
   a(i) = l + i -1
   if( abs( a(i) ) .le. abs(b) ) then
      b = a(i)
   end if
end do
write(*,'(i0)') sum(a) -b

end program main


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdio>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iterator>
using namespace std;
const int INF = 0x3f3f3f3f;

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

ll N;

int ans = 0;

int main(){
    scanf("%lld", &N);
    for (int i = 2; i <= (int)sqrt(N); i++){
        int num = 0;
        while (N%i == 0){
            num++;
            N /= i;
        }
        int tmp = 1;
        while (num-tmp >= 0){
            num -= tmp;
            ans++;
            tmp++;
        }
    }
    if (N > 1) ans++;
    printf("%d", ans);
}


Measured memory_bytes: 3808
#include<iostream>
#include<algorithm>
using namespace std;
int a[50];
int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 0; i < n; i++)cin >> a[i], ans += a[i];
	sort(a, a + n);
	for (int i = 0; i < (n - k); i++)ans -= a[i];
	cout << ans << endl;
}

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

void maerge(int *,int,int,int,int);
void mergeSort(int *,int,int);

int result=0;

int main(){
  int n,*A;
  int i;
  
  scanf("%d",&n);
  A=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);

	 
  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",result);

  free(A);
  
  return 0;
}

void merge(int *A,int l,int m,int r){
  int n1,n2;
  int *L,*R;
  int i,j,k;
  n1=m-l;
  n2=r-m;
  L=(int *)malloc((n1+1)*sizeof(int));
  for(i=0;i<n1;i++) L[i]=A[l+i];
  R=(int *)malloc((n2+1)*sizeof(int));
  for(i=0;i<n2;i++) R[i]=A[m+i];
  L[n1]=1000000001;
  R[n2]=1000000001;
  i=0;
  j=0;
  for(k=l;k<r;k++){
    if(L[i]<=R[j])  A[k]=L[i++];
    else A[k]=R[j++];
    result++;
  }

  
  free(L);
  free(R);
}

void mergeSort(int *A,int l,int r){
  int m;
  if(l+1<r){
    m=(l+r)/2;
    mergeSort(A,l,m);
    mergeSort(A,m,r);
    merge(A,l,m,r);
  }    
}



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

int main(){
  int h,w;
  char c;
  int mp[1410][1410]={0};
  int ans=0;

  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      scanf(" %c",&c);
      if(c=='1')mp[i][j]=0;
      if(c=='0')mp[i][j]=mp[i-1][j]+1;
    }
  }

  int mx;
  int target;
  stack<pair<int,int> >st;
  for(int i=1;i<=h;i++){
    mx=0;
    
    for(int j=1;j<=w;j++){

      if(mx<mp[i][j]){
	st.push(make_pair(mp[i][j],j));
	mx=mp[i][j];
      }

      else if(mx>mp[i][j]){
	target = j;
	while(!st.empty()){
	  pair<int,int>f=st.top();
	  if(f.first<mp[i][j])break; // ...?
	  st.pop();
	  // Debug
	  /*
	  cout<<i<<" "<<j<<" "<<f.first<<" "<<f.second<<endl;
	  cout<<f.first*(j-f.second)<<endl;
	  */
	  ans = max(ans,(f.first*(j-f.second)));
	  target = f.second;
	}
	if(mp[i][j]>0)st.push(make_pair(mp[i][j],target));
	mx=mp[i][j];
      }

    }
    
    while(!st.empty()){
      pair<int,int>f=st.top();st.pop();
      // Debug
      //cout<<i<<"  "<<f.second<<endl;
      ans = max(ans,(f.first*(w+1-f.second)));
      //  cout<<ans<<endl;
    }
  }

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

Measured memory_bytes: 10940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mx 100005
#define inf 100000000000000000LL
ll arr[mx], dp[mx];
int main()
{
    int n,k;
    while(scanf("%d%d",&n, &k)){
        for(int i=1; i<=n; i++)
            scanf("%lld",&arr[i]);
        dp[n] = 0;
        for(int i = n-1; i>=1; i--){
            dp[i] = inf;
            for(int j=1; j<=k; j++){
                int nxt = i+j;
                if(nxt>n) break;
                dp[i] = min(dp[i], llabs(arr[i] - arr[nxt]) + dp[nxt]);
            }
        }
        printf("%lld\n", dp[1]);
        return 0;
    }
}



Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveC();
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		sc.nextLine();
		int[][] dist_map = new int[H][];
		int start_r = -1;
		int start_c = -1;
		for (int r = 0; r < H; r++) {
			dist_map[r] = new int[W];
			String line = sc.nextLine();
			for (int c = 0; c < W; c++) {
				char panel = line.charAt(c);
				if (panel == 'S') {
					start_r = r;
					start_c = c;
					dist_map[r][c] = 1;
				} else if (panel == '#') {
					dist_map[r][c] = -1;
				} else {
					dist_map[r][c] = H * W * 2;
				}
			}
		}
		if (search(start_r, start_c, 0, dist_map, H, W, K) == 0) {
			System.out.println(1);
			return;
		}
		int min_dist = H + W;
		for (int r = 0; r < H; r++) {
			for (int c = 0; c < W; c++) {
				if (dist_map[r][c] <= K && dist_map[r][c] >= 0) {
					if (min_dist > r) {
						min_dist = r;
					}
					if (min_dist > c) {
						min_dist = c;
					}
					if (min_dist > H - 1 - r) {
						min_dist = H - 1 - r;
					}
					if (min_dist > W - 1 - c) {
						min_dist = W - 1 - c;
					}
				}
			}
		}
		System.out.println((min_dist - 1) / K + 2);
	}

	private int search(int r, int c, int dist, int[][] map, int limit_r, int limit_c, int K) {
		if (dist > K) {
			return -1;
		}
		if (r < 0 || c < 0 || r >= limit_r || c >= limit_c) {
			return 0;
		}
		if (dist < map[r][c]) {
			map[r][c] = dist;
			if (search(r - 1, c, dist + 1, map, limit_r, limit_c, K) == 0) {
				return 0;
			}
			if (search(r, c - 1, dist + 1, map, limit_r, limit_c, K) == 0) {
				return 0;
			}
			if (search(r + 1, c, dist + 1, map, limit_r, limit_c, K) == 0) {
				return 0;
			}
			if (search(r, c + 1, dist + 1, map, limit_r, limit_c, K) == 0) {
				return 0;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 33176
#include <iostream>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int a = 0, b = 0;
  for (int i = 1; i <= n; ++i) {
    int r = i % m;
    if (r == 0) {
      ++a;
    } else
    if (2 * r == m) {
      ++b;
    }
  }
  cout << (long long)a * a * a + (long long)b * b * b << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n){
        cin>>a[i];
    }
    a.erase(unique(all(a)),a.end());
    int x=a.size(),cnt=0;
    if(x==1||x==2){cout<<1<<endl;return 0;}
    vi b(x-1);
    rep(i,x-1){
        b[i]=a[i+1]-a[i];
    }
    rep(i,x-1){
        if(b[i]>0&&b[i+1]<0){cnt++;b[i+1]=0;}
        if(b[i]<0&&b[i+1]>0){cnt++;b[i+1]=0;}
    }
    cout<<cnt+1<<endl;
}


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


def prepare(A):
  B=[10000,A[0]]
  for i in range(1,len(A)):
    if B[-2]<B[-1] and B[-1]<=A[i]:
      B[-1]=A[i]
    elif B[-2]>B[-1] and B[-1]>=A[i]:
      B[-1]=A[i]
    else:
      B.append(A[i])
  return B

A=prepare(A)
money=1000
kabu=0
A.pop(0)

def buy(money,kabuka):
  kabu=money//kabuka
  money=kabu*kabuka
  return money,kabu

def sell(money,kabuka,kabu):
  money+=kabuka*kabu
  return money

while True:
  if len(A)==1:
    money=sell(money,A[0],kabu)
    break
  elif A[0]<A[1]:
    diffmoney,diffkabu=buy(money,A[0])
    money-=diffmoney
    kabu+=diffkabu
  elif A[0]>A[1]:
    money=sell(money,A[0],kabu)
    kabu=0
  A.pop(0)
print(money)

Measured memory_bytes: 9248
N, K = [ int(i) for i in input().strip().split(' ') ]
A = [ int(i) for i in input().strip().split(' ') ]

current = 1
N_counter = [0] * N 
N_counter_idx = [0] * N 
N_counter[current-1] += 1
N_counter_idx[current-1] = 1

k_reserved = -1
for i in range(1, N+1):
    current = A[current-1]
    N_counter[current-1] += 1
    if i == K:
        k_reserved = current
    if N_counter[current-1] == 2:
        break
    N_counter_idx[current-1] = i+1

if K < i:
    print(k_reserved)
else:
    #print(N_counter)
    #print(N_counter_idx)
    pre_loop_length = N_counter_idx[current-1] - 1
    loop_length = max(N_counter_idx) - pre_loop_length
    #print(pre_loop_length)
    #print(loop_length)
    K_new = (K - pre_loop_length) % loop_length + pre_loop_length
    
    # K_new = K - (K // i) * i 
    current = 1
    for k in range(K_new):
        current = A[current-1]
    print(current)

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

int main() {
	
	int n;
	cin>>n;
	int t[7]={0,100,101,102,103,104,105};
	bool a[7][n+1];
	memset(a,false,sizeof(a));
	for(int i=0;i<=5;i++)
		a[i][0]=true;
	for(int i=1;i<=6;i++){
		for(int j=1;j<=n;j++){
			a[i][j]=a[i-1][j];
			if(j-t[i]>=0){
				a[i][j]=a[i][j]||a[i-1][j-t[i]];
				a[i][j]=a[i][j]||a[i][j-t[i]];
			}
				
		}
	}
	cout<<a[6][n]<<endl;
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int main(){
   int a,n,x;
   int sum = 0;
   scanf("%d %d", &a,&n);
   for(int i = 0; i < n; i++){
      scanf("%d", &x);
      sum += x;
   }
   if(a <= sum){
      printf("Yes\n");
   }else{
      printf("No\n");
   }
   return 0;
}



Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,i,head,tail;
double l,t[500005],v[500005],tt,vv,z,now;
int main(){
	//freopen("camp.in","r",stdin);
	//freopen("camp.out","w",stdout);
	n=read();l=read();
	head=1;tail=1;
	t[1]=read();v[1]=read();
	now=t[1]*v[1];
	printf("%.7lf\n",t[1]);
	for(i=2;i<=n;i++){
		tt=read();vv=read();
		z=vv;
		now+=tt*vv;
		while(z>eps){
			if(v[head]<z){
				z-=v[head];
				now-=v[head]*t[head];
				head++;
			}
			else{
				now-=z*t[head];
				v[head]-=z;
				z=0.0;
			}
		}
		while(t[tail]>tt&&tail>=head){
			tt=(tt*vv+t[tail]*v[tail])/(v[tail]+vv);
			vv=v[tail]+vv;
			tail--;
		}
		tail++;
		v[tail]=vv;
		t[tail]=tt;
		printf("%.7lf\n",now/l);
	}
	return 0;
}

Measured memory_bytes: 16896
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);

	int x, y;
	y = 0;

	for (x = a; x <= b; x++)
	{
		if (c % x==0)
		{
			y = y + 1;
		}
	}

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

	return 0;
}


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

#define ll long long


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
  	if ((a+b) %2 == 1){ cout << "IMPOSSIBLE"; }
  	else { cout << (a+b)/2 << endl; }
}


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

#define RIDGE 4
#define FLOOR 3
#define ROOM 10

int main(int argc, char const *argv[])
{
    int n;
    int a[RIDGE][FLOOR][ROOM] = {0};
    int b, f, r, v;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        a[b - 1][f - 1][r - 1] += v;
    }

    for (int i = 0; i < RIDGE; i++)
    {
        for (int j = 0; j < FLOOR; j++)
        {
            for (int k = 0; k < ROOM; k++)
            {
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }
        if (i < RIDGE - 1)
            cout << "####################" << endl;
    }

    return 0;
}



Measured memory_bytes: 3096
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int sum = 0;

		for(int i=0; i<N; i++){
			a[i] = sc.nextInt();
			sum += a[i]-1;
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 25576
#include<stdio.h>

int main(void){
  int p,s1,s2,s3,x;
  scanf("%d",&p);
  s1=p/100;
  s2=p/10-p/100*10;
  s3=p%10;
  x=0;
  if(s1==1){
    x=x+1;
  }
  if(s2==1){
    x=x+1;
  }  
  if(s3==1){
    x=x+1;
  }
  printf("%d",x);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n; cin >> n;
	vector<tuple<ll,ll,ll>> p(n);
	REP(i, n) {
		ll a, b;
		cin >> a >> b;
		p[i] = tuple<ll, ll, ll>{ a + b, a, b };
	}
	sort(ALL(p));
	reverse(ALL(p));

	ll ans = 0;
	REP(i, n) {
		if (i % 2 == 0) {
			ans += get<1>(p[i]);
		} else {
			ans -= get<2>(p[i]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
k, n = map(int, input().split())
lst = list(map(int, input().split()))
min_num = k
for i in range(len(lst)):
    if i == 0:
        tmp = min(lst[0] + (k - lst[1]), lst[-1] - lst[0])
    elif i == n - 1:
        tmp = min(lst[-1] - lst[0], (k - lst[-1]) + lst[n - 2])
    else:
        tmp = min(lst[i] + (k - lst[i + 1]), (k - lst[i]) + lst[i - 1])
    if tmp < min_num:
        min_num = tmp

print(min_num)

Measured memory_bytes: 26444
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int makeSum(int x){
  int res = 0;
  while(x != 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}
int main(){
  int N,A,B,ans=0;
  cin >> N >> A >> B;
  for(int i = 1; i <= N; i++){
    int sum = makeSum(i);
    if(A <= sum && sum <= B)ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int n; vector<int>a, b;
int solve(vector<int> p, vector<int> q, int L, int R) {
	if (q.size() == 0)return 0;
	int M1 = L - 1, M2 = R + 1;
	int S[4] = { 0,0,0,0 };
	vector<int>p1; bool flag = false;
	for (int i = 0; i < p.size(); i++) {
		if (M1 != p[i])p1.push_back(p[i]);
	}
	if (p1.size() != p.size()) { flag = true; S[solve(q, p1, L - 1, R)] = 1; }
	p1.clear();
	for (int i = 0; i < p.size(); i++) {
		if (M2 != p[i])p1.push_back(p[i]);
	}
	if (p1.size() != p.size()) { flag = true; S[solve(q, p1, L, R + 1)] = 1; }
	if (flag == false) { S[solve(q, p, L, R)] = 1; }
	for (int i = 0; i < 4; i++) {
		if (S[i] == 0)return i;
	}
	return 4;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		a.clear(); b.clear();
		for (int j = 0; j < 6; j++) { int c; cin >> c; a.push_back(c); }
		for (int j = 1; j <= 13; j++) {
			bool flag = true; if (j == 7)flag = false;
			for (int k = 0; k < 6; k++) { if (a[k] == j)flag = false; }
			if (flag == true)b.push_back(j);
		}
		int E = solve(a, b, 7, 7);
		if (E == 0)cout << "no" << endl;
		else cout << "yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数
 //double 少数（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  int a,b;
  cin>>a>>b;
  if((a+b)%2==0)
    cout<<(a+b)/2;
  else
    cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l;
    cin >> n >> l;
    int a[n];
    for(int i = 0;i < n;i++) {
        a[i] = l+i;
    }
    int min = abs(a[0]);
    int store = a[0];
    for(int i = 0;i < n;i++) {
        int abs_num = abs(a[i]);
        if(min>abs_num) {
            min = abs(a[i]);
            store = a[i];
        }
    }

    int sum = 0;
    for(int i = 0;i < n;i++) {
        if(store!=a[i]) {
            sum+=a[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
from math import atan, degrees
a, b, x = map(int, input().split())

if a * a * b / 2 >= x:
    ans = 90 - degrees(atan((2 * x) / (a * b * b)))
else:
    ans = degrees(atan((2 * ((a**2 * b) - x))/(a ** 3)))
print(ans)

Measured memory_bytes: 3188
import sys

N, M = map(int, sys.stdin.readline().rstrip().split())
A = list(map(int, sys.stdin.readline().rstrip().split()))

sumA = sum(A)
candidates = sorted(A, reverse=True)[:M]
if candidates[-1] < sumA / (4. * M):
    print('No')
else:
    print('Yes')


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

// 2整数の最大公約数を求める関数
ll gcd(ll x, ll y) {
  if (y == 0)
    return (x);
  else
    return (gcd(y, x % y));
}

ll lcm(ll x, ll y) {
  return x * y / gcd(x, y);
}

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

  ll n,m;
  string s,t;
  cin>>n>>m>>s>>t;
  
  ll l = lcm(n,m);
  ll g = gcd(n,m);
  for(ll j = 0; j < g; j++)
  {
    if(s[j * (n / g)] != t[j * (m / g)]) {
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<l<<endl;
  
  return 0;
}


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

int N;
vector<long long> t(100);

long long gcd(long long x,long long y){
  long long c=max(x,y),d=min(x,y);
  if(d==0)return c;
  return gcd(d,c%d);
}

long long b(long long p,long long q){
  return p/gcd(p,q)*q;
}

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> t[i];
  }
  long long current = t[0];
  for(int i=1;i<N;i++){
    current = b(current,t[i]);
  }
  cout << current <<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
// #define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset( a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

inline bool checkBit(ll n, int i) { return n & (1LL << i); }
inline ll setBit(ll n, int i) { return n | (1LL << i); }
inline ll resetBit(ll n, int i) { return n & (~(1LL << i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }



int main() {
    optimize();
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; ++i) cin >> p[i];
    int minSoFar = inf;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (minSoFar >= p[i]) {
            cnt++;
            minSoFar = p[i];
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1024