akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

// https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_2_F/review/3380631/face4/C++14
struct STlazy {
private:
    int n;
    vector<int> node, lazy;

public:
    STlazy() {
        n = (1 << 17) - 1;
        node.resize(2 * n - 1, INT_MAX);
        lazy.resize(2 * n - 1, -1);
    }

    void eval(int k, int l, int r) {
        if (lazy[k] == -1) return;
        node[k] = lazy[k];
        if (r - l > 1) lazy[2 * k + 1] = lazy[2 * k + 2] = lazy[k];
        lazy[k] = -1;
    }

    void update(int a, int b, int val, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] = val;
            eval(k, l, r);
            return;
        }
        update(a, b, val, 2 * k + 1, l, (l + r) / 2);
        update(a, b, val, 2 * k + 2, (l + r) / 2, r);
        node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return INT_MAX;
        eval(k, l, r);
        if (a <= l && r <= b) return node[k];
        int lx = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int rx = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(lx, rx);
    }
};


int main() {

    int n, q;
    cin >> n >> q;

    STlazy st;

    rep(i, q) {
        int query;
        cin >> query;

        if (query == 0) {
            int s, t, x;
            cin >> s >> t >> x;
            t++;
            st.update(s, t, x);
        } else if (query == 1) {
            int s, t;
            cin >> s >> t;
            t++;
            cout << st.query(s, t) << endl;
        }

    }

}



Measured memory_bytes: 4960
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2-(y2-y1) << " " << y2+(x2-x1) << " " << x1-(y2-y1) << " " << y1+(x2-x1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
long long ans = 0;
string S;
int s;

void dfs(int i, int b, long long sum) {
	if (i == s - 1) {
		sum += stoll(S.substr(b + 1, i - b));
		ans += sum;
		return;
	}
	else {
		dfs(i + 1, b, sum);

		sum += stoll(S.substr(b + 1, i - b));
		dfs(i + 1, i, sum);
	}
	return;
}
int main() {
	cin >> S;
	s = S.size();
	dfs(0, -1, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int R = in.nextInt();
            int G = in.nextInt();
            // G=(R+X)/2.0;
            int X = 2 * G - R;
            System.out.println(X);
        }
    }
}


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

int main() {

	int L;
	cin >> L;
	int san[21] = {};

	int saidai = 0;
	int henkazu = 0;
	int i = 0;
	while (L > 0) {
		i++;
		san[i] = L % 3;
		L /= 3;
		saidai = i;
		henkazu += san[i];
	}
	henkazu += 3 * (saidai - 1);
	cout << saidai + 1 << " " << henkazu << "\n";

	int suuji = 1;
	int ii = 1;
	for (ii; ii <= saidai - 1; ii++) {
		int beki = pow(3, ii - 1);
		cout << ii << " " << ii + 1 << " " << 0 << "\n";
		cout << ii << " " << ii + 1 << " " << beki << "\n";
		cout << ii << " " << ii + 1 << " " << beki * 2 << "\n";
		suuji *= 3;
	}
	if (san[ii] == 2) {
		int beki = pow(3, ii - 1);
		cout << ii << " " << ii + 1 << " " << 0 << "\n";
		cout << ii << " " << ii + 1 << " " << beki << "\n";
		suuji *= 2;
	}
	else if (san[ii] == 1) {
		cout << ii << " " << ii + 1 << " " << 0 << "\n";
	}
	for (int iii = saidai - 1; iii >= 1; iii--) {
		if (san[iii] == 2) {
			cout << iii << " " << saidai + 1 << " " << suuji << "\n";
			suuji += pow(3, iii - 1);
			cout << iii << " " << saidai + 1 << " " << suuji << "\n";
			suuji += pow(3, iii - 1);
		}
		else if (san[iii] == 1) {
			cout << iii << " " << saidai + 1 << " " << suuji << "\n";
			suuji += pow(3, iii - 1);
		}
	}
	Would you please return 0;
}

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

const int INF = (1<<28);
int n, m, mincost[100], cost[100][100];
bool used[100];

int prim(){
    int res = 0;
    while( true ){
        int v = -1;
        for(int i = 0; i < n; i++){
            if( !used[i] && (v == -1 || mincost[i] < mincost[v] ) ){
                v = i;
            }
        }
        if( v == -1 ) break;
        used[v] = true;
        res += mincost[v];
        for(int i = 0; i < n; i++){
            mincost[i] = min(mincost[i], cost[v][i]);
        }
    }
    return res;
}

int main(){
    while( scanf("%d", &n), n ){
        scanf("%d", &m);
        for(int i = 0; i < n; i++){
            mincost[i] = INF;
            for(int j = 0; j < n; j++){
                cost[i][j] = INF;
            }
            cost[i][i] = 0;
            used[i] = false;
        }
        mincost[0] = 0;
        for(int i = 0; i < m; i++){
            int a, b, d;
            scanf("%d,%d,%d", &a, &b, &d);
            cost[a][b] = d/100-1;
            cost[b][a] = d/100-1;
        }
        printf("%d\n", prim());
    }
    return 0;
}

Measured memory_bytes: 1068
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final PrintStream so = System.out;
    static final Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        int N = ni();
        int c4 = 0;
        int c2 = 0;
        int c0 = 0;
        for (int i = 0; i < N; i++) {
            int a = ni();
            if (a % 4 == 0)
                c4++;
            else if (a % 2 == 0)
                c2++;
            else
                c0++;
        }
        if (c2 > 0) {
            so.println(c0 <= c4 ? "Yes" : "No");
        } else {
            so.println(c0 <= c4 + 1 ? "Yes" : "No");
        }
    }
    
    static int ni() {
        return sc.nextInt();
    }
    
    static long nl() {
        return sc.nextLong();
    }

    static char[] nsToChars() {
        return sc.next().toCharArray();
    }
}


Measured memory_bytes: 47296
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int h = hw[0];
			int w = hw[1];

			var s = new string[h + 2];
			s[0] = "";
			s[h + 1] = "";
			for (int i = 0; i < w + 2; i++) {
				s[0] += "-";
				s[h + 1] += "-";
			}
			for (int i = 0; i < h; i++) {
				s[i + 1] = "-" + Console.ReadLine() + "-";
			}

			var numss = new int[h, w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (s[i + 1][j + 1] == '#') {
						numss[i, j] = -1;
					} else {
						int cnt = 0;
						for (int ii = -1; ii <= 1; ii++) {
							for (int jj = -1; jj <= 1; jj++) {
								if (ii == 0 && jj == 0) {
									continue;
								}

								if (s[i + 1 + ii][j + 1 + jj] == '#') {
									++cnt;
								}
							}
						}

						numss[i, j] = cnt;
					}
				}
			}

			var sb = new StringBuilder();
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					sb.Append(numss[i, j] == -1 ? "#" : numss[i, j].ToString());
				}

				sb.AppendLine("");
			}

			Console.WriteLine(sb.ToString());
		}
	}
}

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

int main(){
    ll n;cin>>n;
    vl a(n-1);rep(i,n-1){cin>>a.at(i);a.at(i)--;}
    vl b(n);

    rep(i,n-1){b.at(a.at(i))++;}

    rep(i,n)cout<<b.at(i)<<endl;


    
}

Measured memory_bytes: 6428
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
using namespace std;
int main(){
    string s;
    cin >> s;
    rep(i, s.size()){
        if(i%2 == 0){
            if(s[i] == 'L'){
                cout << "No";
                return 0;
            }
        }
        else{
                        if(s[i] == 'R'){
                cout << "No";
                return 0;
            }

        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
main = do
    n <- getInt
    printTime $ toTime n
    putStrLn ""

getInt :: IO (Int)
getInt = do
    str <- getLine
    return $ read str

printTime :: (Int, Int, Int)-> IO ()
printTime (h, m, s) = putStr $ show h ++ ':':show m ++ ':':show s

toTime :: Int -> (Int, Int, Int)
toTime n = (h, m ,s)
    where
        h = n　`div ` (60 * 60)
        m = (n `div` 60) `mod` 60
        s = n `mod` 60


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int N;
long long int A[100005], K;

long long int gcd(long long int a, long long int b) {

	if (a < b) {
		return gcd(b, a);
	}

	if (b == 0) { return a; }

	return gcd(b, a%b);

}

int main(void) {

	cin >> N >> K;

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

	long long int num = A[1];

	for (int i = 2; i <= N; i++) {
		num = gcd(num, A[i]);
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		if (A[i] >= K && (A[i] - K) % num == 0) { ans = 1; }

	}


	if (ans == 1) { cout << "POSSIBLE" << endl; }
	else { cout << "IMPOSSIBLE" << endl; }

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,a[200100],k;
int main()
{
	cin>>k>>n;
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	int ans=0;
	for(int i=2;i<=n;i++) ans=max(ans,a[i]-a[i-1]);
	ans=max(ans,a[1]+k-a[n]);
	cout<<k-ans<<endl;
}

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

#define llint long long int

using namespace std;

int main(){
    llint X;

    cin >> X;

    llint sum = 100;
    llint ans = 0;

    while(true){
        ans ++;

        sum += sum / 100;

        if(sum >= X){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
int x[100010];
int main()
{
    int a;
    __builtin_scanf("%d", &a);
    x[a]++;
    auto f=[](int n) { return n%2 ? 3*n+1 : n/2; };
    for(int i=2; ; ++i) {
        int t=f(a);
        if (x[t]++) return !__builtin_printf("%d\n", i);
        a=t;
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

bool isPerfectSquare(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is an integer 
  return ((sr - floor(sr)) == 0); 
} 

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

    ll a[n];

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

    ll ans = 0;
    sort(a, a+n);

    ans += a[n/2]-a[n/2-1];

    cout << ans << "\n";
}




Measured memory_bytes: 6784
# -*- coding: utf-8 -*-
from itertools import product

D, G = map(int, input().split())
pc_table = [tuple(map(int, input().split())) for _ in range(D)]

bit_table = list(product([0, 1], repeat=D))
cnts = []
for bits in bit_table:
    g = sum([
        pc_table[i][1] + 100 * (i + 1) * pc_table[i][0]
        for i, bit in enumerate(bits) if bit
    ])
    cnt = sum([pc_table[i][0] for i, bit in enumerate(bits) if bit])

    if g >= G:
        cnts.append(cnt)

    else:
        max_p = max([i for i, bit in enumerate(bits) if not bit])
        for _ in range(pc_table[max_p][0]):
            g += 100 * (max_p + 1)
            cnt += 1
            if g >= G:
                cnts.append(cnt)
                break

print(min(cnts))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
 
  int main(){
   lint n,m;
   lint x[100005];
   fill(x,x+100005,0);
   cin>>n>>m;
   rep(i,m){
       lint l,r;
       cin>>l>>r;
       x[l]++;
       x[r+1]--;
   }
   rep(i,100004){
       x[i+1]+=x[i];
   }
   lint count=0;
   rep(i,100005)if(x[i]==m)count++;
   cout<<count;
  }
  
     


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int MAX = 100;

main(){
  int N, s, t, ps, pt;
  int R[MAX];
  pair<int, int> S[MAX];
  cin >> N;
  rep(i, N) { S[i].first = 0; S[i].second = i; }
  rep(i, N*(N-1)/2){
    cin >> s >> t >> ps >> pt; s--; t--; // to 0 base
    if ( ps > pt ) S[s].first += 3;
    else if ( ps < pt ) S[t].first += 3;
    else { S[t].first++; S[s].first++; }
  }
  
  sort(S, S + N);
  reverse(S, S + N);

  int r = 1;
  R[S[0].second] = r;
  REP(i, 1, N){
    if ( S[i].first != S[i-1].first ) r = (i+1);
    R[S[i].second] = r;
  }
  
  rep(i, N) cout << R[i] << endl;
}

Measured memory_bytes: 1164
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    a = [LI_() for _ in range(m)]
    ss = [set() for _ in range(n)]
    for b,c in a:
        ss[b].add(c)
        ss[c].add(b)
    ts = [set(list(range(n))) - set([_]) for _ in range(n)]
    for i in range(n):
        ts[i] -= ss[i]

    d = []
    u = set()
    for i in range(n):
        if i in u:
            continue
        ab = set([i])
        nb = set([i])
        ac = set()
        nc = set()
        f = True
        while f:
            f = False
            k = set()
            nc = set()
            for j in nb:
                nc |= ts[j]
            nc -= ac
            ac |= nc
            nb = set()
            for j in nc:
                nb |= ts[j]
            nb -= ab
            ab |= nb
            if nb:
                f = True
        if ab & ac:
            return -1
        d.append((len(ab),len(ac)))
        u |= ab
        u |= ac
    r = set([0])
    for b,c in d:
        t = set()
        for k in r:
            t.add(k+b)
            t.add(k+c)
        r = t
    rr = inf
    for t in r:
        nt = n - t
        if t == 0 or nt == 0:
            continue
        tr = t * (t-1) // 2
        tr += nt * (nt-1) // 2
        if rr > tr:
            rr = tr
    return rr


print(main())



Measured memory_bytes: 100236
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
typedef long long int ll;
typedef vector<int> vint;
const ll LINF = 9000000000000000000ll;
const int INF = 2000000000;
const ll MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vint x(m);
    rep(i, m) cin >> x[i];

    if (n >= m) {
        puts("0");
        return 0;
    }

    sort(all(x));
    vint dist(m-1);
    rep(i, m-1) dist[i] = x[i+1] - x[i];
    sort(all(dist));
    int ans = 0;
    rep(i, m-n) ans += dist[i];

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

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		sc.close();
		String a = "Yes";
		for(int i=0; i<N; i++) {
			if(S.charAt(i) != S.charAt(N-i-1))
				a = "No";
		}
		for(int i=0; i<(N-1)/2; i++) {
			if(S.charAt(i) != S.charAt((N-1)/2-i-1))
				a = "No";
		}
		for(int i=(N+3)/2; i<N; i++) {
			if(S.charAt(i) != S.charAt(N-i-1))
				a = "No";
		}

		System.out.println(a);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
 
using namespace std;
typedef long long ll;
typedef pair<int,int> pi; 

const int N=100005;
vector<int>prime;
inline bool check(int x){for(int p=2;p*p<=x;p++)if(x%p==0)return false;return true;}
inline ll dcube(ll x){for(int p:prime){ll u=(ll)p*p*p;if(u>x)break;while(x%u==0)x/=u;}return x;}
inline ll squ(ll x){ll r=sqrt(x)-1;while(r*r<x)r++;return r;}
inline ll gop(ll x){
	ll ret=1;int now=0;
	for(int p:prime){
		ll u=(ll)p*p*p;
		if(u>x)break;
		for(now=0;x%p==0;now--)x/=p;
		for(now=(now%3+3)%3;now;now--)ret*=p;
	}
	ll s=squ(x);
	if(s*s==x)x/=s*s,ret*=s;
	return ret*x*x;
}

ll b[N],a[N];
map<ll,pi>cnum;
int n,ans;

int main(){
	for(int i=2;i<=2333;i++)if(check(i))prime.pb(i);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]=dcube(a[i]),b[i]=gop(a[i]);
		cnum[a[i]].fi++,cnum[b[i]].se++;
	}
	if(cnum.find(1)!=cnum.end())cnum[1]={2,2};
	for(auto v:cnum)ans+=max(v.se.fi,v.se.se);
	printf("%d\n",ans>>1);
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll m,n,x = -1,t=0;

    cin>>n;

    for(int i = 1; i <= 1e7; i++)
    {
        t = (t*10+7)%n;
        if(t==0)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<x<<endl;
}


Measured memory_bytes: 3640
package main

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

var n, cnt, visitAll int
var x, y []float64
var total float64

func dfs(i, visit int, path float64) {
	visit += 1 << uint(i)
	if visit == visitAll {
		cnt++
		total += path
	}

	for j := range x {
		if visit&(1<<uint(j)) != 0 {
			continue
		}
		d := math.Sqrt(math.Pow(x[i]-x[j], 2) + math.Pow(y[i]-y[j], 2))
		dfs(j, visit, path+d)
	}
}

func main() {
	n := readInt()

	x = make([]float64, n)
	y = make([]float64, n)
	for i := range x {
		x[i], y[i] = readFloat64(), readFloat64()
	}

	for i := range x {
		visitAll += 1 << uint(i)
	}

	for i := range x {
		dfs(i, 0, 0)
	}
	fmt.Println(total / float64(cnt))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a,b,c,d;
    int x=15;
    scanf("%d %d",&a,&b);
    c=a+b;
    d=a*b;
    if(c==x)
    {
        printf("+");
    }
    else if(d==x)
    {
        printf("*");
    }
    else
    {
        printf("x");
    }
    return 0;













}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;



int main(){
    int N;
    cin >> N;
    cout << N*2/__gcd(N,2) << endl;
    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N, K;
ll A[200005];
vector<ll> B[200005];
bool U[200005];

vector<ll> solve(ll n)
{
    stack<ll> s;
    memset(U, 0, sizeof(U));
    FOR(i, N, n)
    {
        ll m = A[i];
        if (!U[m])
        {
            s.push(m);
            U[m] = true;
            continue;
        }

        while (!s.empty())
        {
            ll t = s.top();
            s.pop();
            U[t] = false;
            if (t == m)
                break;
        }
    }

    vector<ll> v;
    while (!s.empty())
    {
        ll t = s.top();
        s.pop();
        v.push_back(t);
    }
    return v;
}

int main()
{
    cin >> N >> K;
    REP(i, N)
    {
        cin >> A[i];
        B[A[i]].push_back(i);
    }

    ll loop = 1;
    ll index = 0;
    while (true)
    {
        ll t = A[index];
        ll i = lower_bound(B[t].begin(), B[t].end(), index) - B[t].begin();
        i = (i + 1) % B[t].size();
        ll nxt = (B[t][i] + 1) % N;

        if (index >= nxt - 1)
        {
            if (nxt != 0 || index == N - 1)
                loop++;
        }
        //cout << index << "->" << nxt << " " << loop << endl;
        index = nxt;
        if (index == 0)
            break;
    }

    ll n = K % loop;
    index = 0;
    loop = 1;
    while (true)
    {
        if (loop >= n)
            break;
        ll t = A[index];
        ll i = lower_bound(B[t].begin(), B[t].end(), index) - B[t].begin();
        i = (i + 1) % B[t].size();
        ll nxt = (B[t][i] + 1) % N;

        if (index >= nxt - 1)
            loop++;
        index = nxt;
    }

    auto v = solve(index);

    if (n > 0)
    {
        REP(i, v.size())
        {
            cout << v[v.size() - 1 - i] << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 17044
#include <bits/stdc++.h>
#define ff first
#define ss second
#define vi vector<int>
#define pb emplace_back
#define ll long long int
#define vll vector<long long int>
#define vpi vector<pair<ll,ll>>
#define bit(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a , 0 ,sizeof a)
#define rep(i,n) for(int i=0 ; i<n ; ++i)
#define deb(x) cout << #x << " - " << x << endl;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9 + 7;
const ll INF = 10000000000000000;
const ll MAX_N = 1e5 + 7;
 
using namespace std;

int main(){
    IOS;
    ll n; cin>>n;
    ll cur=100,cnt=0;
    while(1){
        if(cur>=n) break;
        cur += cur/100;
        cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3688
N = int(input())
info = [list(map(int,input().split())) for _ in range(N)]
info.sort(key=lambda x:x[2])

x,y,h = info[-1]

for cx in range(101):
  for cy in range(101):
    H = h+abs(x-cx)+abs(y-cy)
    if all(h_ == max(H-abs(x_-cx)-abs(y_-cy),0) for x_,y_,h_ in info):
      print(cx, cy, H)
      exit()


    
  





Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  set<int> s;
  int n;
  cin>>n;
  while(n--){
    int a;
    cin>>a;
    if(s.count(a)){
      s.erase(a);
    }else{
      s.insert(a);
    }
  }
  cout<<s.size()<<endl;
  return 0;
}


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

#define    ll     long long int

const int N = 200005;
pair<int, int> ara[N];
int order[N];
int araa[N];

int compare(pair<int, int> a, pair<int, int> b)
{
    return a.second < b.second;
}

int main( )
{
    int n, i, j, k, l;
    cin >> n;
    l = n / 2;
    for (i = 0; i < n; i++) {
        cin >> ara[i].first;
        ara[i].second = i;
    }
    sort(ara, ara + n);
    for (i = 0; i < n; i++) {
        order[ara[i].second] = i;
        araa[i] = ara[i].first;
    }
    sort(ara, ara + n, compare);
    for (i = 0; i < n; i++) {
        j = order[ara[i].second];
        if (j >= l) {
            cout << araa[l - 1];
        }
        else {
            cout << araa[l];
        }
        cout << '\n';
    }
    return 0;
}

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

using i64 = long long int;

int imos[100005]={0};

int main(){
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        if(a > b)swap(a, b);
        imos[a-1]++;
        imos[b-1]--;
    }

    int acc = 0;
    bool ok = true;
    for(int i=0;i<m;++i){
        acc += imos[i];
        if(acc%2){
            ok = false;
            break;
        }
    }

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 640
from sys  import stdin,stdout

st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')

n,k=mp()
l=li()
dp=[INF for i in range(n)]
dp[0]=0

for i in range(n):

    for j in range(i+1,min(i+k+1,n)):

        dp[j]=min(abs(l[i]-l[j])+dp[i],dp[j])

print(dp[-1])

        


Measured memory_bytes: 90960
using System;
using System.Collections.Generic;

class Q
{
	static void Main()
	{
		Func<int[]> read = () => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		var n = int.Parse(Console.ReadLine());
		var h = read();
		var a = read();

		var l = new List<int>(n) { 0 };
		var dp = new long[n + 1];
		for (int i = 0; i < n; i++)
		{
			var li = ~l.BinarySearch(h[i]);
			var v = dp[l[li - 1]] + a[i];
			while (li < l.Count && dp[l[li]] <= v) l.RemoveAt(li);
			l.Insert(li, h[i]);
			dp[h[i]] = v;
		}
		Console.WriteLine(dp[l[l.Count - 1]]);
	}
}


Measured memory_bytes: 47440
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
static const double pi=3.141592653589793238462643383279;

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

int main(){
    int a,b;
    cin >> a >> b;
    vector<int> A(1000);
    A[1]=1;
    for(int i=2;i<1000;i++){
        A[i]=A[i-1]+i;
    }
    int diff=abs(a-b);
    int ans=A[diff]-max(a,b);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a, b, c, d, e, k;
int main()
{
	cin >> a >> b >> c >> d >> e >> k;
	if(k >= e - a){
		cout << "Yay!";
	}else {
		cout << ":(";
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
#n,m=map(int,input().split())
#t=int(input())
#pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
res=0
for i in range(n):
    s=list(input())
    s="".join(sorted(s))
    count=dic.get(s,0)
    if count>0:
        res+=count
    dic[s]=count+1
print(res)


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int sum=0;
  for (int i = 0; i < K; i++) {
    sum += vec.at(i);
  }
  cout << sum << endl;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int tmp;
    int ans = 0;
    // aで聞ける
    // b: 所持金
    // c: 最大回数
    if(a <= b){
        tmp = b / a;
        if(tmp >= c){
            ans = c;
        }else{
            ans = tmp;
        }
    }
    cout << ans << endl;
}

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

class abc125_C
{
    /*
    learned :
     https://qiita.com/drken/items/56a6b68edef8fc605821
     http://drken1215.hatenablog.com/entry/2019/04/27/224100_1

     example:
        QAs: 6 12 16 8
        left: 0(init) 6(6) 6(6,12) 2(6,12,16) 2(6,12,16,8) 
        right: 2(8,16,12,6) 4(8,16,12) 8(8,16) 8(8) 0(init)
        mix l[i],r[i+1]: 4(0,4) 2(6,8) 2(6,8) 2(2,8) 2(2,8)
    */
    
    static void Main(string[] args)
    {
        var QN = readInt();
        var QAs = readLongs();

        var left = new long[QN+1];
        left[0] = 0;
        for(var i=0; i<QN; i++) {
            left[i+1] = GCD(left[i], QAs[i]);
        }

        var right = new long[QN+1];
        right[QN] = 0;
        for(var i=QN-1; i>=0; i--) {
            right[i] = GCD(right[i+1], QAs[i]);
        }

        var max = 0L;
        for(var i=0; i<QN; i++) {
            var v = GCD(left[i], right[i+1]);
            max = Math.Max(max, v);
        }

        Console.WriteLine(max);
    }

    static long GCD(long a, long b) {
        if(b == 0) return a;
        return GCD(b, a%b);
    }

    static int readInt() { return int.Parse(Console.ReadLine()); }

    static int[] readInts() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); }

    static long readLong() { return long.Parse(Console.ReadLine()); }

    static long[] readLongs() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); }

}

Measured memory_bytes: 27996
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] x = new int[N];
        int sum = 0;

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            if((i+1)%2 != 0){
                sum += A[i];
            }else{
                sum -= A[i];
            }
        }
        x[0] = sum;

        for(int i=1; i<N; i++){
            x[i] = 2*A[i-1] - x[i-1];
        }

        for(int i=0; i<N; i++){
            System.out.println(x[i]);
        }
    }
}

Measured memory_bytes: 66168
#include<bits/stdc++.h>
using namespace std;
int l,r,d,sum;
int n,f[100005];
int main(){
    cin>>n;
    for(int i=1;i<=100;i++)
        for(int j=1;j<=100;j++)
            for(int k=1;k<=100;k++){
                  int x=i*i+j*j+k*k+i*j+i*k+j*k;
                  if(x<=n)f[x]++;
            }
    for(int i=1;i<=n;i++)cout<<f[i]<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;


ll mod_power(ll base , ll up , ll mod)
{
	ll val = 1;
	while(up)
	{
		if(up%2)
			val = (val * base)%mod;
		base = (base * base)%mod;	
		up/=2;
	}	
	
	return val;
}

ll ncr(ll n , ll r)
{
	ll ans = 1;
	for(int i = 1;i<=r;i++)
	{
		ans = (ans * mod_power(i , MOD-2 , MOD))%MOD;
		ans = (ans * (n-i+1))%MOD;
	}
	
	return ans;
}

int main()
{
	ll sum;cin>>sum;
	ll ans = 0;
	
	for(int i = 1;i<=sum/3;i++)
	{
		ll k = sum - i*3;
		ans = (ans + ncr(i+k-1 , i-1))%MOD;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    vector<int> C(N);
    vector<int> V(N);

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

    int ans = 0;
    for(int i=0; i < N; i++) {
        int tmp = V.at(i) - C.at(i);
        if(tmp > 0) {
            ans += tmp;
        }
    }

    cout << ans << endl;

    return 0;
}



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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

vector<int> G[MAX];
int dp[MAX];

int dfs(int v) {
    if (0 <= dp[v]) return dp[v];
    int res = -1;
    for (int u : G[v]) {
        chmax(res, dfs(u));
    }
    if (res < 0) return dp[v] = 0;
    return dp[v] = res + 1;
}

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

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    rep(i, N) dp[i] = -1;
    rep(i, N) {
        if (dp[i] < 0) dfs(i);
    }

    int ans = 0;
    rep(i, N) chmax(ans, dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 10496
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int P, Q, R;
    cin >> P >> Q >> R;
    int Res = P+Q;
    int Tmp = Q+R;
    if (Tmp < Res) Res = Tmp;
    Tmp = R+P;
    if (Tmp < Res) Res = Tmp;
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef vector<vi> vvi;


int main() {
	int n, x;
	cin >> n >> x;
	vi a(n);
	rep(i, n) cin >> a[i];

	ll ans = 0;

	if (a[0] > x) {
		ans += a[0];
		ans -= x;
		a[0] = x;
	}

	rep(i, n - 1) 	if (a[i] + a[i + 1] > x) {
		ans += a[i];
		ans += a[i + 1];
		ans -= x;
		a[i + 1] = x - a[i];
	}

	cout << ans << endl;
}

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

int main() {
  int N, A;
  cin >> N;  //支払い金額
  cin >> A;  //1円硬貨の枚数

  if(N % 500 <= A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
int main() {
    int a,b,c=0;cin>>a>>b;
    if(b==100)c+=a*1000;
    else if(b>=10)c+=a*100;
    else c+=a*10;
    c+=b;
    bool bb=0;
    for(int i=1;i*i<100200;++i){
        if(i*i==c)bb=1;
    }
    cout<<(bb?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
def abc144_e():
    import numpy as np

    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)
    A = np.sort(A)
    F = np.sort(F)[::-1]

    low = -1
    up = 10**12
    while up - low > 1:
        v = (up + low) // 2
        x = A - v // F
        if x[x > 0].sum() > K:
            low = v
        else:
            up = v
    print(up)

if __name__ == '__main__':
    abc144_e()

Measured memory_bytes: 51896
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	if (k == 1) {
		cout << "0" << endl;
	}
	else {
		cout << n-k << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			long[] sum = new long[n + 1];
			sum[0] = 0L;
			IntStream.rangeClosed(1, n).forEach(i -> sum[i] = sum[i - 1] + scanner.nextInt());
			// 左と右の配列のそれぞれ区切ったところ
			int left = 1, right = 3;
			long answer = Long.MAX_VALUE;
			for (int i = 2; i <= n - 2; i++) {
				while ((left < i - 1) && (Math.abs(sum[left] - (sum[i] - sum[left])) > Math
						.abs(sum[left + 1] - (sum[i] - sum[left + 1])))) {
					left++;
				}
				while ((right < n - 1) && (Math.abs((sum[right] - sum[i]) - (sum[n] - sum[right])) > Math
						.abs((sum[right + 1] - sum[i]) - (sum[n] - sum[right + 1])))) {
					right++;
				}
				answer = Math.min(answer,
						Math.abs(max(sum[left], sum[i] - sum[left], sum[right] - sum[i], sum[n] - sum[right])
								- min(sum[left], sum[i] - sum[left], sum[right] - sum[i], sum[n] - sum[right])));
			}
			System.out.println(answer);
		}
	}

	/**
	 * 複数のlongの最大値を取得する
	 * 
	 * @param longs 複数のlong
	 * @return 複数のlongの最大値
	 */
	private static long max(long... longs) {
		if (null != longs) {
			return Arrays.stream(longs).max().getAsLong();
		}
		return 0L;
	}

	/**
	 * 複数のlongの最小値を取得する
	 * 
	 * @param longs 複数のlong
	 * @return 複数のlongの最小値
	 */
	private static long min(long... longs) {
		if (null != longs) {
			return Arrays.stream(longs).min().getAsLong();
		}
		return 0L;
	}
}


Measured memory_bytes: 62524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

string s;
int a[258];

int main(){

cin >> s;
rep(i, 0, 2){
a[s[i]]++;
}
rep(i, 97, 99){
if(a[i])continue;
else return 0*printf("No");
}
cout << "Yes";


return 0;}


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

const int H = 1005, W = 1005, MOD = 1000000007;

int h, w, dp[H][W];
char board[H][W];

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> h >> w;
    dp[0][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> board[i][j];
            if(board[i][j] == '.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }
    cout << dp[h][w] << "\n";
}

Measured memory_bytes: 5248