akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define repi(i,a,n) for(int i = (int)a; i < (int)(n); i++)

typedef long long ll;

int main(void){
    int n;
    double x[9]={0};
    double y[9]={0};
    std::vector<int> v;
    
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        std::cin >> x[i] >> y[i];
    }
    for (int i = 1; i <= n; i++) {
        v.push_back(i);
    }
    int a=1;
    repi(i,1,n+1){
        a*=i;
    }
    
    double sum=0;
    do{
        for (int i = 0; i < n-1; i++) {
            sum+=sqrt(pow(x[v[i]]-x[v[i+1]],2.0)+pow(y[v[i]]-y[v[i+1]],2.0));
        }
    }while(std::next_permutation(all(v)));
    std::cout <<std::fixed<< std::setprecision(10)<<sum/a << std::endl;
    
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    long long K;
    int N;
    cin >> K >> N;
    long long A[N];
    for(int i=0;i<N;++i) cin >> A[i];
    sort(A,A+N);
    long long ans=A[N-1]-A[0];
    for(int i=0;i<N-1;++i){
        ans=min(ans,K+A[i]-A[i+1]);
    }
    cout << ans << endl; 
}

Measured memory_bytes: 1792
#define ll long long

#include "bits/stdc++.h"

using namespace std;
static const int INF = (1 << 21);

int main() {
	int n;
	cin >> n;
	vector<int> A(n), B(n), C(n);
	for (int i = 0;i < n;i++) {
		scanf("%d",&A[i]);
	}
	sort(A.begin(),A.end());
	for (int i = 0;i < n;i++) {
		scanf("%d", &B[i]);
	}
	sort(B.begin(), B.end());
	for (int i = 0;i < n;i++) {
		scanf("%d", &C[i]);
	}
	sort(C.begin(), C.end());
	
	ll sum = 0;

	decltype(A)::iterator memo1 = A.begin();

	decltype(C)::iterator memo2 = C.begin();
		
	for (int i = 0;i < n;i++) {
		
		decltype(A)::iterator ite = lower_bound(memo1, A.end(), B[i]);
		memo1 = ite;
		decltype(C)::iterator itete = upper_bound(memo2, C.end(), B[i]);
		memo2 = itete;
		sum += ((ite - A.begin()))*(n-(itete-C.begin()));
	}

	cout << sum << endl;
}



Measured memory_bytes: 1536
def resolve():
    n, k = map(int, input().split())
    S = []
    L, R = [], []
    for _ in range(k):
        l1, r1 = map(int, input().split())
        L.append(l1)
        R.append(r1)

    dp = [0 for i in range(n + 1)]
    dpsum = [0 for i in range(n + 1)]
    dp[1] = 1
    dpsum[1] = 1
    for i in range(2, n + 1):
        for j in range(k):
            Li = i - R[j]
            Ri = i - L[j]
            if Ri < 0:
                continue
            Li = max(1, Li)
            dp[i] += dpsum[Ri] - dpsum[Li - 1]  # dp[Li] ~ dp[Ri]
            dp[i] %=  998244353

        dpsum[i] = (dpsum[i - 1] + dp[i]) % 998244353

    print(dp[n])

resolve()

Measured memory_bytes: 24412
while True:
	s,t = map(int,input().split())
	if s == 0 and t == 0:	
		break
	a = list(map(int,input().split()))
	a.sort()
	list1 = []
	for i in range(s):
		for j in range(i + 1, s):
		 	price1 = a[i] + a[j]
		 	list1.append(price1)
	list1.sort()
	list2 = list(filter(lambda p: t >= p, list1))


	if list2:
		print(max(list2))
	else:
		print("NONE")	



Measured memory_bytes: 31084
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
const int N = 4e5 + 42;
i64 fen[N];
void add(int i, i64 v) {
  for (i += 2; i < N; i += i & -i) fen[i] += v;
}
i64 get(int i) {
  i64 r = 0;
  for (i += 2; i > 0; i -= i & -i) r += fen[i];
  return r;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  i64 n, d, t;
  cin >> n >> d >> t;
  vector<i64> a(n), b(n);
  {
    vector<pair<int,int>> c(n);
    for (int i = 0; i < n; ++i) {
      cin >> c[i].first >> c[i].second;
    }
    sort(ALL(c));
    for (int i = 0; i < n; ++i) a[i] = c[i].first, b[i] = c[i].second;
  }
  i64 ans = 0;
  for (int i = 0; i < n; ++i) {
    i64 val = b[i] + get(i);
    if (val <= 0) continue;
    i64 upd = (val + t - 1) / t;
    ans += upd;
    upd *= t;
    add(i, -upd);
    add(upper_bound(ALL(a), a[i] + 2 * d) - a.begin(), upd);
  }
  kek(ans);
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

double p[200010];
double ans, tmp;
int k, n;

int main()
{
    read(n), read(k);
    for (int i = 1; i <= n; ++i)    std::cin >> p[i], p[i] = (p[i] + 1) / 2;
    for (int i = 1; i <= k; ++i)    ans += p[i];
    tmp = ans;
    for (int i = k + 1; i <= n; ++i)
    {
        tmp -= p[i - k];
        tmp += p[i];
        ans = std::max(ans, tmp);
    }
    printf("%.12lf\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define pos position<int>
#define at_(p) at(p.x).at(p.y)

#define GCD(v) gcd(ALL(v), 0l)

template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}

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

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


int main(){
  int a;long long b,n;
  cin>>a>>b>>n;
  int c=a%b;
  long long d=min(n,b-1);
  cout<<double(a*d-(c*d)%b)/b;
}


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

struct Edge {
	int from, to, distance;
};

int main()
{
	int l;
	scanf("%d", &l);

	std::vector<Edge> edges;
	int n;
	for (int i = 0; (1 << (i + 1)) <= l; i++)
	{
		edges.push_back((Edge){i, i + 1, 0});
		edges.push_back((Edge){i, i + 1, 1 << i});
		n = i + 1;
	}
	for (int i = 0; (1 << (i + 1)) <= l; i++)
	{
		if (!((1 << i) & l)) continue;
		edges.push_back((Edge){i, n, (l & ~((1 << i) - 1) - (1 << i))});
	}
	
	printf("%d %d\n", n + 1, edges.size());
	for (auto &e: edges)
	{
		printf("%d %d %d\n", e.from + 1, e.to + 1, e.distance);
	}

	return 0;
}

Measured memory_bytes: 256
c = [list(map(int,input().split())) for _ in range(3)]
b = c[0]
a = [0]
for i in range(1,3):
    a.append(c[i][i]-b[i])
for i in range(3):
    for j in range(3):
        if c[i][j] != a[i] + b[j]:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 10000000;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main() {
  ll n;
  cin>>n;
  vecll h(n+1,0);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vecll dp(n+1,0);
  // int b=0;
  for(int i=1;i<n;i++){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  // for(int i=0;i<=n;i++){
  //   cout<<dp[i];
  // }
  // cout<<endl;
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

s,w = inp
puts (s <=w)? "unsafe" : "safe"

Measured memory_bytes: 14436
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let [a,b]=[nin(),sin()]
  out(a>=3200?b:"red")
}
main()

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;

bool solve() {
    ll N, P;
    cin >> N >> P;
    if(!(N + P)) return false;

    V<ll> has(N);
    ll cup = P;

    while(true) {
        bool suc = false;
        for(ll i = 0; i < N; i++) {
            if(cup > 0) {
                cup--;
                has[i]++;
                if(has[i] == P) {
                    cout << i << endl;
                    suc = true;
                    break;
                }
            } else {
                cup += has[i];
                has[i] = 0;
            }
        }
        if(suc) break;
    }
    return true;
}

int main() {
    while(solve());
    return 0;
}



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

int main() {
  int N, K, a=1, i;
  cin >> N >> K;
  for(i=0; i<N; i++) {
    if((a * 2) <= (a + K)) {
      a *= 2;
    } else {
      a += K;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
X, Y = map(int,input().split()) 
cnt=0
for turu in range(0, X+1):
    for kame in range(0, X+1):
        if turu + kame == X:
            if Y == turu * 2 + kame * 4:
                print('Yes')
                cnt+=1
if cnt == 0:
    print('No')

Measured memory_bytes: 9184
import sys
 
nCr_memo = {}
 
def solve(n, k):
    for i in range(k):
        i += 1
        ans = nCr(n - k + 1, i) * nCr(k - 1, i - 1)
        print  ans % (10**9 + 7)
 
 
def nCr(n, r):
    key = str(n) + '_' + str(r)
    if key in nCr_memo:
        return nCr_memo[key]
 
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
 
    nCr_memo[key] = a / b
    return nCr_memo[key]
 
 
if __name__ == '__main__':
 
    n, k = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, k)

Measured memory_bytes: 36252
#include <iostream>
#include <vector>
#include <functional>

template<typename T> struct segment_tree {
private :
	int N;
	std::vector<T> value;
public :
	const std::function<T(T, T)> op;
	const T id;

	segment_tree(const std::vector<T>& a, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int n = a.size(), m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
		for (int i = 0; i < n; i++) value[N + i] = a[i];
		for (int i = N - 1; i > 0; i--) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	segment_tree(const int& n, const std::function<T(T, T)>& f, const T& t) : op(f), id(t) {
		int m = 1;
		while (m < n) m *= 2;
		value.resize((N = m) * 2, id);
	}

	inline const int& size()const{return N;}

	void point_update(int i, const std::function<T(T, T)>& f, const T& t) {
		i += N;
		value[i] = f(value[i], t);
		while (i /= 2) value[i] = op(value[i * 2], value[i * 2 + 1]);
	}

	T range_fold(const int& L, const int& R, const int& i = 1, const int& l = 0, int r = -1) {
		if (r == -1) r = N;
		if (L <= l && r <= R) return value[i];
		if (r <= L || R <= l) return id;
		return op(
			range_fold(L, R, i * 2, l, (l + r) / 2),
			range_fold(L, R, i * 2 + 1, (l + r) / 2, r)
		);
	}

	inline const T& operator[](const int& i)const{return value[N + i];}
};

int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<long long> a(n);
	for (int i = 0; i < n; i++) std::cin >> a[i];

	segment_tree<long long> sg(a, [](long long a, long long b){return a + b;}, 0);
	while (q--) {
		int op;
		std::cin >> op;
		if (op == 0) {
			int p; long long x;
			std::cin >> p >> x;
			sg.point_update(p, [](long long a, long long b){return a + b;}, x);
		} else {
			int l, r;
			std::cin >> l >> r;
			std::cout << sg.range_fold(l, r) << '\n';
		}
	}

	return 0;
}

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

int main()
{
    int nItem, index = 0;
    long long bagWeight, baseWeight, tmpWeight, tmpVal;
    cin>>nItem>>bagWeight;
    vector<long long> vArr0(1, 0), vArr1(1, 0), vArr2(1, 0), vArr3(1, 0);
    cin>>baseWeight>>tmpVal;
    vArr0.push_back(tmpVal);
    index ++;
    while(index < nItem)
    {
        cin>>tmpWeight>>tmpVal;
        int tmpIndex = int(tmpWeight - baseWeight);
        if(tmpIndex == 0) vArr0.push_back(tmpVal);
        else if(tmpIndex == 1) vArr1.push_back(tmpVal);
        else if(tmpIndex == 2) vArr2.push_back(tmpVal);
        else if(tmpIndex == 3) vArr3.push_back(tmpVal);
        index ++;
    }
    
    sort(vArr0.begin() + 1, vArr0.end(), greater<long long>());
    sort(vArr1.begin() + 1, vArr1.end(), greater<long long>());
    sort(vArr2.begin() + 1, vArr2.end(), greater<long long>());
    sort(vArr3.begin() + 1, vArr3.end(), greater<long long>());
    
    
    int len0 = int(vArr0.size()), len1 = int(vArr1.size()), len2 = int(vArr2.size()), len3 = int(vArr3.size());
    
    for(int i = 1; i<len0; i++) vArr0[i] += vArr0[i - 1];
    for(int i = 1; i<len1; i++) vArr1[i] += vArr1[i - 1];
    for(int i = 1; i<len2; i++) vArr2[i] += vArr2[i - 1];
    for(int i = 1; i<len3; i++) vArr3[i] += vArr3[i - 1];
    
    long long maxVal = 0, tmpV0 = 0, tmpV1 = 0, tmpV2 = 0, tmpV3 = 0;
    
    for(int i0 = 0; i0<len0 && (i0 * baseWeight) <= bagWeight; i0++)
    {
        long long tmp0 = i0 * baseWeight;
        tmpV0 = vArr0[i0];
        
        for(int i1 = 0; i1 < len1 && i1<= ((bagWeight - tmp0) >= 0 ? (bagWeight - tmp0): 0)/(baseWeight + 1); i1 ++)
        {
            long long tmp1 = i1 * (baseWeight + 1);
            tmpV1 = vArr1[i1];
            
            for(int i2 = 0; i2< len2 && i2<=((bagWeight - tmp0 - tmp1)>= 0? (bagWeight - tmp0 - tmp1): 0)/(baseWeight + 2); i2++)
            {
                long long tmp2 = i2 * (baseWeight + 2);
                tmpV2 = vArr2[i2];
                
                for(int i3 = 0; i3<len3 && i3<= ((bagWeight - tmp0 - tmp1 - tmp2)>= 0? (bagWeight - tmp0 - tmp1 - tmp2): 0)/(baseWeight + 3); i3++)
                {
                    tmpV3 = vArr3[i3];
                    
                    tmpVal = tmpV0 + tmpV1 + tmpV2 + tmpV3;
                    if(tmpVal > maxVal) maxVal = tmpVal;
                }
            }
        }
    }
    cout<< maxVal<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
typedef long long  ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	ll accum = 0;
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i];
		accum += abs(a[i] - (i == 0 ? 0 : a[i - 1]));
	}
	accum += abs(0 - a[N - 1]);
	for (ll i = 0; i < N; i++)
	{
		cout << accum - (abs(a[i] - (i == 0 ? 0 : a[i - 1])) + abs(a[i] - (i + 1 == N ? 0 : a[i + 1]))) + abs((i + 1 == N ? 0 : a[i + 1]) - (i == 0 ? 0 : a[i - 1])) << endl;
	}
	return 0;

}

Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main()
{
    int n,i;
    long long unsigned ans=0;
    cin>>n;
    for(i=1;i<=n;i++){
    if(i%3&&i%5)
        {
            ans+=i;
        }

    }
        cout<<ans<<endl;

    return 0;
}






Measured memory_bytes: 3596
n = int(input())
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]] #n番目までの素数のリストを生成
prime = primes(100)
primeCount = [0 for i in range(25)]

def searchSingle():
    res = 0
    for i in range(len(primeCount)):
        if primeCount[i] >= 74:
            res += 1
    return res

def searchDouble():
    res = 0
    for i in range(len(primeCount)):
        for j in range(len(primeCount)):
            cnt_i = primeCount[i]
            cnt_j = primeCount[j]
            if cnt_i >= 14 and cnt_j >= 4 and i != j:
                res += 1
            if cnt_i >= 24 and cnt_j >= 2 and i != j:
                res += 1
    return res

def searchTriple():
  res=0
  for i in range(len(primeCount)):
    for j in range(len(primeCount)):
      for k in range(j+1,len(primeCount)):
        if primeCount[i] >=2 and primeCount[j] >=4 and primeCount[k] >=4 and i!=j and j!=k and i!=k:
          res+=1
  return res

for i in range(2, n+1):
    cnt=i
    for j in range(len(prime)):
        if cnt % prime[j] == 0:
            while cnt % prime[j] == 0:
                cnt//= prime[j]
                primeCount[j] += 1
print(searchSingle() + searchDouble() + searchTriple())

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f[100009],dp[100009],k;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>k;
	for(b=1; b<=a; b++) cin>>f[b];
	dp[a]=0;
	for(b=a-1; b>=1; b--){
		dp[b]=1000000000;
		d=min(a,b+k);
		for(c=b+1; c<=d; c++){
			if(dp[b]>dp[c]+abs(f[b]-f[c])) dp[b]=dp[c]+abs(f[b]-f[c]);
		}
	}
	cout<<dp[1];
	return 0;
}

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

int main(){
  int n; cin >> n;
  int b[n-1]; for(int i=0; i<n-1; i++){cin >> b[i];}
  int sum; sum = b[0]+b[n-2];
  
  for(int i=0; i<n-2; i++){
    if(b[i+1]>=b[i]){sum = sum + b[i];}
    else{sum = sum + b[i+1];}
  }
  
  cout << sum;
  
  return 0;
}

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

int main() {
	
	ll n, k; cin >> n >> k;
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) {
		ll tmp_a; cin >> tmp_a;
		tmp_a--;
		a[i] = tmp_a;
	}
	ll firstTimeforBaseCnt;
	ll roopCycle;
	vector<ll> firstTime(n, 0);
	vector<ll> visitCnt(n, 0);
	ll now = 0;
	ll cnt = 0;
	firstTime[0] = 0;
	visitCnt[0] = 1;
	while (true) {
		cnt++;
		now = a[now];	
		if (visitCnt[now] == 0) {
			firstTime[now] = cnt;
		}
		visitCnt[now]++;
		if (visitCnt[now] == 2) {
			firstTimeforBaseCnt = firstTime[now];
			roopCycle = cnt - firstTimeforBaseCnt;
			break;
		}
	}
	vector<ll> roop;
	now = 0;
	for (ll i = 0; i < roopCycle + firstTimeforBaseCnt; i++) {		
		if (i < firstTimeforBaseCnt) {
			now = a[now];
			continue;
		}
		else {
			roop.push_back(now);
		}
		now = a[now];
	}
	ll ans;
	if (k < firstTimeforBaseCnt) {
		ll tmp = 0;
		for (ll i = 0; i < k; i++) {
			tmp = a[tmp];
		}
		ans = tmp;
	}
	else {
		k -= firstTimeforBaseCnt;
		ll tmp = k % roopCycle;
		ans = roop[tmp];
	}
	cout << ans + 1 << endl;
	return 0;
}

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

int main()
{
  long long int A, B, K;
  cin >> A >> B >> K;
  long long int ans = 0;
  if (K <= A)
  {
    A -= K;
    cout << A << " " << B << endl;
  }
  else if (K > A && K <= (A + B))
  {
    K -= A;
    B -= K;
    cout << 0 << " " << B << endl;
  }
  else if (K > A + B)
  {
    cout << 0 << " " << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	int ans = 0;

	if (a + b == c) {
		ans = b + c ;
	}
	else if (a + b < c) {
		ans = a+ 1 + b * 2;
	}
	else {
		ans=b + c;
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    bool flag = true;
    int year = stoi(S.substr(0, 4));
    if (year < 2019){
        flag = false;
    } else if (year == 2019){
        int month = stoi(S.substr(5, 2));
        if (month < 4){
            flag = false;
        } else if (month == 4){
            int day = stoi(S.substr(8, 2));
            if (day <= 30){
                flag = false;
            }
        }
    }

    if (flag){
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
}

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


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int x;
     cin>>x;
     int res=2*(x/11);
     int remaining=x%11;
     if(remaining==0)
     {
     	  cout<<res<<endl;
     	  return 0;
     }
     if(remaining!=2&&remaining!=7)
     {
     	   if(remaining<=6)
     	   {
     	   	    cout<<res+1<<endl;
     	   	    return 0;
     	   }
     	   else
     	   	cout<<res+2<<endl;
     	   return 0;
     }
     cout<<res+2<<endl;
     time();
     return 0;
 }

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  map<int, int> m;
  rep(i, n) {
    vi a(3);
    cin >> a[0];
    a[1] = a[0] + 1;
    a[2] = a[0] - 1;
    rep(k, 3) {
      if (m.find(a[k]) == m.end()) {
        m[a[k]] = 1;
      } else {
        m[a[k]]++;
      }
    }
  }
  int ans = 0;
  for (const auto& x : m) {
    ans = max(ans, x.second);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int count = 0;
	int ans = 0;
	vector<char> vec1(N, '0'), vec2(N, '0'), vec3(N, '0');
	for (int i = 0; i < N - 1; i++) {
		count = 0;
		vec1 = vec3;
		vec2 = vec3;
		for (int j = 0; j < i + 1; j++)
			vec1.at(j) = S.at(j);
		for (int j = 0; j < N - i - 1; j++)
			vec2.at(j) = S.at(N - j - 1);
		sort(vec1.begin(), vec1.end());
		sort(vec2.begin(), vec2.end());
		for (int j = 0; j < N; j++) {
			if (vec1.at(j) == '0') continue;
			else if (j != 0 && vec1.at(j) == vec1.at(j - 1)) continue;
			else {
				for (int k = 0; k < N; k++) {
					if (vec2.at(k) == '0') continue;
					else if (k != 0 && vec2.at(k) == vec2.at(k - 1)) continue;
					else if (vec1.at(j) == vec2.at(k)) {
						count++;
						break;
					}
				}
			}
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
s = [None]*N
for i in range(N):
    s[i] = ''.join(sorted(input().rstrip('\n')))
s.sort()

ans = 0
cur = ''
n = 0
for i in range(N):
    if cur == s[i]:
        n += 1
    else:
        ans += n*(n-1)//2
        n = 1
        cur = s[i]
else:
    ans += n*(n-1)//2
print(ans)

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

int main() {
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for (auto p : mp) mx = max(mx, p.second);
  for (auto p : mp) {
    if (p.second != mx) continue;
    cout << p.first << endl;
  }
  return 0;
}


Measured memory_bytes: 25216
#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793

int main(void) {
	int a = 0;
	int b = 0;
	int h = 0; //時間
	int m = 0; //分
	double radH = 0.0;
	double radM = 0.0;
	double radHM = 0.0;
	double ans = 0.0;

	scanf("%d %d %d %d", &a, &b, &h, &m);

	radH = ((h * 60.0 + m) * 0.50) * PI / 180.0;

	radM = (m * 6.0) * PI / 180.0;

	//printf("%lf %lf", radH, radM);

	radHM = fabs(radH - radM);

	ans = sqrt(a*a + b*b - 2*a*b*cos(radHM));

	printf("%.20f", ans);

	return 0;
}

Measured memory_bytes: 2644
import java.io.*;
import java.util.*;


public class Main{ 

	public static void main(String args[]){
		
		Scanner scan = new Scanner(System.in);
		Aoj aoj = new Aoj();
		aoj.Load(scan.nextInt(),scan.nextInt(),scan.nextInt());
		aoj.show();
	}
}

class Aoj{
	int[] num;
	public void Load(int... x){
		num = new int[x.length];
		for(int i=0; i<num.length;i++){
			num[i]=x[i];
			for(int j=0; j<i;j++)
				if(num[i-j]<num[i-j-1])
					swap(i-j,i-j-1);
		}
	}
	void swap(int x, int y){
		int tmp=num[x];
		num[x]=num[y];
		num[y]=tmp;
	}
	public void show(){
		for(int i=0; ;i++){
			System.out.print(num[i]);
			if(i==num.length-1)
				break;
			System.out.print(" ");
			
		}
		System.out.println("");
	}
	
}

Measured memory_bytes: 17304
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,x,s[25],sum,ans,a[25][25],c[25];
int main()
{int i,j,k;
	scanf("%d%d%d",&n,&m,&x);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		for (j=1;j<=m;j++)
		scanf("%d",&a[i][j]);
	 } 
	 ans=2e9;
	for (i=0;i<(1<<n);i++)
	{
		memset(s,0,sizeof(s));
		sum=0;
		for (j=0;j<n;j++)
		if ((i&(1<<j))!=0){
			for (k=1;k<=m;k++)
				s[k]+=a[j+1][k];
			sum+=c[j+1];
		}
		for (j=1;j<=m;j++)
		if (s[j]<x) break;
		if (j>m) ans=min(ans,sum);
	} 
	if (ans==2e9) printf("-1\n");
	else printf("%d",ans);
}

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
using namespace std;

int main(){
    long N;
    cin >> N;
    long A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    long min_capacity = min(A, min(B, min(C, min(D, E))));
    long ans = N / min_capacity + 5;
    if(N%min_capacity == 0){
        ans--;
    }
    cout << ans << endl;
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n; cin >> n;
    vii f(n, vi(10));
    rep(i,n)rep(j,10) cin >> f[i][j];
    vii p(n, vi(11));
    rep(i,n)rep(j,11) cin >> p[i][j];

    ll ans = -infll, val, cnt;
    for(int bit = 1; bit < (1<<10); ++bit) {  // bit = 0 はだめ。必ず1回は営業
        val = 0;
        for(int i = 0; i < n; ++i) {  // 全店に対し
            cnt = 0;
            rep(j,10) if(((bit>>j)&1) && f[i][j] == 1) ++cnt;
            val += p[i][cnt];
        }
        chmax(ans, val);
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#define int long long
using namespace std;
int32_t main()
{
 int n;
 cin >> n;
 int arr[n];
 int res=0;
 for(int i=0; i<n; i++)
 {
     cin >> arr[i];
     res=res^arr[i];
 }
 for(int i=0; i<n; i++)
 { int ans=res^arr[i];
 cout << ans << " " ;
 }
 return 0;
 }


Measured memory_bytes: 4700
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
typedef priority_queue<int> Pque;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int n;
int T, X, Y;
int d, interval;
vector<int> t;
vector<P> pairs;
int x_s, x_g, y_s, y_g;

bool keiro(int k){
    x_s = pairs[k].first;
    y_s = pairs[k].second;
    x_g = pairs[k+1].first;
    y_g = pairs[k+1].second;

    d = abs(x_s - x_g) + abs(y_s - y_g);
    interval = t[k+1] - t[k];

    if(interval >= d && (interval % 2 == d % 2)){
        return true;
    } else {
        return false;
    }
}

int main(){

    cin >> n;
    t.push_back(0);
    pairs.push_back(P(0, 0));

    REP(i, n){
        cin >> T >> X >> Y;
        t.push_back(T);
        pairs.push_back(P(X, Y));
    }

    REP(i, n){
        if(!keiro(i)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 1780
N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>K:
        print(loop[K-len(p)])
    else:
        num=(K-count)%len(loop)
        print(loop[num])

Measured memory_bytes: 33816
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

#define INF 1<<29

using namespace std;

int main(void){

  int n,dp[45][4],a,b;
  vector<int>p,t;

  while(cin >> n,n){
    p.clear();
    t.clear();
    
    fill(dp[0],dp[42],INF);
    
    for(int i=0;i<n;i++){
      cin >> a >> b;
      p.push_back(a);
      t.push_back(b);
    }

    dp[0][0]=p[0];
    if(p[0]>t[0]){
      cout << "NG " << 1 <<endl;
      continue;
    }
    int cnt=1;
    for(int i=1;i<n;i++){
      for(int j=1;j<4;j++){
	if(dp[i-1][j-1]==INF)continue;
	cnt=i;
	if(j<3 && abs(p[i]-p[i-1])*(j+1)<=t[i]-t[i-1])
	  dp[i][j]=min(dp[i][j],dp[i-1][j-1]+abs(p[i]-p[i-1]));
	if(p[i]+(p[i-1]*(j+1))<=t[i]-t[i-1])
	  dp[i][0]=min(dp[i][0],dp[i-1][j-1]+p[i]+p[i-1]);
      }
    }
    
    int ans=INF;
    for(int i=0;i<4;i++){
      ans=min(ans,dp[n-1][i]);
    }
    if(ans==INF)cout << "NG " << cnt+1 <<endl;
    else cout << "OK " << ans+p[p.size()-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#include <cstdio>

int main()
{
    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    if (a + b < a + c and a + b < b + c)
    {
        printf("%d", a + b);
    }
    
    else if (a + c < a + b and a + c < b + c)
    {
        printf("%d", a + c);
    }
    
    else if (b + c < a + b and b + c < a + c)
    {
        printf("%d", b + c);
    }
    
    else if (a + b == a + c and a + b == b + c)
    {
        printf("%d", a + b);
    }
}

Measured memory_bytes: 1676
#include<stdio.h>

long long abs(long long a){
  if(a >= 0){
    return a;
  }
  else{
    return -a;
  }
}

int main(void){
  int n , k;
  scanf("%d %d",&n ,&k);

  long long x[n];
  for(int i = 0;i < n;i ++){
    scanf("%lld",&x[i]);
  }

  int start , end;
  long long time , min = 1000000000000;
  
  for(int i = 0;i < n - k + 1;i ++){
    start = i;
    end = i + k - 1;
    if(abs(x[start]) < abs(x[end])){
      time = abs(x[start]) + abs(x[start] - x[end]);
    }
    else{
      time = abs(x[end]) + abs(x[start] - x[end]);
    }
	//printf("%lld\n",time);
    if(min > time){
      min = time;
    }
  }

  printf("%lld\n",min);

  return 0;
}

Measured memory_bytes: 2484
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> x(N);
    for (int &t: x)
        cin>>t,
        t--;

    vector<pair<int,int>> X;
    for (int i=0; i<N; i++)
        X.push_back(make_pair(x[i], i));
    sort(X.begin(), X.end());

    vector<int> A(N*N, -1);
    for (int i=0; i<N; i++)
        A[x[i]] = i;

    vector<int> T(N);
    for (int i=0; i<N; i++)
        T[i] = i;
    int p = 0;
    for (int i=0; i<N*N; i++)
    {
        if (A[i]>=0)
        {
            if (T[A[i]]!=0)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        else
        {
            while (p<N && T[X[p].second]==0)
                p++;
            if (p<N)
            {
                A[i] = X[p].second;
                T[X[p].second]--;
            }
        }
    }

    for (int i=0; i<N; i++)
        T[i] = N-i-1;
    p = N-1;
    for (int i=N*N-1; i>=0; i--)
    {
        if (A[i]<0)
        {
            while (p>=0 && T[X[p].second]==0)
                p--;
            if (p<0 || i<X[p].first)
            {
                cout<<"No"<<endl;
                return 0;
            }
            A[i] = X[p].second;
            T[X[p].second]--;
        }
    }
    cout<<"Yes"<<endl;
    for (int i=0; i<N*N; i++)
        cout<<(i>0 ? " " : "")<<A[i]+1;
    cout<<endl;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
char a[100001];
int main()
{
	int b=0,i;gets(a);
	for(i=1;i<strlen(a);i++)
	if(a[i]!=a[i-1])b++;
	printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int as[200000+10];
int bs[200000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d%d", &as[i], &bs[i]);
  }
  sort(as, as + n);
  sort(bs, bs + n);
  int res;
  if(n % 2 == 0) {
    int l1 = as[n/2-1];
    int r1 = bs[n-1-(n/2-1)];
    int l2 = as[n/2];
    int r2 = bs[n-1-(n/2)];
    // cerr << "> " << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
    res = (r1-l1+1) + (r2-l2+1) - 1;
  } else {
    int left = as[n/2];
    int right = bs[n-1-n/2];
    // cerr << "> " << left << " " << right << endl;
    res = right - left + 1;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4812
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

ll fac[2000010], finv[2000010], inv[2000010];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(ll i=2;i<2000010;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll C(ll n, ll k){
  return fac[n] %mod * finv[k] %mod * finv[n-k] %mod;
}

int main(){FIN
    
    ll x, k, d; cin>>x>>k>>d;
    ll ans=0;
    if (x <= 0) x *= (-1);
    
    if (x/d<k) {
        if (((x/d) % 2) == (k % 2)) ans = x%d;
        else ans = abs(d - x%d);
    } 
    else ans = x - k*d;
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3652
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

int n, m;
ll dis[2][maxn];
ll ans[2][maxn];
bool vis[2][maxn];
int const MOD = 1e9 + 7;
int st, ed;

struct Edge {
    int v, next, w;
}e[200000 << 1];
int head[maxn], cnt;

void init() {
    memset(head, -1, sizeof(head));
    memset(dis, 0x3f, sizeof(dis));
    cnt = 0;
}

void add(int u, int v, int w) {
    e[cnt].v = v;
    e[cnt].w = w;
    e[cnt].next = head[u];
    head[u] = cnt++;
}

void dijkstra(int s, ll d[], bool v[], ll ans[]) {
    priority_queue<pair<ll, int> > q;
    d[s] = 0;
    ans[s] = 1;
    q.emplace(0, s);
    while (!q.empty()) {
        int u = q.top().second;
        // cout << u << endl;
        q.pop();
        if (v[u]) continue;
        v[u] = 1;
        for (int i = head[u]; ~i; i = e[i].next) {
            int v = e[i].v;
            int w = e[i].w;
            if (d[v] > d[u] + w) {
                d[v] = d[u] + w;
                ans[v] = ans[u];
                q.emplace(make_pair(-d[v], v));
            } else if (d[v] == d[u] + w) {
                ans[v] = (ans[v] + ans[u]) % MOD;
            }
        }
    }

}

int main(void) {
    FAST_IO;
    
    cin >> n >> m >> st >> ed;
    init();
    for (int i = 1; i <= m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        add(u, v, w);
        add(v, u, w);
    }
    dijkstra(st, dis[0], vis[0], ans[0]);
    dijkstra(ed, dis[1], vis[1], ans[1]);

    ll path = ((ans[0][ed] % MOD) * (ans[0][ed] % MOD)) % MOD;
    ll D = dis[0][ed];
    for (int i = 1; i <= n; i++) {
        if (dis[0][i] == dis[1][i] && D == dis[1][i] * 2) {
            path = path - ((ans[0][i] * ans[0][i] % MOD) * (ans[1][i] * ans[1][i] % MOD)) % MOD;
            path = (path + MOD) % MOD;
        }
        for (int u = head[i]; ~u; u = e[u].next) {
            int w = e[u].w;
            int v = e[u].v;
            ll d1 = dis[0][i], d2 = dis[1][v];
            if (d1 + w + d2 == D && d1 * 2 < D && d2 * 2 < D) {
                path = path - ((ans[0][i] * ans[0][i] % MOD) * (ans[1][v] * ans[1][v] % MOD)) % MOD;
                path = (path + MOD) % MOD;
            }
        }
    }
    cout << path << endl;
    
    return 0;
}

Measured memory_bytes: 12244
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
struct UnionFind {
    vector<int> d ;
    UnionFind (int n = 0) : d(n, -1) {}
    int find(int x) {
        if(d[x] < 0) return x ;
        return find(d[x]) ;
    }
    bool unite(int x, int y){
        x = find(x) ;
        y = find(y) ;
        if(x == y) {
            return false ; 
        }
        if(d[x] > d[y]) swap(x, y) ;
        d[x] += d[y] ;
        d[y] = x ;
        return true ;
    }
    bool same(int x, int y){
        return find(x) == find(y) ;
    }
    int size(int x){
        return -d[find(x)] ;
    }
};

int main() {
    int n ;
    int m ;
    cin >> n >> m ;
    UnionFind uf(n) ;
    rep(i, m){
        int a, b ;
        cin >> a >> b ;
        a-- ;
        b-- ;
        uf.unite(a, b) ;
    }
    int ans = 0 ;
    rep(i, n){
        ans = max(ans, uf.size(i)) ;
    }
    cout << ans << endl ;
} 

Measured memory_bytes: 4036