akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    int g;
    g = a+b*5+c*10+d*50+e*100+f*500;
    if(g>=1000){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}



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

int main(){
  int n,m,a;
  cin >> n >> m;
  vector<int> v(n,0);
  r(i,2*m){
    cin >> a;
    v.at(a-1)++;
  }
  r(i,n){
    cout << v.at(i)<<endl;
  }
}

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



int main(){
    Shazam;
    int n; cin>>n;
    vector<int> a(n);
    for(int &i : a) cin>>i;
    vector<int> st;
    st.push_back(0);
    int ans = -1;
    for(int i =0 ; i < n; i++){
        if(a[i]==st.back()+1){
            st.push_back(a[i]);
        }
        ans = st.size()-1;
    }
    if(ans == 0){
        cout<<-1<<endl;
        return 0;
    }
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 5068
// #include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <fstream>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
// #include <unordered_map>
#include <set>
#include <utility>
#include <bitset>
#include <limits>
#include <climits>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())


const ll INF = 1000000000000000000LL;// 1e18


template <typename T>
void dij1(int nV, vector<vector<pair<int,T>>>& adjacent, vector<T>& d, int start) {
	// nV: |V|
	d.assign(nV, INF);
	d[start] = 0;
	vector<int> prev(nV, -1);

	priority_queue<pair<T, int>> Q;
	Q.push(make_pair(0, start));

	vector<bool> visited(nV, false);

	while (!Q.empty()) {
		T du = -Q.top().first;
        int u = Q.top().second; Q.pop();
		if (visited[u]) continue;
		visited[u] = true;

		int c = adjacent[u].size();
		for (int i=0; i<c; ++i) {
			int v = adjacent[u][i].first;
			T distance = adjacent[u][i].second;
			T alt = du + distance;
			if (d[v] > alt) {
				d[v] = alt;
				prev[v] = u;
				Q.push(make_pair(-alt, v));
			}
		}
	}
}

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

    vector<vector<pair<int,ll>>> adj(N);
    rep(i, N-1) {
        int ai,bi; ll ci; cin >> ai >> bi >> ci;
        --ai; --bi;
        adj[ai].pb(make_pair(bi, ci));
        adj[bi].pb(make_pair(ai, ci));
    }
    int Q, K; cin >> Q >> K;
    --K;

    vector<ll> d(N, INF);
    dij1(N, adj, d, K);
    // cout << d << endl;

    rep(j, Q) {
        int xi,yi; cin >> xi >> yi;
        --xi; --yi;
        ll ans = d[xi] + d[yi];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 11504
#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 = 1001001001;

int main(){
    int n;
    cin >> n;
    
    vector<int> p(n);
    rep(i,n) cin >> p.at(i);
    
    int mn = 0, ans = 0;
    
    rep(i,n) {
        if(i == 0 || p.at(i) < mn) {
            ans++;
            mn = p.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
#include<stdio.h>
int main()
{
    int x,a,b;
    int s1,s2;
    scanf("%d%d%d",&x,&a,&b);
    if (a>x) s1=a-x;
    else s1=x-a;
    if (b>x) s2=b-x;
    else s2=x-b;
    if (s1>s2) printf("B\n");
    else printf("A\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1000000000000000LL
using namespace std;
long long n,W,dp[105][100005];
int main(){
	scanf("%lld%lld",&n,&W);
	for (int i=0;i<=n;i++){
		dp[i][0] = 0;
		for (int j=1;j<100005;j++) 
			dp[i][j] = INF;
	}
	
	for (int i=1;i<=n;i++){
		long long  w,v;
		scanf("%lld%lld",&w,&v);
		for (int j=1;j<100005;j++)  {
			if (dp[i-1][j]!=INF) dp[i][j] = dp[i-1][j];
			if (j>=v && dp[i-1][j-v]!=INF && dp[i-1][j-v]+w<dp[i][j]) dp[i][j]= dp[i-1][j-v]+w;
		}
	}
	long long max = 0;
	for (int j=1;j<100005;j++)
		if (dp[n][j]<=W) max = j;
	printf("%lld",max);
	return 0;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const int N = 101010;
using Pi = P<int>;
VV e(N);
VV dp(N, V(3, upper));
void dijkstra(int s) {
	priority_queue<Pi, VE<Pi>, greater<Pi>>  pq;
	pq.push(make_pair(0, s));
	while (!pq.empty()) {
		int d = pq.top().first, p = pq.top().second;
		pq.pop();
		if (dp[p][d % 3] < d) continue;
		rep(i, e[p].size()) {
			int np = e[p][i];
			if (chmin(dp[np][(d + 1) % 3], dp[p][d % 3] + 1)) {
				pq.push(make_pair(d + 1, np));
			}
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		e[x].push_back(y);
	}
	int s, t;
	cin >> s >> t;
	s--, t--;
	dp[s][0] = 0;
	dijkstra(s);
	if (dp[t][0] == upper) cout << -1 << endl;
	else cout << dp[t][0] / 3 << endl;
	return 0;
}

Measured memory_bytes: 14292
def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()

    Alice = 0
    Bob = 0
    j = 0

    for i in range(N - 1, -1, -1):
        if j % 2 == 0:
            Alice += a[i]
        else:
            Bob += a[i]
        j += 1

    print(Alice - Bob)

main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
#define CoutV(vec)     \
    for (auto v : vec) \
        Cout(v);
#define CoutVV(vecvec)      \
    for (auto vec : vecvec) \
        CoutV(vec);

using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;
//int t[10010];

int main()
{

    int n;
    cin >> n;

    vector<string> s(n);
    map<string, int> mp;
    REP(i, n)
    {
        string w;
        cin >> w;
        mp[w] = 0;
        s[i] = w;
    }

    bool ok;
    for (int i = 0; i < n - 1; i++)
    {
        ok = false;

        if (mp[s[i]] == 0 && mp[s[i + 1]] == 0)
        {
            if (s[i].back() == s[i + 1].front())
            {
                mp[s[i]]++;
                ok = true;
            }
        }
        if (!ok)
            break;
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
vector<vector<int>> Tree(MAXN);
map<pair<int, int>, int> Colors;
int K = 0;

void dfs(int curNode, int prevNode, int prevColor)
{
  vector<int> nextNodes = Tree.at(curNode);
  int nextColor = 1;
  for (int i = 0; i < nextNodes.size(); i++)
  {
    int nextNode = nextNodes.at(i);
    if (nextNode == prevNode)
      continue;
    if (nextColor == prevColor)
      nextColor++;
    int a = curNode, b = nextNode;
    if (a > b)
      swap(a, b);
    Colors[make_pair(a, b)] = nextColor;
    dfs(nextNode, curNode, nextColor);
    K = max(K, nextColor);
    nextColor++;
  }
}

int main()
{
  int N, a, b;
  cin >> N;
  vector<pair<int, int>> vp;
  for (int i = 0; i < N - 1; i++)
  {
    cin >> a >> b;
    if (a > b)
      swap(a, b);
    Tree.at(a).push_back(b);
    Tree.at(b).push_back(a);
    vp.push_back(make_pair(a, b));
  }
  dfs(1, 0, 0);
  cout << K << endl;
  for (int i = 0; i < N - 1; i++)
  {
    tie(a, b) = vp.at(i);
    cout << Colors.at(make_pair(a, b)) << endl;
  }
}

Measured memory_bytes: 16760
def main():
    n, jibun, aite = map(int, input().split())
    data = list(map(int, input().split()))
    if n == 1:
        print(abs(aite - data[-1]))
    else:
        print(max(abs(aite - data[-1]), abs(data[-1] - data[-2])))



if __name__ == '__main__':
    main()

Measured memory_bytes: 38640
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

vector<ll> factor(ll x){
    vector<ll> ans;
    for(ll i = 2; i*i <= x; ++i){
        if(x%i==0){
            ans.push_back(i);
            if(i!=x/i) ans.push_back(x/i);
        } 
    }
    ans.push_back(x);
    return ans;
}

void solve(){
    ll n;
    cin >> n;
    if(n==2){
        cout << "1\n";
    }
    else{
        vector<ll> f1 = factor(n);
        vector<ll> f2 = factor(n-1);

        int ans = 0;
        for(ll i : f1){
            ll t = n;
            while(t%i==0){
                t/=i;
            }
            if(t%i==1) ++ans;
        }
        ans += (int)f2.size();
        cout << ans << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

using namespace std;

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();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n,m;
int d[35][35];
int c[35][35];

double dist[35][35][35];

typedef tuple<double,int,int,int> state;

double dijkstra(int src,int dest){
	rep(i,35)rep(j,35)rep(k,35) dist[i][j][k]=inf;
	rep(i,35) dist[src][i][0]=0.0;

	priority_queue<state,vector<state>,greater<state>> q;

	state init(0.0,src,-1,0);
	q.push(init);

	while(!q.empty()){
		state cur=q.top();q.pop();
		double distance;
		int v,p,s;
		tie(distance,v,p,s)=cur;
		if(p>=0&&dist[v][p][s]<distance) continue;
		rep(i,n){
			if(i==p||d[v][i]==-1)
				continue;
			for(int j=-1;j<=1;++j){
				int nv=i;
				int ns=s+j;
				if(ns<=0||c[v][i]<ns) continue;
				double nd=distance+(1.0*d[v][i]/ns);
				if(dist[nv][v][ns]>nd){
					dist[nv][v][ns]=nd;
					state next(nd,nv,v,ns);
					q.push(next);
				}
			}
		}
	}
	double res=inf;
	rep(i,n) res=min(res,dist[dest][i][1]);
	return (res>=inf)?-1:res;
}

int main(void){
	while(cin >> n >> m){
		if(n==0)
			break;
		clr(d,-1);
		int s,g;
		cin >> s >> g;
		s--,g--;
		rep(i,m){
			int x,y,dd,cc;
			cin >> x >> y >> dd >> cc;
			x--,y--;
			d[x][y]=d[y][x]=dd;
			c[x][y]=c[y][x]=cc;
		}
		cout.precision(9);
		double ans=dijkstra(s,g);
		if(ans==-1.0)
			cout << "unreachable" << endl;
		else
			cout << fixed << ans << endl;
	}
	return 0;
}

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

void dfs(int y, int x, vector<vector<int> > &C, vector<vector<int> > &used) {
    used.at(y).at(x) = 1;
    int H = C.size();
    int W = C.at(0).size();
    for (int dy = -1; dy <= 1; ++dy) {
        for (int dx = -1; dx <= 1; ++dx) {
            int ny = y + dy;
            int nx = x + dx;
            if (ny < 0 || H <= ny) continue;
            if (nx < 0 || W <= nx) continue;
            if (used.at(ny).at(nx)) continue;
            if (C.at(ny).at(nx) == 0) continue;
            dfs(ny, nx, C, used);
        }
    }
}

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

    while (true) {
        int W, H;
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        vector<vector<int> > C(H, vector<int>(W));
        vector<vector<int> > used(H, vector<int>(W, 0));
        for (int y = 0; y < H; ++y) {
            for (int x = 0; x < W; ++x) {
                cin >> C.at(y).at(x);
            }
        }

        int ans = 0;
        for (int y = 0; y < H; ++y) {
            for (int x = 0; x < W; ++x) {
                if (C.at(y).at(x) == 1 && used.at(y).at(x) == 0) {
                    ans++;
                    dfs(y, x, C, used);
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3464
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){	
	long long a;
	cin>>a;
	int b=a;
	long long sum=0;
	while(a!=0){
		sum=a%10+sum;
		a=a/10;
	}
	if(b%sum==0){
		cout<<"Yes";
	}
	else{
		cout<<"No"; 
	}
    return 0;
} 

Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n,w;
vector<pair<int,int>>v;
int32_t main() 
{
    IOS;
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({b,a});
    }
    int dp[100005]={};
    for(int i=0;i<1e5+4;i++)
        dp[i]=1e18;
    dp[0]=0;
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
        for(int j=1e5;j>=v[i].first;j--)
            dp[j]=min(dp[j],dp[j-v[i].first]+v[i].second);

    for(int i=1e5;i>=0;i--)
        if(dp[i]<=w)
            return cout<<i,0;
}


Measured memory_bytes: 4396
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	n <- readLn :: IO Int
	print $ (n + 1) `div` 2


Measured memory_bytes: 508
N, M = map(int, input().split())
H = list(map(int, input().split()))
Root = []
for i in range(M):
  temp = list(map(int, input().split()))
  Root.append(temp)

ans = [1]*N

for i in range(M):
  r_start = Root[i][0] - 1 
  r_stop = Root[i][1] - 1
  if H[r_start] < H[r_stop]:
    ans[r_start] = 0
  elif H[r_start] == H[r_stop]:
    ans[r_start] = 0
    ans[r_stop] = 0
  else:
    ans[r_stop] = 0

print(sum(ans))

Measured memory_bytes: 31860
#include<stdio.h>

int main(void){
	int m,f,r;
	char A[5]={'A','B','C','D','F'};
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1) break;
		if(m==-1 || f==-1)
		printf("%c\n",A[4]);
		else if((m+f)>=80) printf("%c\n",A[0]);
		else if((m+f)>=65) printf("%c\n",A[1]);
		else if((m+f)>=50 || r>=50) printf("%c\n",A[2]);
		else if((m+f)>=30) printf("%c\n",A[3]);
		else if((m+f)<30) printf("%c\n",A[4]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <set>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    llong n,a,b;
    cin>>n>>a>>b;
    if(a>b)
    {
        cout<<0<<endl;
        return  0;
    }
    else if(n==1&&a!=b)
    {
        cout<<0<<endl;
        return  0;
    }
    else if(n==1&&a==b)
    {
        cout<<1<<endl;
        return  0;
    }
    else
        {
        llong ans=(b-a)*(n-2)+1;
        cout<<ans<<endl;
            return  0;
        }
    return  0;
}


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

using namespace std;

int main() {
		int N;
		cin >> N;
		int W[N];
		for (int i = 0; i < N; i++) {
				cin >> W[i];
		}

		int ans = 1e9;
		for (int i = 0; i < N; i++) {
				int s1 = 0, s2 = 0;
				for (int j = 0; j < N; j++) {
						if (j <= i) s1 += W[j];
						else s2 += W[j];
				}
				ans = min(abs(s1 - s2), ans);
		}

		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 < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    int ans = 0;
    if (M == 1){
        ans += 3800;
        ans += 200 * (N - M);
    }
    else if (M == 2){
        ans += 15200;
        ans += 400 * (N - M);
    }
    else if (M == 3){
        ans += 45600;
        ans += 800 * (N - M);
    }
    else if (M == 4){
        ans += 121600;
        ans += 1600 * (N - M);
    }
    else if (M == 5){
        ans += 304000;
        ans += 3200 * (N - M);
    }
    cout << ans << endl;
}


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

namespace D
{
	class Program
	{

		static void printMatrix(List<List<int>> matrix){
			for (int i = 0; i < matrix.Count; i++)
			{
				for (int j = 0; j < matrix[i].Count; j++)
				{
					Console.Write(matrix[i][j]);
					Console.Write(' ');
				}
				Console.Write('\n');
			}
			Console.Write('\n');
		}


		static void Main(string[] args)
		{
			string[] tmp_str = Console.ReadLine().Split(' ');
			int N = int.Parse(tmp_str[0]);
			int X = int.Parse(tmp_str[1]);
			int Y = int.Parse(tmp_str[2]);
			X--;
			Y--;

			// 距離配列
			List<List<int>> matrix = new List<List<int>>();
			// 初期化
			for (int i = 0; i < N; i++)
			{
				List<int> tmp_list = new List<int>();
				for (int j = 0; j < N; j++)
				{
					tmp_list.Add(Math.Abs(i-j));
				}
				matrix.Add(tmp_list);
			}
			matrix[X][Y] = 1;
			matrix[Y][X] = 1;

			// デバッグ表示
			// printMatrix(matrix);

			// やろうとしたけどTLEした
			// // ワーシャルフロイド法
			// for (int i = 0; i < N; i++)
			// {
			// 	for (int j = 0; j < N; j++)
			// 	{
			// 		for (int k = 0; k < N; k++)
			// 		{
			// 			matrix[i][j] = matrix[j][i] = Math.Min(matrix[i][j], matrix[i][k] + matrix[k][j]);
			// 		}
			// 	}
			// }

			// 解放
			for (int i = 0; i < N; i++)
			{
				for (int j = 0; j < N; j++)
				{
					matrix[i][j] = Math.Min(matrix[i][j], Math.Min(Math.Abs(X-i)+1+Math.Abs(Y-j), Math.Abs(Y-i)+1+Math.Abs(X-j)));
				}
			}

			// デバッグ表示
			// printMatrix(matrix);

			// 1~N-1までを数える
			List<int> ans = new List<int>();
			for (int i = 0; i < N; i++)
			{
				ans.Add(0);
			}
			for (int imatrix = 0; imatrix < N; imatrix++)
			{
				for (int jmatrix = 0; jmatrix < N; jmatrix++)
				{
					ans[matrix[imatrix][jmatrix]]++;
				}
			}
			for (int k = 1; k < N; k++)
			{
				Console.WriteLine(ans[k] / 2);
			}
		}
	}
}


Measured memory_bytes: 41288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15

int res = 0, n, m;
const int MAXN = 50;
vector<int> g[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN];

void dfs(int v, int p = -1) {
	used[v] = true;
	tin[v] = fup[v] = timer++;
	for(int i = 0; i < (int)g[v].size(); i++){
		int to = g[v][i];
		if(to == p) continue;
		if(used[to])
			fup[v] = min(fup[v], tin[to]);
		else{
			dfs(to, v);
			fup[v] = min(fup[v], fup[to]);
			if(fup[to] > tin[v])
				res++;
		}
	}
}

void find_bridges(){
	timer = 0;
	for(int i = 0; i < n; i++){
		used[i] = false;
	}
	for(int i = 0; i < n; i++){
		if(!used[i])
			dfs(i);
	}
}

int main() {
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int u,v;
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	find_bridges();
	cout << res << endl;
	return 0;
}





Measured memory_bytes: 256
import Control.Monad

slice a b str = take (b - a + 1) . drop a $ str

parseInsts str [] = return ()
parseInsts str (i:is) = do
  let op = i !! 0
  let a = read (i !! 1) :: Int
  let b = read (i !! 2) :: Int
  when (op == "print") $ do
    putStrLn $ slice a b str
    parseInsts str is
  when (op == "reverse") $ do
    let str1 = take a str ++ (reverse . slice a b) str ++ drop (b + 1) str
    -- print $ "reverse:" ++ drop (b + 1) str
    parseInsts str1 is
  when (op == "replace") $ do
    let sub = i !! 3
    let str1 = take a str ++ sub ++ drop (b + 1) str
    parseInsts str1 is
  
main = do
  str <- getLine
  q <- readLn
  insts <- replicateM q $ return . words =<< getLine
  parseInsts str insts

Measured memory_bytes: 6752
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    auto a = new long[5];
    for (int i = 0; i < n; i++) {
        auto s = read!string;
        switch (s[0]) {
        case 'M': a[0]++; break;
        case 'A': a[1]++; break;
        case 'R': a[2]++; break;
        case 'C': a[3]++; break;
        case 'H': a[4]++; break;
        default: break;
        }
    }

    long ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += a[i] * a[j] * a[k];
            }
        }
    }
    writeln(ans);
}


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

struct UnionFind{
  vector<int> par;
  vector<int> rank;
  vector<int> sizes;

  UnionFind(int n) : par(n, -1), rank(n, 0), sizes(n, 1){}

  int find(int x){
    if(par[x] < 0) return x;
    else return par[x] = find(par[x]);
  }

  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x==y) return false;
    else if(rank[x]<rank[y]){
      par[x] = y;
      sizes[y] += sizes[x];
    }
    else if(rank[x]>rank[y]){
      par[y] = x;
      sizes[x] += sizes[y];
    }
    else{
      par[y] = x;
      rank[x] += 1;
      sizes[x] += sizes[y];
    }
    return true;
  }

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

  int size(int x){
    return sizes[find(x)];
  }
};

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

int main() {
  int h, w, c;
  while(cin >> h >> w >> c){
    if(h==0) return 0;

    int ans=0;
    UnionFind uf(h*w);
    vector<vector<int>> board(h, vector<int>(w));

    rep(i, h)rep(j, w){
      int t; cin >> t;
      board[i][j] = t;
    }

    rep(i, h)rep(j, w)rep(t, 4){
      if(0<=i+dy[t] && i+dy[t]<h && 0<=j+dx[t] && j+dx[t]<w && board[i][j]==board[i+dy[t]][j+dx[t]]){
        uf.unite(w*i+j, w*(i+dy[t])+j+dx[t]);
      }
    }

    REP(c1, 1, 7)REP(c2, 1, 7)REP(c3, 1, 7)REP(c4, 1, 7){
      if(c1==c2 || c2==c3 || c3==c4 || c4==c) continue;
      int cs[] = {c1, c2, c3, c4, c};
      UnionFind uft = uf;
      rep(cc, 5)rep(i, h)rep(j, w){
        int ct = cs[cc];
        if(uft.same(w*i+j, 0)){
          rep(t, 4){
            if(0<=i+dy[t] && i+dy[t]<h && 0<=j+dx[t] && j+dx[t]<w && ct==board[i+dy[t]][j+dx[t]]){
              uft.unite(w*i+j, w*(i+dy[t])+j+dx[t]);
            }
          }
        }
      }
      ans = max(ans, uft.size(0));
    }
    cout << ans << endl;
  }
  return 0;
}



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

using namespace std;
int main(void){
  int  n;
  int sum=0;
  cin >> n;

  int  z=n;
  int a[10]={};
  static int i=0;

  if(n/10==0){cout << "Yes" << endl;return 0;}
  while(n>0){
    a[i]=n%10;
    n=n/10;
    i++;
  }
  for(int j=0; j<10; j++){
    sum += a[j];
  }

  if(z%sum==0){
    cout << "Yes" << endl;
    return 0;
  }else{
    cout << "No" << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int n, m = 0;
vector<int>a, x;
deque<int> ret;
int main(void) {
	cin >> n;
	x = vector<int>(n + 1);
	a = vector<int>(n + 1);
	for (int i = 1; i < n + 1; i++) {
		int ai;
		cin >> ai;
		a[i] = ai;
		if (i > n / 2) {
			x[i] = ai;
			m += ai;
			if (ai)
				ret.push_back(i);
		}
	}
	for (int i = n / 2; i > 0; i--) {
		int tmp = 0;
		for (int j = 2; i * j < n + 1; j++) {
			tmp += x[i * j];
		}
		tmp %= 2;
		if (tmp == 1) {
			if (a[i] == 1)
				x[i] = 0;

			if (a[i] == 0)
				x[i] = 1;
		}
		else {
			x[i] = a[i];
		}
		if (x[i] == 1) {
			m++;
			ret.push_front(i);
		}
	}
	cout << m << endl;
	for (int i = 0; i < m - 1; i++) {
		cout << ret[i] << " ";
	}
	if (m > 0)
		cout << ret[m - 1];
	cout << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


const ll MAX_D=365;
const ll NUM=26;

ll d;
vll c(NUM);
vvll s(MAX_D,vll(NUM));
vll ans(MAX_D);


struct Solve{
  random_device seed_gen;
  default_random_engine engine;
  uniform_int_distribution<ll> day;
  uniform_int_distribution<ll> val;

  ll best_score=0;
  ll pre_score=0;

  Solve():day(0,MAX_D-1),val(0,NUM-1){
    REP(i,d)ans[i]=i%NUM;
    engine=default_random_engine(seed_gen());
  }


  void init(){
    best_score=calcScore();
    pre_score=best_score;
  }


  void modify(ll index, ll value){
    //swap(state[l],state[r]);
    ans[index]=value;
  }


  ll calcScore(){
    vll last(NUM,-1);
    ll score=0;
    REP(i,d){
      ll now=ans[i];
      last[now]=i;

      ll cost=0;
      REP(j,NUM)cost+=c[j]*(i-last[j]);

      score+=s[i][now]-cost;
    }

    //score=max(ll(score+1e6),0LL);
    return score;
  }


  void climbMountain(){
    ll value=val(engine);
    ll index=day(engine);

    ll prevalue=ans[index];
    modify(index,value);
    ld now_score=calcScore();

    if(best_score<now_score)
      best_score=now_score;
    else
      modify(index,prevalue);
  }


};


ll calc(ll x){
  return max(ll(x+1e6),0LL);
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  const ll TIME_LIMIT=1900; //ms
  chrono::system_clock::time_point begin_time,now_time;
  begin_time=chrono::system_clock::now();

  cin>>d;
  REP(i,NUM)cin>>c[i];
  REP(i,d)REP(j,NUM)cin>>s[i][j];

  Solve sl=Solve();
  sl.init();

  sl.init();
  ll cnt=0;
  ll kosin=0;
  while(true){
    if(kosin<cnt/10000){
      kosin=cnt/10000;

      now_time=chrono::system_clock::now();
      ld diff_time=chrono::duration_cast<chrono::milliseconds>(now_time-begin_time).count();
      if (diff_time > TIME_LIMIT) break;
    }

    sl.climbMountain();
    cnt++;
  }

//  cout<<calc(sl.best_score)<<endl;
//  cout<<cnt<<endl;

  REP(i,d)cout<<ans[i]+1<<endl;
}



Measured memory_bytes: 3760
import math
N = int(input())
def greed(N, a):
    if a == 6:
        L = [6**i for i in range(7, -1, -1)]
    else:
        L = [9**i for i in range(6, -1, -1)]
    num = 0
    while True:
        if N == 0:
            return num
        for l in L:
            if l <= N:
                N -= l
                break
        num += 1
A = []
for n in range(N+1):
    A.append(greed(n, 6) + greed(N-n, 9))
print(min(A))

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


int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3);
	cout << ((a[0] == 5 && a[1] == 5 && a[2] == 7) ? "YES" : "NO") << endl;

} 

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

int main(){
  int k; string s;
  cin >> k >> s;
  if (s.size() > k) {
    rep(i,k) cout << s[i];
    cout << "..." << endl;
  }
  else cout << s << endl;
  return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
const int maxn = 2e5 +5;
const int inf = 1e9 + 1;
const ll llinf = 1e18 + 5;
ll n;
vector<int> Build(int x , ll n){
    vector<int> res(0);
    if(n == 1)return res;
    if(n & 1)res = Build(x + 1 , n - 1);
    else res = Build(x + 1 , n / 2);
    if(n & 1)res.insert(res.begin(),x);
    else res.pb(x);
    return res;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    ll n;cin >> n;
    vector<int> res = Build(1 , n + 1);
    cout << res.size() * 2 << endl;
    for(int c : res)cout << res.size() - c + 1 << " ";
    for(int i = 1 ; i <= (int)res.size() ; ++i)cout << i << " ";

}



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

int main()
{
    int i, k, a, b;

    cin >> k;
    cin >> a >> b;

    for (i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK";
            return 0;
        }
        else
        {
        }
    }
    cout << "NG";
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef map<int, int> mii;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n"
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main(){
	ll a, b;
	cin >> a >> b;
	cout << max(0LL, a-2*b) << endl;	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N; cin >> N;
	vector<ll> t(N), a(N);
	for (int i = 0; i < N; i++) {
		cin >> t[i] >> a[i];
	}
	ll T = t[0], A = a[0];
	for (int i = 1; i < N; i++) {
		ll tk = (T + t[i] - 1) / t[i];
		ll ak = (A + a[i] - 1) / a[i];
		ll ba = max(tk, ak);
		T = ba * t[i], A = ba * a[i];
	}
	cout << T + A << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

long long H, W, A[100009], B[100009], L1, L2, sum;
vector<pair<long long, int>>vec;

int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) { scanf("%lld", &A[i]); vec.push_back(make_pair(A[i], 1)); }
	for (int i = 1; i <= W; i++) { scanf("%lld", &B[i]); vec.push_back(make_pair(B[i], 2)); }
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());

	for (int i = 0; i < vec.size(); i++) {
		long long I1 = L1, I2 = L2;
		if (vec[i].second == 1) I1++;
		else I2++;
		sum += (I1 * I2 - L1 * L2) * vec[i].first;
		L1 = I1; L2 = I2;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 8132
import * as fs from "fs"
const process = (n: number): string => {
  const a1 = 9
  const a3 = 999 - 100 + 1
  const a5 = 99999 - 10000 + 1
  const l = (n + "").length
  if (l === 2) {
    return a1 + ""
  }
  if (l === 4) {
    return a1 + a3 + ""
  }
  if (l === 6) {
    return a1 + a3 + a5 + ""
  }

  if (l === 1) {
    return n + ""
  }
  if (l === 3) {
    return a1 + (n - 100 + 1) + ""
  }
  // if (l === 5)
  return a1 + a3 + (n - 10000 + 1) + ""
}

const Main = (input: string): string => {
  const n: number = parseInt(input)

  const res = process(n) + ""
  console.log(res)
  return res
}
Main(fs.readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
import java.util.Scanner;

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

		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();

		double l = 100000000;

		int ans = 0;

		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();

			double ave = t - h * 0.006;

			double s = Math.abs(ave - a);

			if(s < l) {
				l = s;
				ans = i + 1;
			}
		}

		System.out.println(ans);

		sc.close();

	}
}

Measured memory_bytes: 24404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int round255(int x){
    if(x>255)return 255;
    if(x<0)return 0;
    return x;
}

int main(){
    while(true){
        int n,m;cin>>n>>m;if(!n)break;
        int c[m];rep(i,m)cin>>c[i];
        int x[n];rep(i,n)cin>>x[i];
        int dp[n+1][256];
        rep(i,n+1) rep(j,256) dp[i][j]=mod;
        dp[0][128]=0;
        rep(i,n){
            rep(j,256){
                if(dp[i][j]==mod)continue;
                rep(k,m){
                    chmin(dp[i+1][round255(j+c[k])],dp[i][j]+abs(x[i]-round255(j+c[k]))*abs(x[i]-round255(j+c[k])));
                }
            }
        }
        int ans=mod;
        rep(i,256)chmin(ans,dp[n][i]);
        cout<<ans<<endl;
    }
}
                



Measured memory_bytes: 23164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

vector<pair<char, ll>> RLE(string s){
    vector<pair<char, ll>> ret;
    ll ns = SZ(s);
    ll cnt = 0;
    rep(i, ns){
        cnt++;
        if((i < ns-1 && s[i] != s[i+1]) || i == ns-1){
            ret.emplace_back(s[i], cnt);
            cnt = 0;
        }
    }
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin >> s;
    ll n = SZ(s);
    ll k;
    cin >> k;
    {
        bool f = 1;
        char x = s[0];
        rep(i, n){
            if(s[i] != x) f = 0;
        }
        if(f){
            cout << (n*k)/2 << endl;
            return 0;
        }
    }
    vector<pair<char, ll>> r = RLE(s);
    if(s[0] == s[n-1]){
        ll ans = 0;
        repr(i, 1, SZ(r)-1){
            ans += r[i].second/2 * k;
        }
        ans += r[0].second/2;
        ans += r[SZ(r)-1].second/2;
        ans += (r[0].second+r[SZ(r)-1].second)/2*(k-1);
        cout << ans << endl;
    }else{
        ll ans = 0;
        for(auto&& e: r){
            ans += e.second/2;
        }
        cout << ans*k << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()) {
      int A = in.nextInt();
      int B = in.nextInt();
      int C = in.nextInt();

      if (A == B && B == C) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 23124
# coding:utf-8

import sys
import heapq
from collections import defaultdict, deque

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, k = LI()
sushi = [(d, t) for t, d in (LI() for _ in range(n))]
sushi.sort()
sushi.reverse()

# sushiを美味しいものからk個とる
umami_max = []  # 寿司の種類数が減らないように最低一つは別で確保
umami_sub = []  # 種類数を増やす時に捨てる候補(priority_queueで管理)
used = set()
for i in range(k):
    d, t = sushi[i]
    if t not in used:
        umami_max.append(d)
        used.add(t)
    else:
        heapq.heappush(umami_sub, d)

umami_1 = sum(umami_max)
umami_2 = sum(umami_sub)
sushi_v = len(used)
ans = umami_1 + umami_2 + sushi_v ** 2

for i in range(k, n):
    if len(umami_sub) == 0:  # 捨てる寿司の候補がない場合，満足度はこれ以上大きくならない
        break
    d, t = sushi[i]
    if t in used:
        continue
    used.add(t)
    umami_1 += d
    umami_2 -= heapq.heappop(umami_sub)  # 一番美味しくない寿司を消す
    sushi_v += 1
    ans = max(ans, umami_1 + umami_2 + sushi_v ** 2)

print(ans)


Measured memory_bytes: 20084
n = int(input())
xn = list(map(int, input().split()))
xn = sorted(xn)
min_x = xn[0]
max_x = xn[-1]
min_total = float('inf')
for i in range(min_x, max_x+1):
    total = 0
    for x in xn:
        total += abs(x-i)**2
    min_total = min(min_total, total)

print(min_total)

Measured memory_bytes: 3064
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  vector<PII> vec;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    vec.push_back({a, b});
  }  

  bool ok = false;

  for (int i = 0; i < n; ) {
    if (vec[i].F != vec[i].S) {
      i++;
      continue;
    }
    int cnt = 0;
    while (i < n && vec[i].F == vec[i].S) {
      cnt++;
      i++;
    }
    ok |= (cnt >= 3);
  }

  cout << (ok ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();
		
		int oneLoopTime = (n - m) * 100 + m * 1900;
		
		for(int i = 0; i < m; i++) {
			oneLoopTime *= 2;
		}
		
		System.out.println(oneLoopTime);
	}
	
	

}


Measured memory_bytes: 21844
#include <cstdio>
int main()
{
    int n; scanf("%d", &n);
    long long x = 100000;
    for (int i = 0; i < n; ++i) {
        x *= 105;
        int r = x % 100000;
        if (r > 0) { x -= r; x += 100000; }
        x /= 100;
    }
    printf("%lld\n", x);
    return 0;
}

Measured memory_bytes: 0