akhauriyash/Code-Regression huggingface dataset:
isOperator str = str=="+" || str=="-" || str=="*"

operatorCalc :: Int -> Int -> String -> Int
operatorCalc a b op | op=="+"   = a+b
                    | op=="-"   = a-b
                    | op=="*"   = a*b
                    | otherwise = 0

reversePolishNotation::[String]->[String]
reversePolishNotation (a:[])       = [a]
reversePolishNotation (a:b:[])     = [a,b]
reversePolishNotation (a:b:c:expr) = if (isOperator c && not(isOperator b) && not(isOperator a))
                                        then reversePolishNotation(show(operatorCalc(read a)(read b)c):expr)
                                        else if isOperator b
                                            then a:b:c:expr
                                            else reversePolishNotation(a:reversePolishNotation(b:c:expr))

main = do{
    getLine>>=putStrLn.head.reversePolishNotation.words;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N);
  vector<int> y(N);
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }
  
  int xUpper = W, xLower = 0, yUpper = H, yLower = 0;
  for (int i = 0; i < N; i++) {
    if (a.at(i) == 1) {
      xLower = max(xLower, x.at(i));
    } else if (a.at(i) == 2) {
      xUpper = min(xUpper, x.at(i));
    } else if (a.at(i) == 3) {
      yLower = max(yLower, y.at(i));
    } else if (a.at(i) == 4) {
      yUpper = min(yUpper, y.at(i));
    }
  }
  
  if ((xLower < xUpper) and (yLower < yUpper)) {
    cout << (xUpper - xLower) * (yUpper - yLower) << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3604
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();
		// // 文字列の入力
		// String s = sc.next();
		// // 出力
    // System.out.println((a+b+c) + " " + s);
    String N = sc.next();
    if (N.charAt(0) == N.charAt(1) && N.charAt(0) == N.charAt(2)) {
      System.out.println("Yes");
    } else if (N.charAt(1) == N.charAt(2) && N.charAt(1) == N.charAt(3)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
	}
}

Measured memory_bytes: 21844
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    int n;
    Edges[] es;


    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        n = sc.nextInt();
        es = new Edges[n];

        for (int i = 0; i < n; i++) {
            es[i] = new Edges();
        }

        for (int i = 0; i < n - 1; i++) {
            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
            es[a].add(new P(b, i));
            es[b].add(new P(a, i));
        }

        int[] cs = new int[n - 1];

        LinkedList<P> q = new LinkedList<>();
        q.add(new P(0, -1));

        boolean[] visited = new boolean[n];
        int max = 0;
        while (!q.isEmpty()) {
            P cur = q.removeLast();
            visited[cur.a] = true;

            int c = 0;
            for (P next : es[cur.a]) {
                if (visited[next.a]) continue;
                if (c == cur.b) c++;
                cs[next.b] = c;
                max = Math.max(cs[next.b], max);
                q.addFirst(new P(next.a, c++));
            }
        }
        out.println(max + 1);

        for (int i = 0; i < n - 1; i++) {
            out.println(cs[i] + 1);
        }

        out.flush();
    }

    class P implements Comparable<P> {
        int a, b;
        P(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(P o) {
            return o.b - b;
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }
    }

    class Edges extends ArrayList<P> {}

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.rbegin(), A.rend());
	int t = -1;
	vector<ll> ma;
	for (int i = 0; i < N; i++) {
		if (A[i] == t) {
			ma.push_back(A[i]);
			t = -1;
		}
		else {
			t = A[i];
		}
	}
	if ((int)ma.size() >= 2) {
		cout << ma[0] * ma[1] << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}


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

ll dp[11];
ll dpp[11];

ll tx(int k){
  ll a=1;
  for(int i=0;i<k;i++){
    a*=10;
  }
  return a;
}

ll twx(int k){
  if(k<2)
    return 1;
  ll a=1;
  for(int i=0;i<k-1;i++){
    a*=2;
  }
  return a;
}

ll solve(ll x){
  ll a=0;
  for(int i=0;tx(i)<=x;i++){
    a+=(x/tx(i))*dpp[i]+dp[i];
  }
  return a;
}

int main(){
  ll S,C;
  cin>>S;
  for(int i=0;i<11;i++){
    dpp[i-1]=twx(i-1);
    C=solve(S%tx(i));
    if(tx(i)>S){
      cout<<C<<endl;
      return 0;
    }
    dp[i]=C;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>p, a;
	p.push_back(0);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		p.push_back(x);
	}
	p.push_back(0);
	int t = 0;
	long long int r = 0;
	for (int i = 0; i < n+1 ; i++) {
		a.push_back(abs(p[i+1] - t));
		r += abs(p[i+1] - t);
		t = p[i+1];
	//	cout << a[i] << endl;
	}
	//p.push_back(0);
	//a.push_back(abs(t));
	r += abs(t);
	//cout << r;
	for (int i = 1; i < n+1; i++) {
		cout << r - (a[i - 1] + a[i]) + abs(p[i + 1] - p[i-1]) << endl;
	}
	

	return 0;
}

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

using namespace std;
const int MAXN = 1e3 + 7;
const int MOD = 1e9 + 7;

long long dp[MAXN][MAXN];
char a[MAXN][MAXN];

int main() {
  memset(dp, 0, sizeof(dp));
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if(!i && !j) dp[i][j] = (a[i][j] == '.');
      else if(a[i][j] == '.') {
        if(!i) dp[i][j] = dp[i][j-1];
        else if(!j) dp[i][j] = dp[i-1][j];
        else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
      }
    }
  }
  cout << dp[n-1][m-1] << '\n';
  return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rb(i,x) for (auto& i : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define UNIQUE(x) (x).resize(unique(all(x)) - begin(x))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define pow10(n) stoll("1"+string(n,'0'))
#define dbg(x) cout << ">>> " << #x << ": " << x << '\n'

const int MOD = 1e9+7; //998244353
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;
const ld PI = acos((ld)-1);
const int dx[8] = {1,0,-1,0,1,1,-1,-1}, dy[8] = {0,1,0,-1,-1,1,1,-1};
mt19937_64 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll n) { return uniform_int_distribution<ll>(0, n)(rng); }
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

void setIO(const string& s) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

int main() {
    
    setIO("input");
    int n,x,t; cin >> n >> x >> t;
    cout << (n+x-1) / x * t << '\n';
    
}

/*  ! CHECK THIS IF YOU GET IT WRONG !
	* int overflow, array bounds, NO VLAs
	* uninitialized local variables, rounding errors
	* intermediate result type, scientific
	* special cases (n = 0 or 1?)
	* reset your variables in scope
	* INF not large enough for ans, adding value to _MAX
	* using wrong variables, sorting extra 0s in global array
	* comment out input from file
	* operator precedence
*/

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int n,k;

vector <int> v;
vector <int> s;
int solve(int a){
    if(a<=1) return 0;
    if(v[a]!=-1) return v[a];
    int temp = INT_MAX;
    if(a<1+k) {
        
        int upto = a-1;
        for(int i=1;i<=upto;i++) temp = min(temp,abs(s[i]-s[a])+ solve(i));
        v[a]= temp;
        return temp;
         temp = INT_MAX;
    }
    
    else if(a>=1+k)for(int i=1;i<=k;i++) temp = min(temp,abs(s[a-i]-s[a])+ solve(a-i) ),v[a]=temp; 
    return v[a]; 
}
int main(){
    // int t,n;
    cin>>n;
    cin>>k;
    v.resize(n+1,-1);
    s.resize(n+1,-1);
    for(int i=1;i<=n;i++) cin>>s[i];
    cout<<solve(n)<<endl;
    // cout<<v[n]
    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int S, W; cin >> S >> W;
    if(S <= W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    //ll P , Q , R;
    //cin >> P >> Q  >> R;
    ll N = 0;
    cin >> N;
    vector <ll > p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }

    ll total = 0;
    for(int i = 1; i < N - 1; i++){
        vector<ll > p3(3,0);
        p3[0] = p[i-1];
        p3[1] = p[i];
        p3[2] = p[i+1];
        sort(p3.begin(),p3.end());
        if(p3[1] == p[i]){
            total++;
        }
    }
    cout << total << endl;

} 

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

int main() {
        priority_queue<int> Q;
        string s;
        while (cin >> s && s != "end"){
                if (s == "insert"){
                        int i;
                        cin >> i;
                        Q.push(i);
                }
                else if (s == "extract"){
                        cout << Q.top() << endl;
                        Q.pop();
                }
        }
}

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

int main() {
  int n, Alice_score = 0, Bob_score = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n)	cin >> a.at(i); /* 入力を受け取る */
  sort(a.begin(), a.end()); /* 昇順に並べ替え*/
  reverse(a.begin(), a.end()); /* 逆順（降順）に並べ替え*/
  rep(i, n) {
    if (i % 2 == 0)
      Alice_score += a.at(i);
    else
      Bob_score += a.at(i);
  }
  cout << Alice_score - Bob_score << endl;
}

Measured memory_bytes: 256
// Problem : B - FizzBuzz Sum
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    long n;
    cin >> n;
    long long s = 0;
    for (long i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) s = s + i;
    }
    cout << s;
    
    return 0;
}


Measured memory_bytes: 3652
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector <string>
#define vvs vector <vector<string>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr ll inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }

    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
#define double long double
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int N;
    cin >> N;
    int B = lcm(N, 360);
    cout << B / N << endl;
}






Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

template< typename T >
using Matrix = vector< vector< T > >;


void solve(void)
{
  int T1,T2;cin>>T1>>T2;
  int A1,A2; cin>>A1; cin>>A2;
  int B1,B2; cin>>B1; cin>>B2;
  if(A1 > B1)
  {
    swap(A1,B1);
    swap(A2,B2);
  }
  if(T1*A1 + T2*A2 == T1*B1 + T2*B2)
  {
    cout<<"infinity"<<endl;
    return;
  }
  if(T1*A1 + T2*A2 < T1*B1 + T2*B2)
  {
    cout<<0<<endl;
    return;
  }


  int D1 = T1*B1 - T1*A1;
  int UP = T1*A1 + T2*A2 - T1*B1 - T2*B2;
  // DEBUG(D1,UP,D1/UP);
  cout<<D1/UP*2 +(D1%UP >0)<<endl;


  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 3676
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

per = list(permutations(range(1, N + 1)))

for i, pe in enumerate(per, start=1):
    if P == pe:
        a = i
    if Q == pe:
        b = i
print(abs(a - b))


Measured memory_bytes: 8052
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  vector<int> ten(10);
  for(int i=0;i<10;++i) ten[i] = i;
  vector<int> arr;
  map<int, int> amap;
  int num;
  int amari = 0;
  for(int i=S.size()-1;i>=0;--i) {
    num = S[i]-'0';
    amari += ten[num];
    amari %= 2019;
    if(amap[amari]==0) arr.push_back(amari);
    amap[amari]++;
    for(int j=0;j<10;++j) {
      ten[j] = ten[j]*10%2019;
    }
  }
  int ans = 0;
  for(int i=0;i<arr.size();++i) {
    ans += amap[arr[i]]*(amap[arr[i]]-1)/2;
  }
  cout<<ans+amap[0]<<endl;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

Int f(Int x) {
   Int res = 0;
   while( x != 0 ) {
      res += x % 10;
      x /= 10;
   }
   return res;
}

int main() {
   Int n;
   std::cin >> n;
   Int res = f(n);
   for(Int i = 0, x = 1; n/x > 0 ; i+=1, x*=10) {
      res = std::max(res, f(n/x-1) + i * 9);
   }
   printf("%ld\n", res);
}


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

struct Mystruct
{
	int cnt = 0;
	string str;
};

int main() {
	int R, B;
	int num = 0;
	int flg = 0;
	int max = 0;
	Mystruct t[100];
	string tmp;

	cin >> R;
	for (int i = 0;i < R;i++) {
		cin >> tmp;

		//�T��
		flg = 0;
		for (int i = 0; i < num&&flg==0; i++)
		{
			if (tmp == t[i].str) {
				t[i].cnt++;
				flg = 1;
			}
		}
		//t�ɂȂ����
		if (flg == 0) {
			t[num].str = tmp;
			t[num].cnt = 1;
			num++;
		}
	}
	/*
	cout << "�z��" << endl;
	for (int i = 0;i < num;i++) {
		cout << t[i].str << ":" << t[i].cnt << endl;
	}
	cout << "�����" << endl;
	*/

	cin >> B;
	for (int i = 0;i < B;i++) {
		cin >> tmp;
		for (int i = 0;i < num;i++) {
			if (tmp == t[i].str) {
				t[i].cnt--;
			}
		}
	}
	/*
	cout << "�z��" << endl;
	for (int i = 0;i < num;i++) {
		cout << t[i].str << ":" << t[i].cnt << endl;
	}
	cout << "�����" << endl;
	*/

	for (int i = 0;i < num;i++) {
		if (max < t[i].cnt)
			max = t[i].cnt;
	}

	cout << max << endl;
	
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

n,y = map(int,input().split())

n10000 = -1
n5000 = -1
n1000 = -1

for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if i*10000+j*5000+1000*k == y:
            n10000 = i
            n5000 = j
            n1000 = k

print(n10000,n5000,n1000)
            


Measured memory_bytes: 40812
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a*b <= 0 {
		fmt.Println("Zero")
	} else if a > 0 {
		fmt.Println("Positive")
	} else {
		if (b-a)%2 == 0 {
			fmt.Println("Negative")
		} else {
			fmt.Println("Positive")
		}
	}
}


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

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

	vector<int> a(n);

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

	int th = sum / (4 * m);
	int aviable = 0;

	for (int i = 0; i < n; i++) {
		//if (a[i] >= th) aviable++;
		if (a[i] * 4 * m >= sum) aviable++;
	}

	if (aviable >= m) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))

void solve()
{
    ll A,B;
    cin >> A >> B;
    if (A % 3 == 0) {
        cout << "Possible" << endl;
    }
    else if (B % 3 == 0) {
        cout << "Possible" << endl;
    }
    else if ((A + B) % 3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
}

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


Measured memory_bytes: 256
import math

a,b,x=input().split()
a,b,x=[int(a),int(b),int(x)]

if(x/a > a*b*0.5):
  c=(2*b*(a**2)-2*x)/(a**3)
  print(math.degrees(math.atan(c)))
else:
  c=(a*b**2)/(x*2)
  print(math.degrees(math.atan(c)))

Measured memory_bytes: 3064
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int count = 0;
    int total = 0;
    
    for(int i = 1; i <= N; i++){
      int n=i;
      count = 0;
      while(n>0){
        count += n % 10;
        n = n / 10;
      }
      if(A<=count && count<=B){
        total += i;
      }
 
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll inf = 1LL<<60;
int main()
{
  int n,k;
  cin >> n >> k;
  vector<ll> h(n+1);
  h[0] = 0;
  rep1(i,n){
    cin >> h[i];
  }

  vector<vector<ll>> dp(n+1,vector<ll>(n+1,inf));
  // rep(i,n+1){
  //   dp[i][0] = 0;
  // }
  dp[0][0] = 0;
  rep1(i,n){
    rep1(j,n){
      rep(l,i){
	dp[i][j] = min(dp[i][j],dp[l][j-1]+max((ll)0,h[i]-h[l]));
      }
    }
  }

  ll res = inf;
  rep(i,n+1){
    res = min(res,dp[i][n-k]);
  }
  cout << res << "\n";


  // rep(i,n+1){
  //   rep(j,n+1){
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << "\n";
  // }
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==1 && b==2)
    cout<<"3";
  else if(a==2 && b==3)
    cout<<"1";
  else if(a==1 && b==3)
    cout<<"2";
  if(a==2 && b==1)
    cout<<"3";
  else if(a==3 && b==2)
    cout<<"1";
  else if(a==3 && b==1)
    cout<<"2";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    for(int i = 1; i <= n; i++) {
      if (String.valueOf(i).length() % 2 == 1) count++;
    }
    System.out.println(count);
  }
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  string s;
  cin >> s;
  ll q;
  cin >> q;
  ll rcnt = 0;
  string fs = "";
  string bs = "";
  while (q--) {
    ll t;
    cin >> t;
    if (t == 1) {
      ++rcnt;
    } else {
      ll f;
      char c;
      cin >> f >> c;
      if (f == 1) {
        if (rcnt % 2 == 0) {
          fs += c;
        } else {
          bs += c;
        }
      } else {
        if (rcnt % 2 == 0) {
          bs += c;
        } else {
          fs += c;
        }
      }
    }
  }

  if (rcnt % 2 == 0) {
    reverse(ALL(fs));
    s = fs + s + bs;
  } else {
    reverse(ALL(s));
    reverse(ALL(bs));
    s = bs + s + fs;
  }

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 1348
from collections import Counter
import sys

n = int(input())
x = [0]*n ; y = [0]*n
for i in range(n):
    x[i],y[i] = map(int, input().split())

if n == 1:
    print(1)
    sys.exit()

dc_c = []
dc_c = []
dc_ans = []
for i in range(n):
    ii = 0
    d = [[-1]*2 for i in range(n)]
    for j in range(n):
        if i != j:
            d[ii][0] = x[i]-x[j]
            d[ii][1] = y[i]-y[j]
            ii += 1
    dc = Counter(map(tuple, d))
    dc_ans = Counter(dc_ans) + dc
dc_ans = dc_ans.most_common()
if dc_ans[0][0] == (-1, -1):
    print(n-dc_ans[1][1])
else:
    print(n-dc_ans[0][1])


Measured memory_bytes: 4248
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
mt19937 rnd(1337);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pNN pair <Node *, Node *>
#define SZ(x) (int)(x).size()
#define pii pair <int, int>
#define pb push_back
#define rev reverse
#define ins insert
#define ers erase
#define S second
#define F first
#define int ll
const int N = 1e5 + 10, INF = 1e9 + 10;

void solve() {
	int n, k;
	cin >> n >> k;
	n = (n % k);
	cout << min(n, k - n);
}
 
signed main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    #ifdef Solenoid555
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <algorithm>
#include <stdio.h>
using namespace std;

typedef vector<int> VInt;
typedef vector<VInt> VVInt;

typedef list<int> LInt;
typedef vector<LInt> VLInt;
typedef LInt::iterator LIter;
typedef vector<LIter> VLIter;

// Input: the network
int n, src, dest;
VVInt c;

// Output: the flow (preflow while the algo is running)
VVInt f;

// Additional data
VInt h, e;
VLInt nei;
VLIter current;

// Lift the vertex. Assumes that this is possible.
void lift(int u)
{
	int height = 2 * n;
	for (LIter it = nei[u].begin(); it != nei[u].end(); it++)
		if (c[u][*it] > f[u][*it])
			height = min(height, h[*it]);
	h[u] = height + 1;
}

// Push the flow along the given edge. Assumes that this is possible.
void push(int u, int v)
{
	int value = min(c[u][v] - f[u][v], e[u]);
	f[u][v] += value;
	f[v][u] = -f[u][v];
	e[u] -= value;
	e[v] += value;
}

// Discharge the given vertex. Returns true if lifting occurred.
bool discharge(int u)
{
	bool lifted = false;
	while (e[u] > 0) {
		if (current[u] == nei[u].end()) {
			lift(u);
			lifted = true;
			current[u] = nei[u].begin();
			continue;
		}
		int v = *current[u];
		if (c[u][v] > f[u][v] && h[u] == h[v] + 1)
			push(u, v);
		else
			current[u]++;
	}
	return lifted;
}

// The actual lift-to-front algo (with initialization)
// Returns the max flow value
int ltf()
{
	int u, v;

	// Build the neighbours lists
	nei.resize(n);
	current.resize(n);
	for (u = 0; u<n; u++) {
		for (v = 0; v<n; v++)
			if (c[u][v] > 0 || c[v][u] > 0)
				nei[u].push_back(v);
		current[u] = nei[u].begin();
	}

	// Initialize the preflow
	f.assign(n, VInt(n, 0));
	e.assign(n, 0);
	h.assign(n, 0);
	h[src] = n;
	for (u = 0; u<n; u++)
		if (c[src][u] > 0) {
			e[u] = c[src][u];
			f[src][u] = c[src][u];
			f[u][src] = -f[src][u];
		}

	// lift-to-front
	LInt theList;
	for (u = 0; u<n; u++)
		if (u != src && u != dest)
			theList.push_back(u);
	LIter cur = theList.begin();
	while (cur != theList.end()) {
		u = *cur;
		if (discharge(u)) {
			theList.erase(cur);
			cur = theList.insert(theList.begin(), u);
		}
		cur++;
	}
	return e[dest];
}

// A small demo
int main()
{
	int i, j, edgeCount;

	// read the input
	scanf("%d%d", &n, &edgeCount);
	src = 0;
	dest = n - 1;
	c.assign(n, VInt(n, 0));
	while (edgeCount--) {
		int val;
		scanf("%d%d%d", &i, &j, &val);
		c[i][j] = val;
	}

	// find the max. flow
	int result = ltf();

	// print the results
	printf("%d\n", result);
	/*for (i = 0; i<n; i++)
		for (j = 0; j<n; j++)
			if (f[i][j] > 0)
				printf("%d -> %d : %d\n", i, j, f[i][j]);*/
	return 0;
}


Measured memory_bytes: 3008
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>


using namespace std;

int main()
{
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200) {
        cout << s << endl;
    }else{
        cout << "red" <<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define sc second
using namespace std;

string str;
int pos = 0;

char cmp(char x, char y, char z){
	if(x == ' '){
		if(z == 'T') return 'F';
		else return 'T';
	}
	if(y == '*'){
		if(x=='T'&&z=='T') return 'T';
		return 'F';
	}
	if(y == '+'){
		if(x=='F'&&z=='F') return 'F';
		else return 'T';
	}
	if(y == '-'){
		if(x=='T'&&z=='F') return 'F';
		else return 'T';
	}
	return 'T';
}

char dfs(string x){
	if(x[pos] == '-'){
		pos++;
		return cmp(' ','-',dfs(x));
	}
	if(x[pos] == 'T' || x[pos] == 'F'){
		char ret = x[pos];
		pos++;
		return ret;
	}
	pos++;
	char R = dfs(x);
	char X = x[pos]; pos++; if(X == '-') pos++;
	char L = dfs(x);
	pos++;
	return cmp(R,X,L);
}

int main(){
	while(cin >> str,str[0]!='#'){
		bool yes = true;
		for(int i = 0; i < (1<<11); i++){
			string s = str;
			rep(j,s.size()){
				if('a' <= s[j] && s[j] <= 'a'+10){
					if((i>>(s[j]-'a'))&1){
						s[j] = 'T';
					} else{
						s[j] = 'F';
					}
				}
			}
			string S[2];
			int cnt = 0;
			rep(j,s.size()){
				if(s[j] == '='){
					cnt++;
					continue;
				}
				S[cnt].pb(s[j]);
			}
			pos = 0;
			char R = dfs(S[0]);
			pos = 0;
			char L = dfs(S[1]);
			
			if(R != L){
				yes = false;
				break;
			}
		}
		if(yes) puts("YES");
		else puts("NO");
	}
}

Measured memory_bytes: 2268
#include<bits/stdc++.h>
using namespace std;
main()
{
int n,a,b,cnt=0,b_cnt=0;
string s;
cin>>n>>a>>b;
cin>>s;
for(int i=0;i<n;i++)
{
if(s[i]=='c') {cout<<"No\n";continue;}
else if(s[i]=='a')
{
if(cnt<a+b) 
{
cnt++;
cout<<"Yes\n";
}
else cout<<"No\n";
}
else if(s[i]=='b')
{
if(cnt<a+b&&b_cnt<b) 
{
cnt++;
b_cnt++;
cout<<"Yes\n";
}
else cout<<"No\n";
}
}
}

Measured memory_bytes: 896
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int r, g, b;
		String s;
		int map[][] = {{0, 0, 0}, {0, 0, 255}, {0, 255, 0}, {0, 255, 255}, {255, 0, 0}, {255, 0, 255}, {255, 255, 0}, {255, 255, 255}};
		String color[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
		int minIndex;
		double min;
		
		while (true) {
			s = sc.next();
			if (s.equals("0")) {
				break;
			}
			
			r = Integer.decode("0x" + s.substring(1, 3)).intValue();
			g = Integer.decode("0x" + s.substring(3, 5)).intValue();
			b = Integer.decode("0x" + s.substring(5, 7)).intValue();
			
			minIndex = 0;
			min = Double.MAX_VALUE;
			for (int i = 0; i < 8; i++) {
				double dk = Math.sqrt(Math.pow(r - map[i][0], 2) + Math.pow(g - map[i][1], 2) + Math.pow(b - map[i][2], 2));
				if (dk < min) {
					min = dk;
					minIndex = i;
				}
			}
			System.out.println(color[minIndex]);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }



int main(){
  string a,b,c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << endl;
}


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

struct Edge{int s,t,cost;};

int main(){
	int V,E,r;
	cin >> V >> E >> r;
	
	vector<Edge> G(E);
	for (int i=0;i<E;i++){
		cin >> G[i].s >> G[i].t >> G[i].cost;
	}
	
	vector<int> d(V,INT_MAX);
	d[r]=0;
	
	for (int i=0;i<V;i++){
		for (int j=0;j<E;j++){
			Edge e=G[j];
			if(d[e.s]==INT_MAX){
				continue;
			}else{
				if(d[e.t]>d[e.s]+e.cost){
					d[e.t]=d[e.s]+e.cost;
				}
			}
		}
	}
	bool flag=0;
	for (int j=0;j<E;j++){
			Edge e=G[j];
			if(d[e.s]==INT_MAX){
				continue;
			}else{
				if(d[e.t]>d[e.s]+e.cost){
					flag=1;
					break;
				}
			}
		}
	
	if(flag){
		cout << "NEGATIVE CYCLE" <<endl;
	}else{
	for (int i=0;i<V;i++){
		if(d[i]==INT_MAX){
			cout << "INF" << endl;
		}else{
			cout << d[i] << endl;
		}
	}
	}
	return 0;
}

Measured memory_bytes: 1224
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import qualified Data.IntMap.Strict as IM
import Data.Bits

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

parseBin :: Int -> [Int] -> Int
parseBin n xs = sum $ map (\x -> 2^(n-x)) xs

main :: IO ()
main = do
    [n,m] <- r'
    input <- replicateM m $ do
        [a, _]<- r'
        cs <- r'
        return (parseBin n cs, a)
    let inputMap = IM.fromListWith min input
    vec <- VM.replicate (2^n) (-1 :: Int)
    VM.write vec 0 0 
    x <- forM_ (IM.toList inputMap)
                (\(cs,a) ->
                    forM_ [0..(2^n-1)] (\cs' -> do
                            a' <- VM.read vec cs'
                            let nIdx = cs .|. cs'
                                nVal = a' + a
                            oVal <- VM.read vec nIdx
                            if a' /= -1 && (nVal < oVal || oVal == -1)
                                    then VM.write vec nIdx nVal
                                    else return ()
                        )
                )
    res <- VM.read vec (2^n-1)
    print res


Measured memory_bytes: 1404
def rot(v):
    v = [-v[1],v[0]]
    return v

S = list(map(int, input().split()))

u = [S[2]-S[0],S[3]-S[1]]
v = rot(u)
w = rot(v)

X3 = [S[2]+v[0],S[3]+v[1]]
X4 = [X3[0]+w[0],X3[1]+w[1]]

print(*(X3+X4))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;

int px[90010], py[90010];
int magic[90010];

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

	int h, w, d, a, Q;
	cin >> h >> w >> d;

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a;
			px[a] = j;
			py[a] = i;
		}
	}
	
	magic[0] = 0;
	for (int i = d+1; i <= h * w; i++) {
		magic[i] = magic[i - d] + abs(px[i] - px[i - d]) + abs(py[i] - py[i - d]);
	}

	cin >> Q;
	while (Q--) {
		int r, l;
		cin >> l >> r;
		cout << magic[r] - magic[l] << endl;
	}

	return 0;
}

Measured memory_bytes: 2176
from collections import deque

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

t = [[] for _ in range(n+1)]

for a, b in ab:
    t[a].append(b)
    t[b].append(a)

ans = 1
frag = [True]*(n+1)
d = deque()

for i in range(1, n+1):
    if not frag[i]:
        continue
    d.append(i)
    l = []
    while d:
        num = d.popleft()
        for j in t[num]:
            if not frag[j]:
                continue
            d.append(j)
            l.append(j)
            frag[j] = False
    ans = max(ans, len(set(l)))

print(ans)

Measured memory_bytes: 82020
a = list(map(int,input().split()))
N = a[0]
M = a[1]
X = list(map(int,input().split()))
X.sort()
path = []
for i in range(1,M):
    path.append(X[i]-X[i-1])
path.sort()
choose = M - N
sum = 0
for i in range(choose):
    sum += path[i]
print(str(sum))

Measured memory_bytes: 13960
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, M; cin >> N >> M;
  vector<ll> X(M);
  REP(i, M) cin >> X[i];
  if (N >= M) cout << 0 << endl;
  else {
    sort(ALL(X));
    vector<ll> dist(M - 1);
    REP(i, M - 1) dist[i] = X[i + 1] - X[i];
    sort(ALL(dist), greater<ll>());
    ll sum = 0;
    REP(i, N - 1) sum += dist[i];
    cout << (X[M-1] - X[0] - sum) << endl;
  }
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int h,w;
int c[1500][1500]={0};
int m=-1;

int main(){
  
  scanf(" %d %d",&h,&w);
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf(" %d",&c[i][j]);
      if(c[i][j]==0)c[i][j]=1;
      else c[i][j]=0;
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(i>0&&j>0&&c[i][j]!=0&&c[i-1][j]!=0&&c[i][j-1]!=0&&c[i-1][j-1]!=0){
	int mi=min(c[i-1][j],min(c[i][j-1],c[i-1][j-1]));
	c[i][j]=mi+1;
	//cout << mi << endl;
      }      
      m=max(c[i][j],m);
    }
  }

  cout << m*m << endl;

  return 0;

}

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

int main() {

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  bool ans = false;
  
  if (a-c <= d && c-a <= d) ans = true;
  else if (a-b <= d && b-a <= d) {
    if (b-c <= d && c-b <= d) ans = true;
  }
  
  cout << ((ans) ? "Yes" : "No") << endl;
  
}

Measured memory_bytes: 256
N = int(input())
C = {}
for _ in range(N):
    s = input().strip()
    if s not in C:
        C[s] = 0
    C[s] += 1
C = sorted(list(C.items()),key=lambda x:x[0])
C = sorted(C,key=lambda x:x[1],reverse=True)
k = C[0][1]
for i in range(len(C)):
    if C[i][1]==k:
        print(C[i][0])
    else:break

Measured memory_bytes: 113516
# python3
# -*- coding: utf-8 -*-
import sys
import math
import bisect
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
lmtx = lambda h: [list(map(int, lmis())) for _ in range(h)]
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
s, w = mis()

print('safe' if s>w else 'unsafe')


Measured memory_bytes: 10504
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            var c = cin.ReadStrArray(3);
            WriteLine($"{c[0][0]}{c[1][1]}{c[2][2]}");
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//階乗
ll fact(ll a) {
	int ans = 1;
	for (int i = 1; i <= a; i++) {
		ans *= i;
	}
	return ans;
}

//コンビネーション
ll combi(ll a, ll b) {
	return fact(a) / (fact(b) * fact(a - b));
}


int n, m, x;
vector<int>c;
vector<vector<int>>a;

int check(int bit) {
	vector<bool>book_state(n, false);
	rep(i, n) {
		if (bit & (1 << i)) {
			book_state[i] = true;
		}
	}

	int total_money = 0;
	vector<int>total_understand(m, 0);
	rep(i, book_state.size()) {
		if (book_state[i]) {
			total_money += c[i];
			rep(j, total_understand.size()) {
				total_understand[j] += a[i][j];
			}
		}
	}

	bool temp = true;
	rep(i, total_understand.size()) {
		if (total_understand[i] < x) {
			temp = false;
		}
	}

	if (temp) {
		return total_money;
	}
	else return -1;
}


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

	c.resize(n);
	a.resize(n);
	rep(i, n){
		cin >> c[i];
		a[i].resize(m);
		rep(j, m) {
			cin >> a[i][j];
		}
	}

	int ans = 100000000;
	bool pos = false;
	for (int bit = 0; bit < (1 << n); bit++) {
		int piyo = check(bit);
		if (piyo != -1) {
			ans = min(ans, piyo);
			pos = true;
		}
	}

	if (pos)cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 3596
# include<bits/stdc++.h>
# define int long long
# define mod 1000000007
using namespace std ;
const int N = 1000000;

int32_t main()
{  
   int a,b,c,d ; cin >> a >> b >> c >> d ;
   cout << max({a*c, a*d , b*d, b*c}) << endl ;
            
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define pb push_back
#define eb emplace_back

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

template<class T>
void dcomb(T n,T m, string s){
    if(n==0) cout << s << endl;
    else {
        for(T i=0; i<m; ++i){
            dcomb(n-1,m,s+to_string(i));
        }
    }
}

int  INF = 1e9+7;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    vector<int> dp(n);
    rep(i,n){
        dp[i] = INF;
    }
    dp[0] = 0;
    rep(i,n-1){
        rep(j,k){
            if(i+j+1>=n) break;
            chmin(dp[i+j+1],dp[i]+abs(h[i+j+1]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024