akhauriyash/Code-Regression huggingface dataset:
while True:
   a,b,c=input().split()
   a=int(a)
   c=int(c)
   if b == "?":
      break
   if b == "+":
      print(a+c)
   if b == "-":
      print(a-c)
   if b == "*":
      print(a*c)
   if b == "/":
     print(a//c)


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

int main() {
  int n,x,ans = 1,d = 0;
  cin >> n >> x;
  vector<int>data(n);
  for(int i = 0;i < n;i++){
    cin >> data.at(i);
  }
  for(int i = 0;i < n;i++){
    d += data.at(i);
    if(d > x){
      break;
    }
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n, q) = get!(usize, usize);
    let stx = get!(isize, isize, isize; n);
    let d = get!(isize;q);

    let mut event = Vec::with_capacity(2*n);
    let mut xset = BTreeSet::new();

    for (s,t,x) in stx {
        event.push((s-x,true,x));
        event.push((t-x,false,x));
    }

    let mut res = vec![None;q];
    let mut i = 0;
    event.sort_by_key(|e| e.0);
    for (t, kind, x) in event {
        if d[i] < t {
            while i < q && d[i] < t {
                res[i] = xset.iter().next().cloned();
                i += 1;
            }
            if i >= q {
                break;
            }
        }
        if kind {
            xset.insert(x);
        } else {
            xset.remove(&x);
        }
    }
    for i in 0..q {
        if let Some(val) = res[i] {
            println!("{}", val);
        } else {
            println!("-1");
        }
    }
}


Measured memory_bytes: 29008
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
#define _USE_MATH_DEFINES
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}

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

  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  int p[a], q[b], r[c];
  
  for (int i = 0; i < a; i++)
    cin >> p[i];
  for (int i = 0; i < b; i++)
    cin >> q[i];
  for (int i = 0; i < c; i++)
    cin >> r[i];

  sort(p, p + a, greater<>());
  sort(q, q + b, greater<>());
  sort(r, r + c, greater<>());
  int pp = x - 1;
  int qq = y - 1;
  int rr = 0;
  int min_ = min(p[pp], q[qq]);
  int best = r[rr];

  int ans = 0;
  for (int i = 0 ; i < x; i++)
    ans += p[i];
  for (int j = 0; j < y; j++)
    ans += q[j];
  
  while(best > min_){
    ans += best - min_;
    if (p[pp] == min_)
      pp--;
    else
      qq--;
    rr++;
    min_ = min(pp >=0 ? p[pp] : LINF, qq >= 0 ? q[qq] : LINF);
    best = rr < c ? r[rr] : 0;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 5964
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1005;
#define M 1000000007
#define double long double
#define BINF 1000000000001
#define init(a,val) memset(a,val,sizeof(a))
const int LG = 22;


 
#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0); 
 
    


    string s,r;
    cin >> s >> r;
    int ans = 0;
    for(int i = 0; i < 3; i++)
        if(s[i]  == r[i]) ans++;
    cout << ans;



 
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Node
{
    int x,y,z;
};
int cmp(Node a,Node b)
{
    if(a.x!=b.x)
        return a.x>b.x;
    else if(a.y!=b.y)
        return a.y>b.y;
    else
        return a.z>b.z;
}
int main()
{
    Node a,b;
    b.x=2019,b.y=4,b.z=30;
    scanf("%d/%d/%d",&a.x,&a.y,&a.z);
    if(cmp(a,b)>0)
        printf("TBD\n");
    else
        printf("Heisei\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public int josephus(int n,int m,int k){
		return ((k<=1)?(m-1):(josephus(n-1,m,k-1)+m))%n;
	}

	public void run() {
		while(true){
			int n=sc.nextInt();
			int m=sc.nextInt();
			if(n==0 && m==0)break;
			ln(josephus(n,m,n)+1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int H,W;
	while(cin>>H>>W,H){
		vector<string> vstr(H);
		vector<bool> memo(H*W,false);
		for(int i=0;i<H;i++){
			string str;
			cin>>str;
			vstr[i]=str;
		}
		int x=0,y=0;
		bool flag=false;
		while(!flag){
			memo[x+y*W]=true;
			switch(vstr[y][x]){
			case '>':
				x++;
				break;
			case '<':
				x--;
				break;
			case '^':
				y--;
				break;
			case 'v':
				y++;
				break;
			case '.':
				flag=true;
				break;
			}
			if(!flag){
				if(memo[y*W+x]){
					break;
				}
			}
		}
		if(flag){
			cout<<x<<" "<<y<<endl;
		}
		else{
			cout<<"LOOP"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c)ou("Yes");
  else ou("No");
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll A[N];
    ll B[N];
    rep(i, N - 1){
        cin >> B[i];
    }
    B[N - 1] = 100001;

    ll ans = 0;
    rep(i, N){
        if(i == 0){
            A[i] = B[i];
        }else{
            A[i] = min(B[i - 1], B[i]);
        }
        ans += A[i];
    }

    cout << ans << endl;

    return 0;
}

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



signed main() {
  int N, M, K; cin >> N >> M >> K;
  const int mod = 998244353;
  M %= mod;
  vector<int> com(K+1, 1);
  rep(i, K) {
    com[i+1] = (com[i]*(N-1-i))%mod;
    int x = i+1;
    rep(j, 30) {
      if(j > 0) x *= x;
      x %= mod;
      if(j != 26 && j != 23) {
        com[i+1] *= x;
        com[i+1] %= mod;
      }
    }
  }
  //cout << com[0] << endl << com[1] << endl << com[2] << endl;

  vector<int> paint(N+1, M);
  rep(i, N-1) paint[i+2] = (paint[i+1]*(M-1))%mod;
  
 
  int ans = 0;
  rep(i, K+1) {
    ans += com[i]*paint[N-i];
    ans %= mod;
  }

  cout << ans << endl;
}

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

using namespace std;

long long dp[10001][2][101];
const int mod = 1e9 + 7;

int main() {
    int m;
    string s;
    cin >> s >> m;

    int n = s.size(); 
    dp[n][1][0] = dp[n][0][0] = 1;
    for (int pos = n - 1; pos >= 0; pos--) 
        for (int flag = 0; flag < 2; ++flag) 
            for (int sum = 0; sum <= 100; ++sum) {
                int lim = flag ? s[pos] - '0' : 9;
                for (int i = 0; i <= lim; ++i) {
                    dp[pos][flag][sum] += dp[pos + 1][i == lim and flag][(sum + i) % m];
                    dp[pos][flag][sum] %= mod;
                }
            }

    cout << (dp[0][1][0] + mod - 1) % mod << "\n";

    return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A) cin >> x;
	int m = 0;
	ll r = 0;
	for (auto x : A) {
		m = max(m, x);
		r += m - x;
	}
	cout << r << endl;
}


Measured memory_bytes: 3944
/*
author: shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,sum=0;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    sort(arr,arr+n);
    sum-=arr[n-1];
    if(arr[n-1]<sum)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

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

using namespace std;

int m,coef[10];
bool zero[10];

int dfs(int idx,int sum,int used){
	if(idx==m)	return sum==0;

	int pr_max=0,pr_min=0;
	for(int i=idx;i<m;i++){
		if(coef[i]>0)	pr_max+=coef[i]*9;
		if(coef[i]<0)	pr_min+=coef[i]*9;
	}
	if(sum>0 && sum+pr_min>0)	return 0;
	if(sum<0 && sum+pr_max<0)	return 0;

	int cnt=0;
	rep(i,10){
		if(used&(1<<i) || (i==0 && !zero[idx]))	continue;
		cnt+=dfs(idx+1,sum+coef[idx]*i,used|(1<<i));
	}
	return cnt;
}

int main(){
	for(int n;cin>>n,n;){
		int f[128],idx=0;
		fill(f,f+128,-1);
		fill(coef,coef+10,0);
		fill(zero,zero+10,true);
		rep(i,n){
			string num;	cin>>num;
			int sign=(i<n-1?1:-1);
			for(int j=num.length()-1,d=1;j>=0;j--,d*=10){
				if(f[num[j]]==-1)	f[num[j]]=idx++;
				coef[f[num[j]]]+=sign*d;
			}
			if(num.length()>1)	zero[f[num[0]]]=false;
		}
		m=idx;
		cout<<dfs(0,0,0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 928
#include <iostream>
#include <string>

using namespace std;

int main(){
	string input;
	cin >> input;
	if (input.length() < 6){
		cout << "INVALID" << endl;
		return 0;
	}
	int flag = 0;
	for (int i = 0; i < input.length(); i++){
		if (input[i] >= '0'&&input[i] <= '9'){
			flag = 1;
			break;
		}
	}
	if (!flag){
		cout << "INVALID" << endl;
		return 0;
	}
	flag = 0;
	for (int i = 0; i < input.length(); i++){
		if (input[i] >= 'A'&&input[i] <= 'Z'){
			flag = 1;
			break;
		}
	}
	if (!flag){
		cout << "INVALID" << endl;
		return 0;
	}
	flag = 0;
	for (int i = 0; i < input.length(); i++){
		if (input[i] >= 'a'&&input[i] <= 'z'){
			flag = 1;
			break;
		}
	}
	if (!flag){
		cout << "INVALID" << endl;
		return 0;
	}
	cout << "VALID" << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	vector<int> v;
	v.push_back(abs(a-b));
	v.push_back(abs(b-c));
	v.push_back(abs(c-a));
	sort(v.begin(), v.end());
	v.pop_back();
	cout << v.at(0) + v.at(1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define res register int
#define mod 1000000007
#define N 8005
#define M 200005
#define ll long long
using namespace std;
int n,a[M],b[M],jie[N],inv[N];
int f[N][N];
inline int read()
{
  int X=0,w=0;
  char ch=0;
  while(!isdigit(ch))
  {
    w|=ch=='-';
    ch=getchar();
  }
  while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  return w?-X:X;
}
inline int &F(res x,res y)
{
  return f[x+2001][y+2001];
}
inline void init()
{
  jie[0]=1;
  for(res i=1; i<=8000; i++)
    jie[i]=1LL*jie[i-1]*i%mod;
  inv[1]=1;
  for(res i=2; i<=8000; i++)
    inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
  inv[0]=1;
  for(res i=1; i<=8000; i++)
    inv[i]=1LL*inv[i]*inv[i-1]%mod;
}
inline int C(int x,int y)
{
  return 1LL*jie[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
  n=read();
  init();
  for(res i=1; i<=n; i++) F(-(a[i]=read()),-(b[i]=read()))++;
  for(res i=-2000; i<=2000; i++)
    for(res j=-2000; j<=2000; j++)
      F(i,j)=((ll)F(i,j)+F(i-1,j)+F(i,j-1))%mod;
  int ans=0;
  for(res i=1; i<=n; i++) ans=((ll)ans+F(a[i],b[i])-C(a[i]+a[i]+b[i]+b[i],b[i]+b[i]))%mod;
  ans=1LL*ans*inv[2]%mod;
  printf("%d\n",(ans+mod)%mod);
  return 0;
}

Measured memory_bytes: 128512
<?php
  list($n, $m) = explode(" ", trim(fgets(STDIN)));

  if($n == 1 || $m == 1){
    if($n == 1 && $m == 1){
      echo 1;
    }else{
      echo $n*$m-2;
    }
  }
  else {
    echo ($n-2)*($m-2);
  }
  

Measured memory_bytes: 16228
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <math.h>

int main()
{
    int a,b,coin;
    coin=0;
    std::cin >> a >>b;
    if(a-b >0){
        coin += a;
        a -=1;
    }
    else{
        coin +=b;
        b-=1;
    }
    if(a-b>0){
        coin +=a;
        a-=1;
    }else{
        coin +=b;
    }
    std::cout << coin << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2147483647
#define  ll long long
using namespace std;
const int Max=1e5+20;
const int Maxn=1e7+20;
const int mod=1e9+7;
inline int read()
{
    int f=1,x=0;
    char ch;
    do{ch=getchar(); if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return x*f;
}
int a[120];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        a[i]=read();
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=0;i<=n;i++)
        for(int j=i+1;j<=n;j++)
          for(int k=j+1;k<=n;k++)
    {
        if(a[i]+a[j]>a[k]&&a[k]-a[j]<a[i]&&a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]) ans++;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3616
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 1e3 + 10;
char s[maxn];
int n;

int read() {
  if (scanf("%s", s) < 1) {
    return 0;
  }
  return 1;
}

void solve() {
  n = (int) strlen(s);
  if (!!count(s, s + n, 'N') != !!count(s, s + n, 'S')) {
    printf("No\n");
    return;
  }
  if (!!count(s, s + n, 'W') != !!count(s, s + n, 'E')) {
    printf("No\n");
    return;
  }
  printf("Yes\n");
}

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

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[] charS = S.toCharArray();
    int N = charS.length;
    boolean isStrong = true;
    for(int i=0; i<N; i++){
      if(charS[i] != charS[N-1-i]){
        isStrong=false;
        break;
      }
    }
    for(int i=0; i<(N-1)/2; i++){
      if(charS[i] != charS[(N-1)/2-1-i]){
        isStrong=false;
      }
    }
    for(int i=(N+3)/2-1; i<N; i++){
      if(charS[i] != charS[N-1-i]){
        isStrong=false;
      }
    }
    

    if(isStrong){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define F first
#define S second
#define REP(i, a, b, c) for(int i = a; i <= b; i+=c)
#define pb push_back
#define int long long int
#define MOD 1000000007
using namespace std;

int a[105];

int solve(int n, int k) {
  int dp[n + 5][k + 5];
  for (int j = 0; j <= k; j++)
  {
    dp[1][j] = (j > a[1]) ? 0 : 1;
  }
  for (int i = 2; i <= n; i++)
  {
    for (int j = 0; j <= k; j++)
    {
      if (j == 0)
        dp[i][j] = dp[i - 1][j];
      else
        dp[i][j] = (MOD + dp[i][j - 1] + dp[i - 1][j] - ((j - a[i] - 1 >= 0) ? dp[i - 1][j - a[i] - 1] : 0)) % MOD;

    }
  }
  return dp[n][k];
}

int32_t main()
{
  ios :: sync_with_stdio(false); cin.tie(0);
  int t = 1;
  //cin >> t;
  for (int i9 = 1; i9 <= t; i9++)
  {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
      cin >> a[i];
    cout << solve(n, k);
  }
}



Measured memory_bytes: 81724
n, m = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
if m <= n:
    print(0)
    exit()

x = sorted(x)
diffs = []
for i in range(m - 1):
    diffs.append(x[i + 1] - x[i] - 1)
diffs = sorted(diffs, reverse=True)
print(x[-1] - x[0] + 1 - sum(diffs[: n - 1]) - n)


Measured memory_bytes: 13840
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k,l,n,m;
    cin>>n;
    int a[n][3];
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    int dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1;i<n;i++)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

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

int main()
{
	int count[26] = {};

	char ch;
	
	while (cin >> ch)
	{
		if ('a' <= ch && ch <= 'z')
		{
			int num = ch - 'a';
			count[num]++;
		}
		else if ('A' <= ch && ch <= 'z')
		{
			int num = ch - 'A';
			count[num]++;
		}
	}

	ch = 'a';

	for (int i = 0; i < 26; i++){
		cout << (char)(ch + i) << " : " << count[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
package main

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

func main() {
	N := readInt()

	if N == 2 {
		// K = 2
		fmt.Println(1)
		return
	}

	result := 2 // K = N - 1, N
	for K := 2; K <= int(math.Sqrt(float64(N))); K++ {
		t := N
		for t >= K && t%K == 0 {
			t /= K
		}
		if t%K == 1 {
			result++
		}

		if (N-1)%K == 0 && (N-1)/K > K {
			result++
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = readInt()
	}
	return result
}


Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<string.h>
using namespace std;

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

const int maxn = 100005;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
map<pair<int,int> ,int> mm;

#define Se second
#define Fi first

int n,m;
int  l,r,d;
int book[maxn];
int num[maxn];
int flag;

vector<int> v[maxn];

void dfs(int x)
{
    if(flag==1)
        return ;
    for(int i=0;i<v[x].size();i++)
    {
        int pos=v[x][i];
         if(book[pos]==0)
         {
             book[pos]=1;
             num[pos]=num[x]+mm[pair<int,int>(x,pos)];
             dfs(pos);
         }
         else
         {
             if(num[pos]!=num[x]+mm[pair<int,int>(x,pos)])
             {
                 flag=1;
                 return ;
             }
         }
    }
    return ;
}
int main()
{
    cin>>n>>m;
    flag=0;
    while(m--)
    {
        cin>>l>>r>>d;
        v[l].push_back(r);
        v[r].push_back(l);
        mm[pair<int,int>(l,r)]=d;
        mm[pair<int,int>(r,l)]=-d;
    }
    for(int i=1;i<=n;i++)
    {
        if(flag==1)
            break;
        if(book[i]==0)
        {
            book[i]=1;
            num[i]=0;
            dfs(i);
        }
    }
    if(flag==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 40064
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int max = Math.max(a,Math.max(b,c));
      if(max == a+b+c-max)System.out.println("Yes");
      else System.out.println("No");
    }
}

Measured memory_bytes: 23380
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int q = sc.nextInt();
    int[] a = new int[n];
    Arrays.fill(a, k - q);

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

    for (int i = 0; i < n; i++) {
      if (a[i] > 0) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }

  }
}

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

const int maxn = 2e5 + 10;

ll n,k,cnt0,cnt1,cnt2;
vector<int>v1,v2,v;

bool check(ll x)
{
	ll cnt = 0;
	if(x < 0) {
		for(int i = 0; i < cnt2; i++) {
			ll y = (-x) / v2[i];
			cnt += v1.end() - upper_bound(v1.begin(),v1.end(),y);
		}
	}
	else if(x == 0){
		cnt += cnt1 * cnt2;
	}
	else {
		cnt += cnt1 * cnt2;
		cnt += cnt0 * (cnt1 + cnt2);
		cnt += cnt0 * (cnt0 - 1) / 2;
		ll tmp = 0;
		for(int i = 0; i < cnt1; i++) {
			ll y = (x + v1[i] - 1) / v1[i];
			tmp += lower_bound(v.begin(),v.end(),y) - v.begin();
			v.push_back(v1[i]); 
		}
		v.clear();
		for(int i = 0; i < cnt2; i++) {
			ll y = (x + v2[i] - 1) / v2[i];
			tmp += lower_bound(v.begin(),v.end(),y) - v.begin(); 
			v.push_back(v2[i]);
		}
		v.clear();
		cnt += tmp;
	}
	return cnt < k;

}

int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		int x; cin >> x;
		if(x > 0) v1.push_back(x);
		else if(x < 0) v2.push_back(-x);
		else cnt0++;
	} 
	cnt1 = v1.size(), cnt2 = v2.size();
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	ll l = -1e18 - 1, r = 1e18 + 1;
	while(r - l > 1){
		ll mid = (l + r) / 2;
		if(check(mid)) l = mid;
		else r = mid;
		//cout << l << " " << r << endl;
	}		
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c,r=0;
  cin>>n;
  map<int,int> m;
  for(int i=0;i<n;++i){
    cin>>c;
    if((c/=400)>=8)r++;
    else m[c]++;
  }
  cout<<max((int)m.size(),1)<<" "<<m.size()+r<<endl;
  return 0;
}

Measured memory_bytes: 256
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int tx, ty, ch, cw;
int h, w;
char grid[1009][1009];
bool vis[1009][1009];

int dr[4] = {0, 0, -1, 1};
int dc[4] = {1, -1, 0, 0};

bool valid (int x, int y) {
	return x > 0 && x <= h && y > 0 && y <= w && !vis[x][y] && grid[x][y] == '.';
}

int solve() {
	deque < pair < pair<int, int> , int > > q;
	q.push_front({{ch, cw}, 0});

	while (!q.empty()) {
		pair < pair <int, int >, int > x = q.front(); q.pop_front();
		pair < int, int > pos = x.first;

		int u = pos.first;
		int v = pos.second;

		if(vis[u][v]) continue;
		vis[u][v] = true;

		if(u == tx && v == ty) {
			return x.second;
		}

		for(int d = 0; d < 4; d++) {
			int uu = u + dr[d];
			int vv = v + dc[d];

			if(valid(uu, vv)) {
				q.push_front({{uu, vv}, x.second});
			}
		}

		for(int i = -2; i <= 2; i++) {
			for(int j = -2; j <= 2; j++) {
				int uu = u + i;
				int vv = v + j;

				if(valid(uu, vv)) {
					q.push_back({{uu, vv}, x.second + 1});
				}
			}
		}
	}
	return -1;
}

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> h >> w;
	cin >> ch >> cw;
	cin >> tx >> ty;

	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			cin >> grid[i][j];
		}
	}

	
	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 6188
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int m = sc.nextInt();
            boolean answer = rec(0, m, A, n);
            if (answer) System.out.println("yes"); 
            else System.out.println("no"); 
        }
        sc.close();
    }
    public static boolean rec (int i, int m, int[] A, int n) {
        if (m == 0) return true;
        if (i >= n) return false;
        boolean res = rec(i + 1, m, A, n) || rec(i + 1, m - A[i], A, n);
        return res;
    }
}


Measured memory_bytes: 26844
#include <iostream>
#include <string>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
    int n, m, l;
    cin >> n >> m >> l;
    long long a[n][m], b[m][l], c[n][l];
    rep(i, n)
    {
        rep(j, m)
        {
            cin >> a[i][j];
        }
    }
    rep(i, m)
    {
        rep(j, l)
        {
            cin >> b[i][j];
        }
    }
    rep(i, n)
    {
        rep(j, l)
        {
            rep(k, m)
            {
                if (k == 0)
                    c[i][j] = a[i][k] * b[k][j];
                else
                    c[i][j] += a[i][k] * b[k][j];
            }
            cout << c[i][j];
            if (j == l - 1)
                continue;
            else
                cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3336
n, m, x = map(int, input().split())
a = []
c = 2000000
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(2**n):
    b = [0]*(m+1)
    for j in range(n):
        if i%2 == 1:
            for k in range(m+1):
                b[k] += a[j][k]
        i //= 2
    d = 0
    for j in range(m):
        if b[j+1] < x:
            d += 1
    if d == 0:
        c = min(c, b[0])
if c == 2000000:
    c =-1
print(c)

Measured memory_bytes: 9176
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
//const ll MOD = INF + 7;
//Combination MOD
const int MOD = 1e9 + 7;



int main(){
   int n;
   cin >> n;
   vector<ll> a(n);
   rep(i, n){
      cin >> a[i];
   }
   vector<ll> b(n);
   rep(i, n){
      if(i == 0)b[i] = a[i];
      else b[i] = b[i - 1] ^ a[i];
   }
   rep(i, n){
      cout << (b[n - 1] ^ a[i]) << " ";
   }
}

Measured memory_bytes: 6408
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll gcd(ll x, ll y)
{
    ll r;

    if(x == 0 || y == 0)
    {
        return 0;
    }
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll number1,ll number2){
	return (ll)((long double)number1 * number2 / gcd(number1,number2)+0.1);
}
int main(){
	int N;
	ll T[101];
	scan(N);
	rep(i,N){
		scan(T[i]);
	}
	ll ans=1;
	rep(i,N){
		ans=lcm(ans,T[i]);
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
    ll dp[2][2100];
  	string s;
  	cin >> s;
  	for(int i=0;i<2100;i++){
    	dp[0][i] =0;
    }
  	dp[0][(s[0]-'0')]=1;
  	ll ans=0;
  	for(ll i=1;i<(ll)s.size();i++){
    	for(ll j=0;j<2019;j++){
    	    dp[i%2][(j*10+(s[i]-'0'))%2019] =dp[(i-1)%2][j];
        }
      	dp[i%2][s[i]-'0']++;
      	ans += dp[i%2][0];
    }
  	cout << ans << endl;
}


Measured memory_bytes: 3760
//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define ld long double
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 3e2+10;
ld p[nax][nax][nax] , ex[nax][nax][nax];

signed main()
{
    fast;
    int n;
    cin >> n;
    int cnt[4] = {0};
    for(int i=1 ; i<=n ; i++ )
    {
        int x;
        cin >> x;
        cnt[ x ]++;
    }
    memset( p,0.0,sizeof(p));
    memset( ex, 0.0 , sizeof( ex ) );
    p[ cnt[1] ][ cnt[2] ][ cnt[3] ] = 1.0;
    
    for(int c = n; c>= 0 ; c-- )
    {
        for(int b = n ; b >= 0 ; b-- )
        {
            for(int a = n ; a >= 0 ; a-- )
            {
                if( !a && !b && !c ) continue;
                if( n < a+b+c ) continue;
                double aa = a;
                double bb = b;
                double cc = c;
                double nn = n;
                
                
                    double p_waste = ( nn - (aa+bb+cc) )/nn;
                    ex[ a ][ b ][ c ] += ((p[a][b][c]* p_waste) / (1.0 - p_waste) );
                
                
                if( a )
                {
                    double pr = aa/(aa+bb+cc);
                    p[ a-1 ][ b ][ c ] += ( p[a][b][c] * pr );
                    ex[ a-1][ b][ c] += ( (ex[a][b][c]) *pr );
                }
                if( b )
                {
                    double pr = bb/(aa+bb+cc);
                    p[ a+1 ][ b-1 ][ c ] += ( p[a][b][c] * pr );
                    ex[ a+1][ b-1 ][ c ] += ( (ex[a][b][c]) *pr );
                }
                if( c )
                {
                    double pr = cc/(aa+bb+cc);
                    p[ a ][ b+1 ][ c-1 ] += ( p[a][b][c] * pr );
                    ex[ a ][ b+1 ][ c-1] += ( (ex[a][b][c]) *pr );
                }
            }
        }
    }
    cout << fixed << setprecision( 9 ) << ex[0][0][0] + cnt[1] + cnt[2] *2.0 + cnt[3]*3;
}





Measured memory_bytes: 931328
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
using namespace std;

string str;

int main(){
	while(getline(cin,str)){
		stack<double> st;
		stringstream ss(str);
		while(ss >> str){
			if(str == "+"){
				double p = st.top(); st.pop();
				double q = st.top(); st.pop();
				st.push(p+q);
			} else if(str == "-"){
				double p = st.top(); st.pop();
				double q = st.top(); st.pop();
				st.push(q-p);
			} else if(str == "*"){
				double p = st.top(); st.pop();
				double q = st.top(); st.pop();
				st.push(p*q);
			} else if(str == "/"){
				double p = st.top(); st.pop();
				double q = st.top(); st.pop();
				st.push(q/p);
			} else{
				st.push((double)(atoi(str.c_str())));
			}
		}
		printf("%.7f\n", st.top());
	}
}

Measured memory_bytes: 1268
#include <stdio.h>
int main(void){
	int s,m,h;
	while(1){
	scanf("%d %d %d",&h,&m,&s);
	if(s<0 && m<0 && h<0)break;
	s+=m*60+h*3600;
	s=7200-s;
	m=s*3;
	printf("%02d:%02d:%02d\n",s/3600,(s/60)%60,s%60);
	printf("%02d:%02d:%02d\n",m/3600,(m/60)%60,m%60);
	}
	return 0;
}

Measured memory_bytes: 612
program kadai
implicit none
integer  ::  n,l,i,aji

read(*,*) n,l

aji=0
do i=1,n
aji=aji+l+i-1
end do

if (n+l-1<0) then
    aji=aji-(n+l-1)
end if
if (l>0) then
    aji=aji-l
end if

write(*,*) aji

end program kadai


Measured memory_bytes: 256
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
bc = []
for i in range(0,m):
    temp_bc = list(map(int,input().split()))
    bc.append(temp_bc)
bc.sort(key=lambda x:x[1])
bc.reverse()
i = 0
for j in range(0,m):
    for k in range(0,bc[j][0]):
        if a[i] < bc[j][1]:
            a[i] = bc[j][1]
        i += 1
        if i == n:
            break
    if i == n:
        break

print(sum(a))

Measured memory_bytes: 32968
#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a<1 && b>-1)
        printf("Zero\n");
    else if (a > 0)
        printf("Positive\n");
    else if ((b - a) % 2 == 0)
        printf("Negative\n");
    else
        printf("Positive\n");
    return 0;
}

Measured memory_bytes: 128
def get(s):
    length = len(s)
    sum = 0
    for i in range(length):
        sum += int(s[0:i+1])
        sum += get(s[i+1:])
        if len(s[i+1:]) != 0:
            sum += (2**(len(s[i+1:])-1)-1)*int(s[0:i+1])
    return int(sum)

def main():
    string = str(input())
    print(int(get(string)))

main()

Measured memory_bytes: 42992
#include <stdio.h>

int main()
{
    char word;
    scanf("%c",&word);
    if(word>='a' && word<='z')
    {
        printf("a\n");
    }
    if(word>='A' && word<='Z')
    {
        printf("A\n");
    }

    return 0;
}

Measured memory_bytes: 1572
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
int dp[100000][5], a[100000], b[100000], c[100000];
int main()
{
    int n;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[1][1] = a[1];
    dp[1][2] = b[1];
    dp[1][3] = c[1];
  for (int i=2;i<=n;i++)
    {
        dp[i][1] += max(dp[i - 1][2], dp[i - 1][3]) + a[i];
        dp[i][2] += max(dp[i - 1][1], dp[i - 1][3]) + b[i];
        dp[i][3] += max(dp[i - 1][1], dp[i - 1][2]) + c[i];
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
    return 0;
}

Measured memory_bytes: 3328
use std::cmp::Ordering;
use std::collections::BinaryHeap;
use std::collections::BTreeSet;
use std::cmp::Reverse;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        m: usize,
        s: Usize1,
        t: Usize1,
        mat: [(Usize1,Usize1,usize,usize); m]
    }

    let mut yen = vec![vec![]; n];
    let mut snu = vec![vec![]; n];
    for &(u,v,a,b) in mat.iter() {
        yen[u].push((v,a));
        yen[v].push((u,a));
        snu[u].push((v,b));
        snu[v].push((u,b));
    }

    let yeN = dijkstra(n, &yen, s);
    let snU = dijkstra(n, &snu, t);
    let mut ans = {
        let mut ans = Vec::new();
        for i in 0..n {
            ans.push((i,yeN[i]+snU[i]));
        }
        ans.sort_by(|(_,x),(_,y)| y.cmp(x));
        ans
    };

    let mut now = 0;
    while let Some((i,val)) = ans.pop() {
        if now <= i {
            for _ in now..=i {
                println!("{}",1000000000000000-val)
            }
            now = i+1;
        }
    }

}

#[derive(Clone,Copy)]
struct Pair {
    label: usize,
    value: usize,
}

impl Pair {
    fn new(l: usize, v: usize) -> Pair {
        Pair { label: l, value: v }
    } 
}

impl Ord for Pair {
    fn cmp(&self, other: &Self) -> Ordering {
        self.value.cmp(&other.value)
    }
}

impl PartialOrd for Pair {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for Pair {
    fn eq(&self, other: &Self) -> bool {
        (self.label,self.value) == (other.label,other.value)
    }
}

impl Eq for Pair { }

pub fn dijkstra (size: usize, list: &Vec<Vec<(usize,usize)>>, start: usize) -> Vec<usize> {
    let mut potential = vec![std::usize::MAX; size];
    potential[start] = 0;
    let mut heap = BinaryHeap::new();
    heap.push(Reverse(Pair::new(start,0)));
    let mut set = BTreeSet::new();
    for i in 0..size {
        set.insert(i);
    }
    while let Some(Reverse(pair)) = heap.pop() {
        if set.contains(&pair.label) {
            set.remove(&pair.label);
            for &(v,weight) in list[pair.label].iter() {
                if set.contains(&v) && (potential[v] > potential[pair.label] + weight) {
                    potential[v] = potential[pair.label] + weight;
                    heap.push(Reverse(Pair::new(v,potential[v])));
                }
            }
        }
        if set.is_empty() {
            break;
        }
    }
    potential
}

Measured memory_bytes: 29296
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N;
	cin >> N;

	lint ans = 1;
	lint a = 2;
	lint b = 1;
	for (int i = 0; i < N - 1; i++)
	{
		ans = a + b;
		a = b;
		b = ans;
	}

	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int n,k,x[105],s=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&x[i]);
    for(int i=1;i<=n;i++)
    {
        int a=x[i]*2,b=abs(x[i]-k)*2;
        s+=min(a,b);
    }
    printf("%d\n",s);
}


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

int main() {
    // 入力, キューにまずは順に要素を追加します
    int N;
    int Q; // クオンタム
    cin >> N >> Q;
    queue<pair<string,int> > que;
    for (int i = 0; i < N; ++i) {
        string name;
        int time;
        cin >> name >> time;
        que.push({name, time});
    }

    // ラウンドロビンスケジーリング
    int cur_time = 0;
    while (!que.empty()) {
        auto cur = que.front();
        que.pop();

        // Q 秒以上かかるとき、Q 秒処理してまたキューに追加
        if (cur.second > Q) {
            cur_time += Q;
            cur.second -= Q;
            que.push(cur);
        }
        // Q 秒以内に終了するときは、処理を終えてプログラムを出力する
        else {
            cur_time += cur.second;
            cout << cur.first << " " << cur_time << endl;
        }
    }   
}   



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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = (1ll << 30) - 1;  //nearly 1.07e9
const ll INFLL = 1ll << 60;       //nearly 1.15e18
const int MOD = 1e9 + 7;
const long double EPS = 1.0e-14;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

//================ Main Loop ================
int main() {
    int l;
    cin >> l;
    setpre(10);
    cout << (l / (long double)3.0) * (l / (long double)3.0) * (l / (long double)3.0) << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;

    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    auto tri = [&](bool t, string a, string b){
        cout << (t ? a : b) << endl;
    };

    cin >> a >> b >> c;
    YES((a * 100 + b * 10 + c) % 4 == 0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	char c;
	cin >> c;
	if ('a' <= c and c <= 'z')
		cout << "a" << endl;
	else
		cout << "A" << endl;
	return 0;
}

Measured memory_bytes: 3648
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sat Dec  8 20:05:49 2018
//
package main

import "fmt"

const MOD = 1e9 + 7

func main() {
	var S string
	fmt.Scan(&S)
	dp := make([][]int, len(S)+1)
	for i := range dp {
		dp[i] = make([]int, 4)
	}

	dp[0][0] = 1
	for i := 0; i < len(S); i++ {
		switch S[i] {
		case 'A':
			dp[i+1][0] = dp[i][0]
			dp[i+1][1] = (dp[i][1] + dp[i][0]) % MOD
			dp[i+1][2] = dp[i][2]
			dp[i+1][3] = dp[i][3]
		case 'B':
			dp[i+1][0] = dp[i][0]
			dp[i+1][1] = dp[i][1]
			dp[i+1][2] = (dp[i][2] + dp[i][1]) % MOD
			dp[i+1][3] = dp[i][3]
		case 'C':
			dp[i+1][0] = dp[i][0]
			dp[i+1][1] = dp[i][1]
			dp[i+1][2] = dp[i][2]
			dp[i+1][3] = (dp[i][3] + dp[i][2]) % MOD
		case '?':
			dp[i+1][0] = 3 * dp[i][0] % MOD
			dp[i+1][1] = (3*dp[i][1] + dp[i][0]) % MOD
			dp[i+1][2] = (3*dp[i][2] + dp[i][1]) % MOD
			dp[i+1][3] = (3*dp[i][3] + dp[i][2]) % MOD
		}
	}

	fmt.Println(dp[len(S)][3])
}


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

using namespace std;

const int maxn = 2e5 + 9;

using lint = long long;

int a[maxn], b[maxn];
priority_queue<pair<int, int>> pq;

int main() {
#if DEBUG
    freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        pq.push({b[i], i});
    }
    lint ans = 0;
    while (!pq.empty()) {
        pair<int, int> here = pq.top();
        pq.pop();
        if (b[here.second] <= a[here.second]) continue;
        int p = b[(here.second + n - 1) % n];
        int q = b[here.second];
        int r = b[(here.second + 1) % n];
        lint s = (q - a[here.second]) / (p + r);
        if (s == 0) {
            cout << "-1\n";
            return 0;
        }
        ans += s;
        q -= s * (p + r);
        b[here.second] = q;
        if (a[here.second] != b[here.second])
            pq.push({q, here.second});
    }
    for (int i = 0; i < n; ++i) {
        if (a[i] != b[i]) {
            cout << "-1\n";
            return 0;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3700
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("in.txt", "r", stdin); 
    freopen("out.txt", "w", stdout); 
#endif 
}

const int MX=1e5;
int N,K; 
int t[MX];
int memo[MX];

int solve(int idx){
	if(idx==N-1) return 0;
	if(idx>=N) return INF;
	if(memo[idx]!=-1) return memo[idx];
	int ans=INF;
	for(int i=idx+1; i<idx+K+1 && i<N; i++){
		ans=min(ans,solve(i)+abs(t[idx]-t[i]));
	}
	/*int ans=solve(idx+1)+abs(t[idx]-t[idx+1]);
	if(idx<N-2) ans=min(ans,solve(idx+2)+abs(t[idx]-t[idx+2]));*/
	return memo[idx]=ans;
}

int32_t main(){
   boost;
   IO();
   memset(memo,-1,sizeof(memo));
   cin>>N>>K;
   for(int i=0; i<N; i++) cin>>t[i];
   cout << solve(0) << endl;

   return 0;
}



Measured memory_bytes: 9888