akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
#define ll long long
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    ll W = (7 * A) + B;
    ll T = C % W;
    cout << ((C / W) * 7) + min(7, (int)((T + A - 1) / A)) << endl;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

long long INF=LLONG_MAX;

ll a[200222];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	ll h; cin >> h;
	ll ans = 0;
	ll ptr = 1;
	while(h>1){
		ans+=ptr;
		h/=2;
		ptr*=2;
	}
	ans += ptr;
	cout << ans << endl;
}	


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

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


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

    if(X == 1){
        cout << 1 << endl;
        return 0;
    }

    ll Xcopy = X;
    ll a = 2;
    ll acopy = 1;
    ll ans = 0;
    while(a * a <= X){
        acopy = a;
        while(acopy <= X){
            ans = max(ans, acopy);
            acopy *= a;
        }
        a++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
 
using namespace std;
 
int main() {
  int h, n;
  int damage = 0;
  cin >> h >> n;
  int a[n];
  bool yes = false;
  
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (h <= damage + a[i]) {
      yes = true;
      break;
    } else {
      damage += a[i];
    }
  }
  
  if (yes) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  
  return 0;
}

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

int main(){
	double l, r;
	int l_cnt[4] = {}, r_cnt[4] = {};
	while(cin >> l >> r){
		if(l >= 1.1) l_cnt[0]++;
		else if(l >= 0.6) l_cnt[1]++;
		else if(l >= 0.2) l_cnt[2]++;
		else l_cnt[3]++;

		if(r >= 1.1) r_cnt[0]++;
		else if(r >= 0.6) r_cnt[1]++;
		else if(r >= 0.2) r_cnt[2]++;
		else r_cnt[3]++;
	}

	for(int i = 0; i < 4; i++){
		cout << l_cnt[i] << " " << r_cnt[i] << endl;
	}

}

Measured memory_bytes: 1224
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	cin>>s;
	int i,k=0,z=0;
	for(i=1;i<s.length() ;i++){
		if(s[i]!='0')k=1;
	}
	if(k==0&&s[0]=='1'){
		cout<<10;
		return 0;
	}
	for(i=0;i<s.length() ;i++){
		z+=s[i]-48;
	}
	cout<<z;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n, N) for(ll i=(n);i<(N);i++)
#define RREP(i, n, N) for(ll i=(N-1);i>=(n);i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int N;
int p[11];

int main() {
    cin>>N;
    REP(i,0,N){
        cin>>p[i];
    }

    sort(p, p+N);

    int sum = 0;
    REP(i,0,N){
        if(i == N-1){
            sum += p[i] / 2;
        }else{
            sum += p[i];
        }
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
import static java.lang.System.in;
 
public class Main {
    static long mod = 1000000000+7;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        int[] p = new int[n];
        for(int i=0;i<n;i++) p[i]=sc.nextInt();
        int left = 0, mid = 0, right = 0;
        for(int w:p){
            if(w<=a) left++;
            else if(w>=b+1) right++;
            else mid++;
        }
        int ans = Math.min(left,Math.min(mid,right));
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
s = int(input())
memo = [0]*1000000
memo[0] = s
dic = {s:1}

def f(n):
    return int(n/2) if n%2==0 else 3*n+1

for i in range(1, 1000002):
    memo[i] = f(memo[i-1])
    if dic.get(memo[i]):
        print(i+1)
        exit()
    else:
        dic[memo[i]] = 1

Measured memory_bytes: 46192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);	
ll tot(ll v, ll n, vec &a)
{
	ll ans=0;
	floop(i,0,n)
		ans+=max((a[i]-1)/v,0ll);
	return ans;
}
ll bs(vec &a, ll mx, ll k)
{
	ll low=1,high=mx,mid;
	while(low<high)
	{
		mid=low+(high-low)/2;
		if(tot(mid,sz(a),a)<=k)
		high=mid;
		else
		low=mid+1;	
		//cout<<low<<" ";
	}
	return high;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	vec a(n);
	floop(i,0,n)
	cin>>a[i];
	sort(all(a), greater<ll> ());
	ll mx=a[0];
	cout<<bs(a,mx,k)<<"\n";
	return 0;
}

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

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

    int count = 0;
    for(int i = 0; i < n; i++){
        if(d % a[i] == 0){
            count += d / a[i];
        }else{
            count += d / a[i] + 1;
        }
    }

    cout << count + x << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat() float64 {
	a, _ := strconv.Atoi(next())
	return float64(a)
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func abs(a, b int) int {
	return int(math.Abs(float64(a) - float64(b)))
}

func main() {
	sc.Split(bufio.ScanWords)
	H := nextInt()
	W := nextInt()
	N := nextInt()

	larger := max(H, W)
	if N%larger == 0 {
		fmt.Print(N / larger)
		return
	}
	fmt.Print(N/larger + 1)
}


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

int a[1000005],b[1000005];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	int	R, L;
	if(n%2==0)
	{

		R=n/2+1, L=R-1;
		for(int i=1;i<=n;i++)
			if(i&1)
				b[R]=a[i], R++;
			else
				b[L]=a[i],L--;
		for(int i=1;i<=n;i++)
			printf("%d ",b[i]);
	}
	else
	{

		L=n/2+1, R=L+1;
		for(int i=1;i<=n;i++)
			if(i&1)
				b[L]=a[i], L--;
			else
				b[R]=a[i], R++;
		for(int i=1;i<=n;i++)
			printf("%d ",b[i]);
	}
return 0;
}

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k;
	int a[5];


		REP(i,5){
			cin >> a[i];
		}

		cin >> k;

	bool f = true;
		REP(i,5){
			REP(j,5){
				if(i == 5) continue;
				if(abs(a[i] - a[j]) > k) f = false;
				
			}
		}

		if(f){
			cout <<"Yay!"<<endl;
		}
		else{
			cout << ":(" << endl;
		}
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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




int main(){
    // cout << fixed << setprecision(5);

    lli n,m;
    cin>>n>>m;

    set<lli> s;

    REP(i,0,m){
        lli d;
        cin>>d;
        REP(j,0,d){
            lli a;
            cin>>a;
            s.insert(a);
        }
    }

    cout<<n-s.size()<<endl;

    // Failed to predict input format
    return 0;
}


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

int main(){
    int V, E;
    cin >> V >> E;
    vector<vector<int> > edge(10001);
    vector<int> state(V, 0);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        edge[s].push_back(t);
        state[t]++;
    }
    vector<int> ans;
    for (int i = 0; i < V; i++) {
        if (state[i] == 0) ans.push_back(i);
    }
    for (int i = 0, s = ans.size(); i < s; i++) {
        int a = ans[i];
        for (int j = 0, ss = edge[a].size(); j < ss; j++) {
            int t = edge[a][j];
            state[t]--;
            if (state[t] == 0) {
                ans.push_back(t);
                s++;
            }
        }
        cout << ans[i] << endl;
    }

    return 0;
}



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

int main(){
  int n,x1,y1,z1,w1,x2,y2,z2,w2;
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
      cout << x1*x2 - y1*y2 - z1*z2 - w1*w2 << " ";
      cout << y1*x2 + x1*y2 - w1*z2 + z1*w2 << " ";
      cout << z1*x2 + x1*z2 + w1*y2 - y1*w2 << " ";
      cout << w1*x2 - z1*y2 + y1*z2 + x1*w2 << endl;
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n;
  cin >> n;
  ll dv=2;
  vector<int> ans;
  rep(i,60){
    if(n%dv!=0){
      ans.pb(1);
      n += -pow(-2,i);
    }
    else ans.pb(0);
    if(n==0) break;
    dv*=2;
    //    cout << n << endl;
  }
  reverse(ans.begin(),ans.end());
  rep(i,ans.size()){
    cout << ans[i];
  }
  cout << "" << endl;
  
    

  

  //  cout << endl << endl;
  //  cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << "s"<<endl;
  return 0;


}


Measured memory_bytes: 256
/*
    Created by Ezio112
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define inf ll(10e16)
#define mod ll(10e8+7)
#define ff first
#define ss second
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll k,l,r;
        cin>>k>>l>>r;
        for(ll i=l;i<=r;++i)
        {
            if(i%k==0)
            {
                cout<<"OK";
                return 0;
            }
        }
        cout<<"NG";
    }
    return 0;
}


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

using namespace std;
#define ll long long
#define int long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

#define MAX 200000

bool gojo[MAX];
vector<int> pr;

void init()
{
	rep(i, MAX) gojo[i] = true;
	gojo[0] = gojo[1] = false;
	rep(i, MAX) {
		while (!gojo[i]) i++;
		pr.PB(i);
		for (int j = i+i; j < MAX; j += i) gojo[j] = false;
	}
}

int N, P;

signed main()
{
	init();
	cin >> N >> P;
	while (N+1) {
		N++;
		auto itr = lower_bound(all(pr), N);
		vector<int> v;
		rep(i, 22) {
			v.PB(*itr);
			itr++;
		}
		vector<int> vv;
		rep(i, 22) rep(j, 22) {
			if (i > j) continue;
			vv.PB(v[i]+v[j]);
		}
		sort(all(vv));
		cout << vv[P-1] << endl;
		cin >> N >> P;
	}
}



Measured memory_bytes: 3320
# 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 <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	int sx = 0, sy = 0, gx = w, gy = h;
	int x, y, a;
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		if (a == 1)sx = max(sx, x);
		if (a == 2)gx = min(gx, x);
		if (a == 3)sy = max(sy, y);
		if (a == 4)gy = min(gy, y);
	}
	if (sx > gx || sy > gy)cout << 0 << endl;
	else cout << (gx - sx)*(gy - sy) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  long ans=0;
  bool f=false;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=n-1;i>0;i--){
    if(a[i-1]==a[i]){
      if(ans){cout<<ans*a[i]<<endl;return 0;}
      ans=a[i--];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define floop(i,a,b) for (int i=(a);i<(b);i++)
#define rloop(i,a,b) for (int i=(a);i>=(b);i--)
#define floopeq(i,a,b) for (int i=(a);i<(b);i++)
#define pa pair<int,int>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll modInverse(ll a, ll m) 
{ 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; 
}
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  
    {if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;  }  return res;  
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b){if(a.fi==b.fi)return b.se>a.se;return a.fi>b.fi;}
void run(vector<int>v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}
void solve()
{
   ll n;
   cin>>n;unordered_map<int,int>mp;
   while (n % 2 == 0)  
    {  
        mp[2]++; 
        n = n/2;  
    }  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            mp[i]++;
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        mp[n]=1;
    int ans=0;
    for(auto x:mp)
    {
        int i=1,cnt=0;
        while(((i*(i+1))/2)<=x.se)
        {
            cnt++;
            i++;
        }
        ans+=cnt;
    }
    cout<<ans<<endl;

}

int main() 
{ 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    
        solve();
        
    
    
    return 0; 
} 

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

int main() {
	ll n; 
	while (cin >> n, n) {
		vector<ll>v;
		rep(i, n) {
			ll t; cin >> t;
			v.push_back(t);
		}
		sort(v.begin(), v.end());
		ll cnt = 0;
		ll back = 0;
		for (ll i : v) {
			cnt += back;
			back += i;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3280
x=[int(i) for i in input (). split ()]
g=[0,0]
for i in range(len(x)):
    if x[i]==2:
        g[i]=2
    elif x[i]==4 or x[i]==6 or x[i]==9 or x[i]==11:
        g[i]=1
if g[0]==g[1]:
    print ("Yes")
else:
    print ("No")

Measured memory_bytes: 3064
// C - Special Trains
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vector<int> C(N),S(N),F(N);
	rpz(i, N-1) cin>>C[i]>>S[i]>>F[i];

	rpz(i, N-1){
		int ans = C[i] + S[i];
		rp(j, i+1, N-1) ans = C[j] + max(S[j], (ans + F[j] - 1) / F[j] * F[j]);//round up
		cout<< ans <<endl;
	}
	cout<< 0 <<endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
x, y = LS()
if x > y:
    print(">")
elif x == y:
    print("=")
else:
    print("<")
"""

#B
x, y, z = LI()
print((x-z)//(y+z))

Measured memory_bytes: 38384
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
int temp[100000];
char A[100010];
int main() {
	int N, M, L, R;
	scanf("%d%d", &N, &M);
	//cin >> N >> M;
	getchar();
	int j = 0;
	for (int i = 0,sum = 0; i < N; i++) {
		A[i] = getchar();
		if (A[i] == 'C' && i != 0 && A[i - 1] == 'A') {
			sum++;
		}
		temp[i+1] = sum;
	}
	while (M--) {
		scanf("%d%d", &L, &R);
		printf("%d\n", temp[R] - temp[L]);
	}
	return 0;
}


Measured memory_bytes: 1280
import java.util.*;
public class Main {

    static int[] f = null;

    static int rhs(int a, int b, int c){
        return ((a*a)+(b*b)+(c*c)+(a*b)+(b*c)+(a*c));
    }

    static void solve(){
        Scanner sc = new Scanner(System.in);
        int NOC = sc.nextInt(); 
        int count = 0;
        f = new int[10050];
        Arrays.fill(f,0);
        // Can we do better? I dont know..
        for(int i=1; i<=105;i++){
            for(int j=1; j<=105; j++){
                for(int k=1; k<=105; k++){
                    int val = rhs(i,j,k);
                    if(val<10050) f[val]+=1;
                }
            }
        }
    
        for(int a: f) {
            if(count>0) System.out.println(a);
            if(count==NOC) break;
            count++;
        }
        sc.close();
    }
    
    public static void main(String args[]) {
        solve();
    }
}

Measured memory_bytes: 38948
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b ? "true" : "false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vector<bool> v) {
	string res;
	for(int i = 0; i < (int) v.size(); i++)
		res += char('0' + v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template<class T> string to_string(T v) {
    bool f = 1;
    string res;
    for(auto& x : v) {
		if(!f)
			res += ' ';
		f = 0;
		res += to_string(x);
	}
    return res;
}
 
void DBG() {
	cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

long long mod = 1e9 + 7;

void solve() {
	long long s;
	cin >> s;
	vector<long long> dp(s + 1, 1);
	dp[0] = dp[1] = dp[2] = 0;
	for(int i = 3; i <= s; i++){
		for(int j = 3; j <= 2000; j++){
			if(i + j > s) break;
			(dp[i + j] += dp[i]) %= mod;
		}
	}
	cout << dp[s];
}	
 
int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3460
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		sc.close();

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


Measured memory_bytes: 23380
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;
vector<ll>g[maxn];
ll sz[maxn];
bool used[maxn];

void dfs1(ll u) {
	used[u] = 1;
	sz[u] = 1;
	for (ll v : g[u]) {
		if (used[v]) continue;
		dfs1(v);
		sz[u] += sz[v];
	}
}

ll ans[maxn];
ll cur;

void dfs(ll u) {
	used[u] = 1;
	ans[u] = cur;
	for (ll v : g[u]) {
		if (used[v]) continue;
		ll lstu = sz[u], lstv = sz[v];
		sz[u] -= sz[v];
		sz[v] = lstu;
		ll lstcur = cur;
		cur = mul(cur, inv(lstu));
		cur = mul(cur, inv(lstv));
		cur = mul(cur, sz[u]);
		cur = mul(cur, sz[v]);
		dfs(v);
		cur = lstcur;
		sz[u] = lstu;
		sz[v] = lstv;
	}
}


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	for (ll i = 0; i < n - 1; i++) {
		ll u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1);
	fill_n(used, maxn, 0);
	cur = 1;
	ll fact_n = 1;
	for (ll i = 1; i <= n; i++) {
		cur = mul(cur, sz[i]);
		fact_n = mul(fact_n, i);
	}
	dfs(1);
	
	for (ll i = 1; i <= n; i++) {
		cout << mul(fact_n, inv(ans[i])) << '\n';
	}


		
	return 0;
}

/*
8 6

4 5 1 2 3 5 3 3

*/

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int k,x; cin >> k >> x;

  for(int i = -k;i<=k;i++){
    int y;
    if(i<0) y = x+i+1;
    else if(i>1) y = x+i-1;
    if(i<0 || i>1) cout << y << " ";
  }
  
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b; a>=c; a--)
#define ll long long
#define sum(a,b) a=a+b
#define mem(a, b) memset(a, (b), sizeof(a))

int main(){
    
    
    string s;
    cin>>s;
    
    rep(i,0,s.size()-1){
        if(s[i]=='1'){
            cout<<9;
        }else{
            cout<<1;
        }
    }
    
    return 0;
}


Measured memory_bytes: 384
(* Vicfred
 * https://atcoder.jp/contests/abc144/tasks/abc144_c
 * math
 * *)
let divisors n =
    let rec f i =
        if i*i > n then []
        else if n mod i = 0 then i :: f(i+1)
        else f(i+1)
    in
    f 1
;;

let min_list a = List.fold_left min max_int a ;;

let main =
    let n = Scanf.scanf "%d" (fun x -> x) in
    let ans = divisors n |> List.map (fun x -> x + n / x - 2) |> min_list in
    Printf.printf "%d\n" ans
;;



Measured memory_bytes: 3948
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void){

    string S, T, U;
    int A, B;

    cin >> S >> T >> A >> B >> U;


    if(U == S)
        A--;
    else
        B--;

    cout << A << " " << B << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  int count=0;
  cin>>A>>B;
  for(int i=0;i<1000;i++){
    if(i*(A-1)+1<B){
      count++;
    }
    else{
      break;
    }
  }

  cout<<count<<endl;
}

  



    

      

    
     


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int a,b; cin >> a >> b;
  cout << (a+b >= 10 ?  "error" : to_string(a+b)) << endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n = s.size();
	vector<int> ans(n);
	int rfirst = 0, rend = 0;
	bool flg = true;
	rep(i,n){
		if(flg){
			if(s.at(i) == 'R') rend = i;
			else flg = false;
		}
		else{
			if(s.at(i) == 'R'){
				ans.at(rend) += (i - 1 - (rend + 1) + 1) / 2;
				ans.at(rend + 1) += (i - 1 - (rend + 1)) / 2;
				ans.at(rend) += (rend - rfirst) / 2;
				ans.at(rend + 1) += (rend - rfirst + 1) / 2;
				ans.at(rend)++;
				ans.at(rend + 1)++;
				rfirst = i;
				rend = i;
				flg = true;
			}
		}
	}
	ans.at(rend) += (n - 1 - (rend + 1) + 1) / 2;
	ans.at(rend + 1) += (n - 1 - (rend + 1)) / 2;
	ans.at(rend) += (rend - rfirst) / 2;
	ans.at(rend + 1) += (rend - rfirst + 1) / 2;
	ans.at(rend)++;
	ans.at(rend + 1)++;
	rep(i,n){
		if(i == n - 1) cout << ans.at(i) << endl;
		else cout << ans.at(i) << " ";
	}
}


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

using namespace std;

int main() {
	vector<vector<int>> cs(3,vector<int>(3,0));
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			int c;
			cin >> c;
			cs[j][i] = c;
		}
	}

	bool flag = true;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < 2; ++j) {
			if (cs[j][i] - cs[j + 1][i] != cs[j][i+1] - cs[j + 1][i + 1]) {
				flag = false;
			}
			if (cs[j][i] - cs[j][i+1] != cs[j+1][i] - cs[j+1][i + 1]) {
				flag = false;
			}
		}
	}

	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }


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

    if(n%k==0) cout << 0 << endl;
    else cout << 1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin>>N;

	int R=N;
	N=N/2+N%2;
	double T=(double)N/R;
	cout<<T<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int l, r, d;

    cin >> l >> r >> d;

    cout << r / d - (l - 1) / d << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, c;
int main() {
	auto I = [](){int i;cin>>i;return i;};
	vector<int> S;
	cin >> n;
	while(n--) S.push_back(I());
	cin >> n;
	while(n--)
		if (binary_search(S.begin(), S.end(), I())) ++c;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1672
#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+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a);
  int m = a[n-1];
  vector<pair<int,int>> b(n-1);
  rep(i,n-1){
    if(m%2){
      int dif1 = abs(a[i] - (m+1)/2);
      int dif2 = abs(a[i] - m/2);
      b[i] = make_pair(min(dif1,dif2),a[i]);
    }
    else b[i] = make_pair(abs(a[i]-m/2),a[i]);
  }
  sort(b);
  cout << m << " " << b[0].second << endl;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int A,B;
	cin>>A>>B;
	cout<<(A-1)*(B-1)<<endl;
}


Measured memory_bytes: 256
#ABC167b
a, b, c, k = map(int, input().split())
# print(a, b, c, k)

if k <= a:
    ans = k*1
elif a<k<=a+b:
    ans = a
elif a+b<k<=a+b+c:
    ans = a - (k-a-b)

print(ans)


Measured memory_bytes: 9036
n, m = gets.chomp.split.map(&:to_i)

if n == 1
  n = 1
elsif n == 2
  n = 0
else
  n = n - 2
end

if m == 1
  m = 1
elsif m == 2
  m = 0
else
  m = m - 2
end

puts(n * m)

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

double EPS = 0.1;

bool D_EQ(double a,double b){
    return abs(a - b) < EPS;
}

int main(){
    int X;
    int N = 360;
    int ans = 0;
    
    cin >> X;
    
    while(N){
        N -= X;
        N = N < 0 ? N + 360 : N;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
int main() {
	int n;
	std::cin >> n;

	std::vector<int> v;
	v.resize(n);

	for (auto&e : v)
		std::cin >> e;




	auto find = [&](auto& f) {
		return
			std::find_if(std::begin(v), std::end(v), f);
	};

	auto not_zero
		= [&](auto x) { return x != 0; };

	auto it = find(not_zero);
//	auto it = std::begin(v);
	int count{};
	while (it != std::end(v)) {
		auto zp = std::find(it, std::end(v), 0);
		auto me = std::min_element(it, zp);
		
		/*
		std::cout <<"min_e = "<< (*me) << "\n";
		std::cout << "[ " << std::distance(std::begin(v), it) << ", ";
		std::cout << std::distance(std::begin(v),zp)<<" )" << "\n";
		*/

		auto min_v = *me;
		while (it != zp) {
			*it -= min_v;
			++it;
		}
		/*
		for (const auto&e : v)
			std::cout <<" "<< e;
		std::cout << "\n";
		*/
		count += min_v;
		it = find(not_zero);
	}

	std::cout << count << "\n";
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n,m;
vector<l_l> g[110000];
vector<ll> dist(110000,LINF);
void dijkstra(ll s){
    dist[s]=0;
    priority_queue<l_l,vector<l_l>,greater<l_l>> pq;
    pq.push({dist[s],s});
    while(pq.size()){
        ll now=pq.top().se;
        ll d=pq.top().fi;
        pq.pop();
        if(dist[now]<d)continue;
        for(auto nxt:g[now]){
            ll cost=nxt.se;
            ll to=nxt.fi;
            if(chmin(dist[to],dist[now]+cost)){
                pq.push({dist[to],to});
            }
        }
    }
}
int main(){
    cin>>n>>m;
    rrep(i,n-1){
        g[i+1].push_back({i,0ll});
    }
    rep(i,m){
        ll l,r,c;cin>>l>>r>>c;
        g[l].push_back({r,c});
    }
    dijkstra(1);
    if(dist[n]==LINF){
        cout<<-1<<endl;
    }
    else cout<<dist[n]<<endl;
    return 0;
}

Measured memory_bytes: 10488
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    string s;
    int k;
    cin >> n >> k >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    else if(s[k-1] == 'A') s[k-1] = 'a';
    else if(s[k-1] == 'B') s[k-1] = 'b';
    else if(s[k-1] == 'C') s[k-1] = 'c';
    else if(s[k-1] == 'D') s[k-1] = 'd';
    else if(s[k-1] == 'E') s[k-1] = 'e';
    else if(s[k-1] == 'F') s[k-1] = 'f';
    else if(s[k-1] == 'G') s[k-1] = 'g';
    else if(s[k-1] == 'H') s[k-1] = 'h';
    else if(s[k-1] == 'I') s[k-1] = 'i';
    else if(s[k-1] == 'J') s[k-1] = 'j';
    else if(s[k-1] == 'K') s[k-1] = 'k';
    else if(s[k-1] == 'L') s[k-1] = 'l';
    else if(s[k-1] == 'M') s[k-1] = 'm';
    else if(s[k-1] == 'N') s[k-1] = 'n';
    else if(s[k-1] == 'O') s[k-1] = 'o';
    else if(s[k-1] == 'P') s[k-1] = 'p';
    else if(s[k-1] == 'Q') s[k-1] = 'q';
    else if(s[k-1] == 'R') s[k-1] = 'r';
    else if(s[k-1] == 'S') s[k-1] = 's';
    else if(s[k-1] == 'T') s[k-1] = 't';
    else if(s[k-1] == 'U') s[k-1] = 'u';
    else if(s[k-1] == 'V') s[k-1] = 'v';
    else if(s[k-1] == 'W') s[k-1] = 'w';
    else if(s[k-1] == 'X') s[k-1] = 'x';
    else if(s[k-1] == 'Y') s[k-1] = 'y';
    else if(s[k-1] == 'Z') s[k-1] = 'z';
    cout << s << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    map<int,int> m;
    cin>>n;
    long long t=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        m[a]++;
        t+=a;
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        int cnt=m[b];
        m[b]=0;
        m[c]+=cnt;
        t+=cnt*(c-b);
        cout<<t<<'\n';
    }


    return 0;

}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***



Measured memory_bytes: 8040
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
    int n,m;
    int t[100]={},h[100]={},sumt=0,sumh=0,tmp=0,anst=10000,ansh=10000;

    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        t[100]={},h[100]={},sumt=0,sumh=0,tmp=0,anst=10000,ansh=10000;

        int jud=0;

        for (int i = 0; i < n; i++) {
            cin>>t[i];
            sumt+=t[i];
        }
        for (int i = 0; i < m; i++) {
            cin>>h[i];
            sumh+=h[i];
        }

        if(sumt>sumh){
            if((sumt-sumh)%2!=0){
                jud=1;
            }
            else {
                tmp=(sumt-sumh)/2;

                for (int it = 0; it < n; it++) {
                    for (int ih = 0; ih < m; ih++) {
                        if(t[it]-h[ih]==tmp){
                            if(ansh>h[ih]&&anst>t[it]){
                                ansh=h[ih];
                                anst=t[it];
                            }
                            jud=2;
                            break;
                        }
                    }
                }
            }

        }else{
            if((sumh-sumt)%2!=0){
                jud=1;
            }
            else {
                tmp=(sumh-sumt)/2;

                for (int ih = 0; ih < m; ih++) {
                    for (int it = 0; it < n; it++) {
                        if(h[ih]-t[it]==tmp){
                            if(ansh>h[ih]&&anst>t[it]){
                                ansh=h[ih];
                                anst=t[it];
                            }
                            break;
                        }
                    }
                }
            }

        }
        if(jud==1||ansh==10000||anst==10000)cout<<"-1\n";
        else cout<<anst<<" "<<ansh<<"\n";

    }
    
    return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
#define all(x) (x).begin(), (x).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define eb emplace_back
#define inf INT64_MAX
#define pii pair<int, int>

using namespace std;

const int mxn = 1e5 + 5;
int n, k, h[mxn], dp[mxn];

void solve()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> h[i];
    dp[0] = 0, dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = inf;
        for (int j = 1; j <= k and i - j >= 0; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
    cout << dp[n - 1];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//namespaces
using namespace __gnu_pbds; 
using namespace std;

//MACROS
#define ld long double
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long 
#define For(i,s,e) for (int i=(s); i<(e); i++)
#define Fod(i,s,e) for (int i=(s); i>=(e); i--)
#define pii pair<ll,ll>
#define f first
#define s second
#define endl "\n"
#define all(container) container.begin(), container.end()
#define mp make_pair
#define int ll

//debug
#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//Templates
template <typename T>
using ordered_set =tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }

//globals
ll const prime1 = 304933;
ll const prime2 = 15486277;
ll const mod = 1e9+7;
ll const inf = 1e18;
ll const size_1d = 1e6 + 7;
ll const size_2d = 1e3 + 7;

//functions
ll power(ll x, ll y, ll mod = 2e18){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){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;} 
ll gcdext(ll a,ll b,ll *x = 0, ll *y = 0){if(a == 0){*x = 0;*y = 1;return b;}ll x1,y1;ll gcd1 = gcdext(b%a,a,&x1,&y1);*x = y1 - (b/a)*x1;*y = x1;return gcd1;}
int randomize(){return (rand()%10000);} 

// CODE STARTS HERE

signed main(){
    IOS
    ll a,b,k;cin >> a>> b >> k;
    cout << max(0ll,a - k) << " " << max(b - max(-a + k,0ll),0ll) << endl;
    return 0;
}


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

namespace AtTest.ABC_135
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long[] ab = ReadLongs();
            long a = ab[0];
            long b = ab[1];
            if ((a + b) % 2 == 1)
            {
                WriteLine("IMPOSSIBLE");
            }
            else
            {
                WriteLine((a + b) / 2);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>
int sort(const void *a,const  void *b)
{
  return *(int *)a - *(int *)b;
}
int main(){
  int i,n,a[200010],s[200010];
  int min,j,tmp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    s[i]=a[i];
  }
  qsort(s,n,sizeof(int),sort);
  for(i=0;i<n;i++){
    if(a[i]<=s[n/2-1])
      printf("%d\n",s[n/2]);
    else
      printf("%d\n",s[n/2-1]);
  }
  return 0;
}

Measured memory_bytes: 3704