akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1
 
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;
 
    int N,K,A[101],ans;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N)cin>>A[i];
    REP(i,N){
        ans+=std::min(abs(A[i]-K),A[i])*2;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
	vector<ll> argA(3);
	for (ll i = 0; i < 3; ++i) {
		cin >> argA.at(i);
	}

	sort(argA.begin(), argA.end());

	ll firstOp = argA.at(2) - argA.at(1);
	ll diff = argA.at(2) - argA.at(0) - firstOp;
	ll secondOp = diff % 2 == 0 ? diff / 2 : diff / 2 + 2;

	cout << firstOp + secondOp << endl;
}

Measured memory_bytes: 632
#include <iostream>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
#define foR(i,x,y) for(register int i=(x); i>=(y); i--)
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+10;
typedef long long ll;
ll pre[maxn],suf[maxn];
int main()
{
    int n,k;
    cin>>n>>k;
    For(i,1,n+1)pre[i]=pre[i-1]+i-1;
    foR(i,n+1,1)suf[i]=suf[i+1]+i-1;
    ll ans=0;
    For(i,k,n+1)
    {
        ans=ans+suf[n+2-i]-pre[i]+1;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6704
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[MAX];
  
  for(i=0; i<N; i++) cin >> a[i];
  
  ll cnt[MAX]={};
  map<ll, ll, greater<>> mp;
  map<ll, ll> cp;
  for(i=N-1; i>=0; i--) {
    mp[a[i]]=i;
    cp[a[i]]++;
  }
  mp[0]=-1;
  
  ll t=0;
  ll p=N-1;
  for(auto it=mp.begin(); it!=mp.end(); it++) {
    if(it->first==0) continue;
    
    auto nt=it; nt++;
    ll A=it->first, B=nt->first;
    t+=cp[A];
    chmin(p, mp[A]); //mp[A]:it->second
    
    cnt[p]+=t*(A-B);
  }
  
  for(i=0; i<N; i++) pt(cnt[i]);
}



Measured memory_bytes: 15104
class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
end

n, m = gets.strip.split.map(&:to_i)
ps = gets.strip.split.map(&:to_i)
xy = readlines.map {|line| line.strip.split.map(&:to_i) }

uf = UnionFind.new(n+1)

xy.each do|x, y|
  uf.unite(x,y)
end

result = 0
ps.each_with_index do|p, i|
  ci = i+1
  result += 1 if uf.same_parent?(ci, p)
end

p result





Measured memory_bytes: 19636
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int i = 0; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 K, N;
    cin >> K >> N;
    vector<i64> A(N);
    rep(i, N) cin >> A[i];

    i64 ans = A[N-1] - A[0];
    for(int i = 1; i < N-1; i++){
        ans = min({ans, K - (A[i] - A[i-1]), K - (A[i+1] - A[i])});
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvii;
typedef pair<int, int> ii;
typedef vector<ii> vii;

////////////////////////////////

void solve() {
	
}

const ll INF = 1e9 + 5;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, w;
	cin >> n >> w;
	vector<int> weight(n), value(n);
	for (int i=0; i<n; ++i) {
		cin >> weight[i] >> value[i];
	}
	ll valsum = 0;
	for (auto& v : value) valsum += v;
	vector<ll> dp(valsum + 1, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int curVal = valsum - value[i]; curVal >= 0; --curVal) {
			dp[curVal + value[i]] = min(dp[curVal + value[i]], dp[curVal] + weight[i]);
		}
	}
	ll ret = 0;
	for (ll i = 0; i <= valsum; ++i) {
		if (dp[i] <= w) ret = max(ret, i);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll H, W, h, w; cin >> H >> W >> h >> w;
    cout << H * W - h * W - H * w + h * w << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,m,k;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
   cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
 cin>>n>>m>>k;
 cout<<min(n*m,k)<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
	int n, v;
	int a[101];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		v = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		
		cout << a[0];
		for(int i = 1; i < n; i++){
			cout << ' ' << a[i];
		}
		cout << endl;
	}
	return 0;
}

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

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

int main() {
    std::cout<<std::fixed<<std::setprecision(5);
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    float tmp = 0;
    rep(i, n) {
        tmp += (1.0/a[i]);
    }

    float ans = 1.0/tmp;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

module IntSet = Set.Make(struct
  type t = int
  let compare = (-)
end)

let () =
  let n = read_int () in
  let xs = read_ints n in
  List.fold_left (fun s x ->
    if IntSet.mem x s then IntSet.remove x s else IntSet.add x s)
  IntSet.empty xs
  |> IntSet.elements |> List.length
  |> printf "%d\n"


Measured memory_bytes: 14496
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		if(n == 0)
			break;
			
		int scoreA = 0, scoreB = 0;
		for(int i =0;i<n;i++)
		{
			int a, b;
			cin>>a>>b;
			if(a > b)
				scoreA+=(a+b);
			else if(b > a)
				scoreB+=(a+b);
			else
				scoreA+=a, scoreB+=b;
		}
		cout<<scoreA<<" "<<scoreB<<endl;
	}
	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++)
    {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    vector<int> prime(1000001,0);
    int ans=0;
    for (int i=0;i<N;i++)
    {
        if (A[0]==1) break;
        if (prime[A[i]]==0)
        {
            if (i+1<N)
            {
                if (A[i+1]!=A[i]) ans++;
            }
            else ans++; 
        }
        for (int j=A[i];j<1000001;j+=A[i])
        {
            prime[j]=1;
        }
    }
    if (A[0]==1)
    {
        if (1<N)
        {
            if (A[0]!=A[1]) ans++;
        }
        else ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8008
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


vector<int> v;
void generate_sosu(){
	v.push_back(2);
	rep(i,2,250000){
		rep(j,0,v.size()){
			if(i%v[j]==0)break;
			if(j==v.size()-1)v.push_back(i);
		}
	}
	return;
}


int main(){
	generate_sosu();
	while(1){
		int n;
		int ans,s=0,e=0;
		cin>>n;
		if(n==0)break;
		rep(i,0,v.size()){
			if(v[i]<=n)s=i+1;
			if(v[i]>2*n){
				e=i;
				break;
			}
		}
		ans=e-s;
		print(ans);
	}
	return 0;
}


Measured memory_bytes: 3216
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    Ls, Rs = [], []
    for i in range(N):
        a, b = list(map(int, input().split()))
        Ls.append(a), Rs.append(b)
    Ls.sort(), Rs.sort()

    ans = 0
    if N%2 == 1:
        # Nが奇数なら
        l = Ls[N//2]
        r = Rs[N//2]
        ans = r-l+1
    else:
        # Nが偶数なら
        l2 = Ls[N//2-1]+Ls[N//2]
        r2 = Rs[N//2-1]+Rs[N//2]
        ans = r2-l2+1

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 25400
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)





int main() {
	ll n,l;
	in(n);
	in(l);
	vector<string> s(n);
	rep(i, 0, n) {
		in(s[i]);
	}
	sort(s.begin(), s.end());
	rep(i, 0, n) {
		out(s[i]);
	}
	outn("");
	
	return 0;

}


Measured memory_bytes: 256
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

a, b = mi()

if a<=0 and b>=0: print("Zero")
elif a>0: print("Positive")
else:
  #このパターンのみ、+と-が入り交じる
  #数が偶数なら+で、奇数なら-
  if (b-a+1)%2==0: print("Positive")
  else: print("Negative")





Measured memory_bytes: 3832
N, M = map(int, input().split())

Hs = list(map(int, input().split()))
A = [True for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())

    if Hs[a-1] == Hs[b-1]:
        A[a-1] = A[b-1] = False
    if Hs[a-1] > Hs[b-1]:
        A[b-1] = False
    if Hs[a-1] < Hs[b-1]:
        A[a-1] = False


print(sum(A))

Measured memory_bytes: 20120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll N, H, W;
	cin >> N >> H >> W;
	vector<ll> A(N), B(N);
	int count = 0;
	rep(i, N) {
		cin >> A[i] >> B[i];
		if (A[i] >= H && B[i] >= W) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector< pair<int, pair<int,int> > > fs;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		fs.pb( mp( a+b, mp(a,b) ) );
	}
	sort( fs.begin(), fs.end() );
	reverse( fs.begin(), fs.end() );
	int ans = 0;
	for(int i=0;i<n;i++){
		if( i % 2 == 0 ){
			ans += fs[i].second.first;
		}
		else{
			ans -= fs[i].second.second;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int A,B,K; cin >> A >> B >> K;
    int cnt = 0;
    int d = min(A,B);
    int ans = 1;
    while(cnt < K){
        if(A%d == 0 && B%d==0){
            cnt++;
            ans = d;
        }
        d--;
    }
    cout << ans << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  vector<ll> p(n);
  REP(i, n)
  {
    cin >> p[i];
  }
  ll cnt = 0;
  for (ll i = 1; i < n - 1; i++)
  {
    if ((p[i] > p[i + 1] && p[i] < p[i - 1]) || (p[i] > p[i - 1] && p[i] < p[i + 1]))
    {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using plglg = pair<ll, ll>;
using tlglglg = tuple<ll, ll, ll>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);

    ll reach_cnt = x / d;
    ll ans;
    ll d1, d2;
    if (k <= reach_cnt) {
        ans = x - k * d;
    } else {
        k -= reach_cnt;
        d1 = x - reach_cnt * d;
        d2 = abs(d1 - d);
        if (k % 2 == 0) {
            ans = d1;
        } else {
            ans = d2;
        }
    }
    print(ans);

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  std::string S; cin >> S;
  int cnt = 0;
  for (char x : S) if (x == 'o') ++cnt;

  cnt += 15 - S.size();
  if (cnt >= 8) cout << "YES" << endl;
  else          cout << "NO" << endl;
}


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

int main(){
	int x, y, s;
	int f[10][10];
	
	memset(f, 0, sizeof(f));
	
	while( scanf(" %d,%d,%d", &x, &y, &s) != EOF ){
		if(s==1){
			for(int i=y-1; i<=y+1; ++i){
				int a=0;
				if(i==y) a=1;	
				for(int j=x-a; j<=x+a; ++j){
					if(i>=0 && i<10 && j>=0 && j<10) f[i][j]++;
				}	
			}
		}
		else if(s==2){
			for(int i=y-1; i<=y+1; ++i){
				for(int j=x-1; j<=x+1; ++j){
					if(i>=0 && i<10 && j>=0 && j<10) f[i][j]++;
				}
			}	
		}
		else if(s==3){
			for(int i=y-2; i<=y+2; ++i){
				int a=y-i;
				if(a<0) a=-a;
				a=a-2;
				if(a<0) a=-a;	
				for(int j=x-a; j<=x+a; ++j){
					if(i>=0 && i<10 && j>=0 && j<10) f[i][j]++;
				}	
			}
		}
	}
	
	int max=0, count=100;
	for(int i=0; i<10; ++i){
		for(int j=0; j<10; ++j){
			//printf("%d", f[i][j]);
			if(f[i][j]>0) count--;
			if(f[i][j]>max) max=f[i][j];
		}
		//printf("\n");
	}
	
	printf("%d\n%d\n", count, max);
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[100000];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int *x;
  x=unique(a,a+n);
  int d = distance(a, x);
  for(int i=0;i<d;i++){
    if(i!=0) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  return 0;
}


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

int main(){
    long long N , K;
    cin >> N >> K;
    long long x = N,y = 0,z = 1;
    string sy;
    string ans = "";
    while (x > 0){
        y = (x % K);
        sy = to_string(y);
        ans = sy + ans;
        x /= K;
        z *= 10;
    }
    cout << ans.length() << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
void solve(void)
{
	int n;
	int max=0, min=INT_MAX;
	int i;
	scanf("%d", &n);
	for(i=0;i<n;++i){
		int a;
		scanf("%d", &a);
		if(a>max)max=a;
		if(a<min)min=a;
	}
	printf("%d\n", max-min);
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


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

using namespace std;

vector<string> ss;


int main(){
  	int n, l;
  string s;
 	cin>>n>>l; 
  
  for(int i = 0; i<n;i++){
   cin>>s;
    ss.push_back(s);
  }
  
  sort(ss.begin(),ss.end());
  
  
  for(int i = 0; i<n;i++){
	cout<<ss[i];
  }
  
  cout<<"\n";
  
  return 0;
  
  
  
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACantWaitForHoliday solver = new ACantWaitForHoliday();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACantWaitForHoliday {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String str = s.nextString();
            if (str.equals("SUN")) {
                out.println(7);
            } else if (str.equals("MON")) {
                out.println(6);
            } else if (str.equals("TUE")) {
                out.println(5);
            } else if (str.equals("WED")) {
                out.println(4);
            } else if (str.equals("THU")) {
                out.println(3);
            } else if (str.equals("FRI")) {
                out.println(2);
            } else {
                out.println(1);
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 23508
a,b = map(int,input().split())
s = input()
ok = True
if s[a] != '-': ok = False
for i in range(a):
    if s[i] == '-': 
        ok = False
        break
for i in range(a+1,a+b+1):
    if s[i] == '-':
        ok = False
        break
if ok == 1: print("Yes")
else: print("No")

Measured memory_bytes: 3064
while True:
  try:
      A=[]
      for i in range(5):
        s1,s2=map(int,input().split())
        if s1==0 and s2==0:
          break
        s=s1+s2
        A.append(s)
      if s==0:
        break
      for i in range(len(A)):
        if A[i]==max(A):
          if i==0:
            print("A",A[i])
          if i==1:
            print("B",A[i])
          if i==2:
            print("C",A[i])
          if i==3:
            print("D",A[i])
          if i==4:
            print("E",A[i])
  except EOFError:
      break
  


Measured memory_bytes: 5604
import math
A,B,H,M = map(int,input().split(" "))

a_angle = 360*H/12 + 15*2*M/60
b_angle = 360*M/60

angle = a_angle - b_angle
if angle>180:
    angle = 360 - angle

ans = A**2 + B**2 - 2*A*B*math.cos(math.radians(angle))
print(ans**0.5)

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

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

    long long int cumul[N + 1];
    cumul[0] = 0;
    for (long long int i = 0; i < N; ++i) {
        cumul[i + 1] = cumul[i] + recorder[i];
    }

    unordered_map<long long int, long long int> cntmap;

    for (auto A : cumul) {
        if (cntmap.count(A) == 0) {
            cntmap[A] = 1;
        } else {
            ++cntmap[A];
        }
    }

    long long int ans = 0;
    for (auto kv : cntmap) {
        ans += kv.second * (kv.second - 1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 11592
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

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

	bool ans = true;
	int s = x * 2;
	for (int i = 0; i < x; ++i)
	{
		if (s == y)
			break ;
		s += 2;
	}
	if (s != y)
		ans = false;
	cout << (ans ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int[] price = new int[4];
	price[0] = sc.nextInt();
	price[1] = sc.nextInt();
	price[2] = sc.nextInt();
	for(int a = 1; a >= 0;a--){
		for(int b = 0; b <=a;b++){
			if(price[b]>price[b+1]){
				price[3] = price[b];
				price[b] = price[b+1];
				price[b+1] = price[3];
			}
		}
	}
	System.out.println(price[0]+" "+price[1]+" "+price[2]);
	}
}

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

int n;
vector<int> a;

int gcd(int a, int b) {
  int A = max(a, b);
  int B = min(a, b);
  if (A < 1 || B < 1) {
    return A;
  }
  return gcd(B, A % B);
}

int solve() {
  int i, ans = 0;
  bool check = false;

  sort(a.begin(), a.end());

  ans = a[0];

  for (i = 1; i < n; i++) {
    a[i] %= ans;
  }

  for (i = 1; i < n; i++) {
    if (a[i] != 0) {
      check = true;
      ans = gcd(a[i], ans);
    }
  }
  if (check == false) {
    ans = a[0];
  }
  return ans;
}

int main() {
  int i;

  cin >> n;
  a.resize(n);
  for (i = 0; i < n; i++) {

    cin >> a[i];
  }

  cout << solve() << "\n";
  return 0;
}

Measured memory_bytes: 768
from collections import deque
N = int(input())
A = [deque(map(lambda x: int(x)-1,input().split(" "))) for _ in range(N)]
ans = 0
used_prev = set(range(N))

while any(A):
    used = set()
    for i in used_prev:
        a = A[i]
        if not a or i in used:
            continue
        j = a[0]
        b = A[j]
        if not b or j in used:
            continue
        if i == b[0]:
            A[i].popleft()
            A[j].popleft()
            used.add(i)
            used.add(j)
    if not used:
        ans = -1
        break
    used_prev = used
    ans += 1
print(ans)

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

//const ll mod = static_cast<int>(1e9 + 7);



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

	int cnt_nega = 0;
	ll ans = 0;
	ll min_num = 2002002002;
	for (int i = 0; i < N; ++i) {
		ll tmp;
		cin >> tmp;
		A_abs[i] = abs(tmp);
		ans += abs(tmp);
		min_num = min(min_num, abs(tmp));
		if (tmp < 0) {
			++cnt_nega;
		}
	}

	if (cnt_nega % 2 == 1) {
		ans -= min_num * 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  cin >> s;
  rep(i,s.size()) if(s[i]==',') s[i]=' ';
  pr(s);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
int f[5][4005],a[3]={10,2,1},b[5];
int F(int x,int y)
{
	if(y==0) return 1;
	if(x<0) return 0;
	if(f[x][y]!=-1) return f[x][y];
	f[x][y]=0;
	for(int i=0;i<=b[x] && a[x]*i<=y;i++)
		f[x][y]+=F(x-1,y-a[x]*i);
	return f[x][y];
}
int main()
{
	memset(f,-1,sizeof f);
	f[0][0]=1;
	int x;
	for(int i=0;i<3;i++)
		scanf("%d",&b[i]);
	scanf("%d",&x);x/=50;
	printf("%d\n",F(2,x));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n, a[10001], i;
	int min, max;
	long long sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	min = a[0];
	max = a[0];
	for (i = 0; i < n; i++) {
		if (min > a[i])min = a[i];
		if (max < a[i])max = a[i];
		sum += a[i];
	}
	printf("%d %d %ld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 2748
#include<iostream>
#include<cstdio>
#define MAX 100001
using namespace std;

int A[MAX];
int n;

void add(int x, int y){
    int add = A[x];
    A[x] = add + y;
}

void getSum(int x, int y){
    
    int sum = 0;
    
    for(int i=x; i<=y; i++){
        sum = sum + A[i];
    }
    cout << sum << endl;
    
    
}


int main(){
    int q, a, b, com;
    
    /*int fir = 1;
    for(int i=0; i<31; i++){
        fir = fir*2;
    }
    fir = fir -1;*/
    
    cin >> n >> q;
    for(int i=0; i<n; i++){
        A[i]  = 0;
    }
    
    for(int i=0; i<q; i++){
        cin >> com >> a >> b;
        
        if(com == 0){
            add(a, b);
        }else if( com == 1){
            getSum(a,b);
        }
    }
    
    return 0;
}



Measured memory_bytes: 3480
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        System.out.println(N*N*N);
    }
    
    public static void solver() {
        // write logic
    }
    
    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 22740
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int INFTY = int.MaxValue;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] table = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int u = int.Parse(input[0]) - 1;
                int k = int.Parse(input[1]);

                for (int j = 0; j < k; j++)
                {
                    int v = int.Parse(input[2 + j]) - 1;

                    table[u, v] = 1;
                }
            }

            Dijkstra(table, n);
        }

        static void Dijkstra(int[,] table, int n)
        {
            int i, minCost;
            int[] minCostArr = Enumerable.Repeat(INFTY, n).ToArray();
            bool[] isVisit = new bool[n];

            minCostArr[0] = 0;

            while (true)
            {
                minCost = INFTY;
                int u = -1;

                for (i = 0; i < n; i++)
                {
                    if (!isVisit[i] && minCost > minCostArr[i])
                    {
                        u = i;
                        minCost = minCostArr[i];
                    }
                }

                if (u == -1) break;

                isVisit[u] = true;

                for (i = 0; i < n; i++)
                {
                    int w = table[u, i];

                    if (w > 0)
                    {
                        int c = minCostArr[u] + w;

                        if (c < minCostArr[i])
                        {
                            minCostArr[i] = c;
                        }
                    }
                }
            }

            StringBuilder sb = new StringBuilder();
            for (i = 0; i < n; i++)
            {
                int temp = minCostArr[i] == INFTY ? -1 : minCostArr[i];
                sb.AppendLine((i + 1) + " " + temp);
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9440
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, x = map(int, readline().split())
xx = list(map(int, readline().split()))
gcd_ans = abs(x - xx[0])
for i in range(1, n):
    gcd_ans = gcd(gcd_ans, abs(x - xx[i]))
print(gcd_ans)


Measured memory_bytes: 14532
import java.util.*;

class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      
      	if(a*n >= b){
        	System.out.println(b);
        }else{
        	System.out.println(a*n);
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int x,a;
    cin>>x>>a;
    int ans;
    if(x<a){
        ans=0;
    }else{
        ans=10;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3552
#include <iostream>
using namespace std;
int main(){
  string s,t;
  cin >> s;
  cin >> t;
  for(int i=0; i<3; i++){
    if(s[i] != t[2-i]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=201000;
const int K=20;
double EPS=1e-12;
typedef long long ll;
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)

int32_t main()	
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c;
	cin>>a>>b>>c;
	// cout<<fixed<<setprecision(7)<<sqrt(a)+sqrt(b)-sqrt(c)<<" "<<EPS<<"\n";
	// cout<<4LL*a*b<<" "<<(c-a-b)*(c-a-b)<<"\n";
	if(a+b<c && 4LL*c*b<(c-a+b)*(c-a+b))
		cout<<"Yes\n";
	else
		cout<<"No\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> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W;
char C[400][400];
int di[4] = {0,1,0,-1}, dj[4] = {1,0,-1,0};
bool visited[400][400];
ll ans = 0, b = 0, w = 0;

int DFS(int i, int j){
  if (visited[i][j]) return 0;
  visited[i][j] = true;

  if (C[i][j] == '.') w++;
  else b++;

  for (int k = 0; k < 4; k++){
    int I = i + di[k], J = j + dj[k];
    if (0 <= I && I < H && 0 <= J && J < W){
      if (visited[I][J]) continue;
      if (C[i][j] != C[I][J]) DFS(I, J);
    }
  }
  return 0;
}


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

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (visited[i][j]) continue;
      b = 0; w = 0;
      DFS(i, j);
      ans += b * w;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

string s;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>s;
    int n = s.size();
    int ans = 9999;
    REP(i,n-3+1){
        int tmp = 0;
        tmp += (s[i]-'0')*100;
        tmp += (s[i+1]-'0')*10;
        tmp += (s[i+2]-'0');

        ans = min(ans, abs(753-tmp));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;
  vi A(N);
  cin >> A;
  i64 ans = 0;
  i64 b = 0;
  rrep(i,N-1,-1){
    if(A[i]>i or A[i]<b){
      ans = -1;
      break;
    }
    if(A[i]>b){
      ans += A[i];
      b = A[i];
    }
    b--;
  }
  cout << ans << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
int main(void) {
    int n,i,j;
    while (scanf("%d",&n)!=EOF) {
        int sieve[n+1],count=0;
        for (i=2; i<=n; i++) sieve[i]=0;
        for (i=2; i<=sqrt(n); i++) {
            if (sieve[i]==0) {
                for (j=i*2; j<=n; j+=i) sieve[j]=1;
            }
        }
        if (n%2==0) {
            for (i=2; i<=n/2; i++) {
                if (sieve[i]==0&&sieve[n+1-i]==0) count++;
            }
            printf("%d\n",count*2);
        } else {
            for (i=2; i<=n/2; i++) {
                if (sieve[i]==0&&sieve[n+1-i]==0) count++;
            }
            if (sieve[n/2+1]==0) {
                printf("%d\n",count*2+1);
            } else {
                printf("%d\n",count*2);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 632
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

int n, k, a[6000];
bool c[6000], d[6000];
vector<int> u[6000];
int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);

	c[0] = true;
	u[n].emplace_back(0);
	for (int i = n - 1; 0 <= i; i--) {
		for (int w = k - 1; 0 <= w; w--)
			if (c[w] && w + a[i] < k)
				c[w + a[i]] = true;
		for (int w = 0; w < k; w++)
			if (c[w])
				u[i].emplace_back(w);
	}

	int count = 0;
	d[0] = true;
	for (int i = 0; i < n; i++) {
		bool any = false;
		for (int w = 0; w < k && (!any); w++) {
			if (!d[w])
				continue;
			int p = lower_bound(u[i + 1].begin(), u[i + 1].end(), k - w) - u[i + 1].begin();
			if (p <= 0)
				continue;
			if (k <= u[i + 1][p - 1] + w + a[i])
				any = true;
		}
		if (!any)
			count++;
		for (int w = k - 1; 0 <= w; w--)
			if (d[w] && w + a[i] < k)
				d[w + a[i]] = true;
	}
	printf("%d\n", count);
}

Measured memory_bytes: 116480
#include<bits/stdc++.h>
#define f first
#define s second
#define inf 999999999999
#define N  500009
#define M  (L+R)/2
#define ll long long
#define pb push_back
using namespace std;

ll n,ans,sum,fix[40],a[N];
string s;

int main()
{

	ios::sync_with_stdio(0);
	
	cin>>n>>s;
	
	for(int i=0;i<n;i++){
		a[i+1]=s[i]-'a'+1;
	}
	
	for(int i=1;i<=n;i++){
		sum=1;
		for(int j=1;j<=30;j++){
			if(j==a[i])continue;
			sum*=(fix[j]+1);
			sum%=1000000007;
		}
		ans+=sum;
		ans%=1000000007;
		fix[a[i]]++;
	}
	ans%=1000000007;
	cout<<ans<<endl;
return 0;
}






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

int main() {
  int s;
 
  cin >> s;
  if(400 <= s && s<600){
      cout << 8;
    }else if(600 <= s && s<800){
    cout << 7;
  }else if(800 <= s && s<1000){
    cout << 6;
  }else if(1000 <= s && s< 1200){
    cout << 5;
  }else if(1200 <= s && s<1400){
    cout << 4;
  }else if(1400 <= s && s<1600){
    cout << 3;
  }else if(1600 <= s && s< 1800){
    cout <<2;
  }else if(1800 <= s && s< 2000){
    cout << 1;
  }
    
    
}


Measured memory_bytes: 3632