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

class Sai {
    vector<int> m_s;
public:
    Sai(vector<int> s) {
        m_s = vector<int>(6);
        rep(i, 6) {
            m_s.at(i) = s.at(i);
        }
    }
    void move(char ch) {
        switch(ch) {
        case 'E':
            swap(m_s.at(0), m_s.at(3));
            swap(m_s.at(2), m_s.at(3));
            swap(m_s.at(3), m_s.at(5));
            break;
        case 'N':
            swap(m_s.at(0), m_s.at(1));
            swap(m_s.at(4), m_s.at(1));
            swap(m_s.at(5), m_s.at(1));
            break;
        case 'S':
            swap(m_s.at(0), m_s.at(4));
            swap(m_s.at(1), m_s.at(4));
            swap(m_s.at(5), m_s.at(4));
            break;
        case 'W':
            swap(m_s.at(0), m_s.at(2));
            swap(m_s.at(3), m_s.at(2));
            swap(m_s.at(5), m_s.at(2));
            break;
        default:
            assert(false);
        }
    }
    int top(void) {
        return m_s.at(0);
    }
};

int main() {
    vector<int> n(6);
    rep(i, 6) cin >> n.at(i);
    Sai sai(n);
    string str; cin >> str;
    for (auto ch : str) {
        sai.move(ch);
    }
    cout << sai.top() << endl;
}



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

using namespace std;

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

vector <pll> V[101010], K;
vector <ll> S;
ll T[101010];
ll n,m;

void pass(ll a,ll b)
{
	ll t = upper_bound(S.begin(), S.end(), a) - S.begin() - 1;
	if(t < 0) V[0].push_back(pll(a, b));
	else V[t].push_back(pll(a, b));
}

int main()
{
	ll i,a,p,cnt;
	pll q;
	
	scanf("%lld%lld",&n,&m);
	
	S.push_back(n);
	
	for(i=0;i<m;i++){
		scanf("%lld",&a);
		for(;!S.empty() && S.back() >= a; S.pop_back());
		S.push_back(a);
	}
	
	V[S.size()-1].push_back(pll(S.back(), 1));
	
	for(i=S.size()-1;i>=1;i--){
		p = S[i];
		
		if(V[i].empty()) continue;
		
		sort(V[i].begin(), V[i].end());	
		K.clear();
		for(pll q: V[i]){
			if(!K.empty() && K.back().first == q.first) K.back().second += q.second;
			else K.push_back(q);
		}
		
		cnt = 0;
		for(pll q: K){
			if(q.first % p) pass(q.first % p, q.second);
			cnt += q.first / p * q.second;
		}
		
		ll q = S[i-1];
		V[i-1].push_back(pll(q, p / q * cnt));
		pass(p % q, cnt);
	}
	
	for(pll q: V[0]){
		T[q.first % S[0]] += q.second;
		T[S[0]] += q.first / S[0] * q.second;
	}
	
	for(i=n;i>=1;i--) T[i] += T[i+1];
	
	for(i=1;i<=n;i++) printf("%lld\n",T[i]);	
	
	return 0;
}

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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 5e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

vector<int> G[N];
ll mul(ll a, ll b){
	return (a*b) % Mod;
}
ll bin_pow(ll b, ll p){
	ll res = 1;
	for(ll pw = b, j = 1; j <= p; j <<= 1, pw = mul(pw, pw))
		if(p & j)
			res = mul(res, pw);
	return res;
}

ll p[N];

ll mk[N], sz ;
void DFS(ll u){
	mk[u] = 1;
	sz ++;
	for(auto adj : G[u]) if(!mk[adj]) DFS(adj);
}
ll dp[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> p[i];
		if(p[i] > 0){
			G[p[i]].pb(i);
			G[i].pb(p[i]);
		}
	}
	vector<ll> V;
	ll C = 0;
	for(int i = 1; i <= n; i++){
		if(p[i] == -1){
			C++;
			sz = 0;
			DFS(i);
			V.pb(sz);
		}
	}
	ll T = bin_pow(n - 1, C);
	ll ans = mul(T, n);
	for(int i = 1; i <= n; i++){
		if(!mk[i]){
			DFS(i);
			ans -= T;
		}
	}
	ans %= Mod;
	dp[0] = 1;
	for(auto x : V){
		//debug(x);
		for(int i = N - 2; i > 0; i--){
			dp[i + 1] = mul(n - 1, dp[i + 1]) + mul(dp[i], mul(i, x));
			dp[i + 1] %= Mod;
		}
		dp[1] = mul(dp[1], n - 1) + mul(x, dp[0]);
		dp[1] %= Mod;
		dp[0] = mul(dp[0], n - 1);
	}
	dp[1] = 0;
	for(auto x : V){
		dp[1] += mul(dp[0], mul(bin_pow(n - 1, Mod - 2), x - 1));
	}
	for(int i = 1; i < N; i++){
		ans -= dp[i];
		ans %= Mod;
	}
	cout << (ans + Mod) % Mod << '\n';
	return 0;
}


Measured memory_bytes: 4076
import collections
import itertools
import functools
import math

if __name__ == "__main__":
    x = 0
    m = 0
    input()  # we don't need n
    s = input()
    for letter in s:
        if letter == "I":
            x += 1
        elif letter == "D":
            x -= 1
        m = max(m, x)
    print(m) 

Measured memory_bytes: 3572
def operate(operand0, operand1, operator):
    if operator == "+":
        return str(int(operand0) + int(operand1))
    elif operator == "*":
        return str(int(operand0) * int(operand1))
    elif operator == "-":
        return str(int(operand0) - int(operand1))

if __name__ == "__main__":
    import sys
    expr = sys.stdin.readline().strip().split()
    stack = []
    for t in expr:
        if t.isdigit():
            stack.append(t)
        else:
            a = stack.pop()
            b = stack.pop()
            stack.append(operate(b, a, t))
    print stack.pop()

Measured memory_bytes: 4228
import java.lang.Math.abs
import java.lang.Math.min
import java.util.*

fun main(args: Array<String>) = abc160d()

fun abc160d() {
    val (n, x1, y1) = readLine()!!.split(' ').map { it.toInt() }
    val x = x1 - 1
    val y = y1 - 1

    val distances = IntArray(n)

    for (left in 0 until n) {
        for (right in left + 1 until n) {
            distances[min(right - left, abs(right - y) + abs(left - x) + 1)]++
        }
    }

    val answer = distances.drop(1).joinToString(System.lineSeparator())

    println(answer)
}


Measured memory_bytes: 38304
N = int(input())
D = list(map(int, input().split()))
dic = {}
ABCs = 0
count = 0

for i in range(N):
    if D[i] in dic:
        dic[D[i]] += 1
    else:
        dic[D[i]] = 1

diffs = sorted(dic.keys())

for i in range(diffs[-1]+1):
    if i in dic:
        ABCs += dic[i]
    if ABCs == N / 2:
        count += 1

print(count)


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

int main() {
 int n,cnt=0,w1=0,w2=0,ma=-1;
 cin>>n;
 vector<pair<int,int>>v(n+1);

  for(int i=0;i<n+1;i++){
	  v.at(i).second=i;
	  w1=i;
	  while(w1>=2 && w1%2==0){
		  cnt++;
		  v.at(i).first=cnt;
		  w1/=2;
	  }
	  cnt=0;

  }
  for(int i=0;i<n+1;i++){
	  if(ma<=v.at(i).first){
		  ma=v.at(i).first;
		  w2=v.at(i).second;
	  }
  }
  cout<<w2<<endl;

	return 0;
}



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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int x[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
    int n, m;
    cin >> n >> m;
    
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

//MOD,および逆元テーブルの作成
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    int N,K;
    cin>>N>>K;
    long long ans=0;
    long long tmp;
    long long tmp2;
    for(int i=1;i<=K;++i){
      tmp=0;
      tmp2=0;
      ans=0;
      //i-1箇所を選ぶ
      tmp=COM(K-1,i-1);
      //i-1箇所に赤ボールを配った上で残りのN-K+1-iこのボールをi+1箇所へ
      if(N-K+1>=i){
        tmp2=COM(N-K+1,i);
      }
      else{
        tmp2=0;
      }
      ans=(tmp*tmp2%MOD);
      cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, k;
    cin >> n >> k;
    n -= k;
    if (k == 1) {
        cout << 0 << endl;
    } else {
        cout << n << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define N 501

int main(){
	while(1){
		int a,n,i,sum=0;
		cin>>n;
		if(n==0)break;
		n/=4;
		for(i=0;i<n;i++){
			cin>>a;
			sum+=a;
		}
		cout<<sum<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int D; cin >> D;
    vector<int> c(26+1, 0);
    for(int i = 1; i <= 26; i++) cin >> c[i];
    vector<vector<int>> s(D+1, vector<int>(26+1, 0));
    for(int i = 1; i <= D; i++)for(int j = 1; j <= 26; j++) cin >> s[i][j];
    vector<int> t(D+1, 0);
    for(int i = 1; i <= D; i++) {
        t[i] = rand() % 25 + 1;
    }
    vector<int> last(26+1, 0);
    int ans = 0;
    auto f = [&](int d){
        int res = 0;
        for(int i = 1; i <= 26; i++){
            res += c[i] * (d - last[i]);
        }
        return res;
    };
    for(int day = 1; day <= D; day++){
        int con = t[day];
        ans += s[day][con];
        last[con] = day;
        ans -= f(day); 
        //cout << ans << endl;
    }
    for(int i = 1; i <= D; i++) cout << t[i] << endl;
}

Measured memory_bytes: 3664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

template<typename T>
struct BIT{
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1){}
  void add(int i,T x=1) {
    for(i++;i<=n;i+= i&-i){
      d[i]+=x;
    }
  }
  T sum(int i){
    T x=0;
    for(i++;i;i-= i&-i){
      x+=d[i];
    }
    return x;
  }
  T sum(int l,int r){
    return sum(r-1)-sum(l-1);
  }
};

int ans[500010];

int main(){
  int n,q; cin >> n >> q;
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  vector<vector<int> > pr(n,vector<int>(0));
  map<int,int> last;
  rep1(i,n) last[i]=-1;
  rrep(i,n) {
    if(last[c[i]]!=-1) pr[i].push_back(last[c[i]]);
    last[c[i]]=i;
  }
  vector<vector<pii> > que(n,vector<pii>(0));
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--; r--;
    que[l].push_back(pii(r,i));
  }
  BIT<int> yaxis(n);
  rrep(x,n){
    for(auto y:pr[x]){
      yaxis.add(y,1);
    }
    for(auto v:que[x]){
      int r,i;
      tie(r,i)=v;
      ans[i]=(r-x+1)-yaxis.sum(r);
    }
  }
  rep(i,q) cout << ans[i] << endl;
}

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

int main(){
    ll N, T; cin >> N >> T;
    vector<ll> t(N);
    for(int i = 0; i < N; i++) cin >> t[i];
    ll ans = T;
    for(int i = 1; i < N; i++){
        if(t[i] - t[i-1] >= T) ans += T;
        else ans += t[i] - t[i-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <functional>
#include <utility>
const int N = 1000000;
typedef long long ll;
const ll ha = 1000000007LL;
inline ll pow_mod(ll a, ll b) {
  ll ans = 1, res = a;
  while(b) {
    if(1LL & b) ans = ans * res % ha;
    res = res * res % ha; b >>= 1;
  }
  return ans;
}
inline ll inv(ll x) {
  return pow_mod(x, ha - 2LL);
}

ll fac[N + 5], ifac[N + 5];
inline void process() {
  fac[0] = 1;
  for(int i = 1; i <= N; i ++) fac[i] = fac[i - 1] * i % ha;
  ifac[N] = inv(fac[N]);
  for(int i = N - 1; i >= 0; i --) ifac[i] = ifac[i + 1] * (i + 1) % ha;
}
inline ll C(int n, int m) {
  if(n < m) return 0;
  return fac[n] * ifac[m] % ha * ifac[n - m] % ha;
}

ll f[N + 5]; int n, m, k;
inline void dp() {
  f[0] = 1;
  for(int i = 1; i <= m + k; i ++) {
    f[i] = f[i - 1] << 1;
    f[i] += ha - C(i - 1, m);
    f[i] += ha - C(i - 1, k);
    f[i] %= ha;
  }
}

int main() {
  process();
  scanf("%d%d%d", &n, &m, &k);
  dp();
  ll ans = 0;
  for(int i = n; i <= n + m + k; i ++) {
    ll val = f[i - n] * C(i - 1, n - 1) % ha;
    val *= pow_mod(3, n + m + k - i);
    ans = (ans + val) % ha;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 23552
//include
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

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

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

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

template <class T>
inline T nCr(T n, T r)
{
    T num = 1;
    for (int i = 1; i <= r; ++i)
    {
        num *= (n - i + 1) / i;
    }
    return num;
}
template <class T>
inline T nPr(T n, T r)
{
    r = n - r;
    T sum = 1;
    int i;
    for (i = n; i >= r + 1; --i)
        sum *= i;
    return sum;
}

template <class T>
inline T facctorial(T k)
{
    T sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

//numeric
template <class T>
inline T gcd(T a, T b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

//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 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())

//repetition
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

//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()
{
    LL L, R;
    cin >> L >> R;
    for (int i = L; i <= R; ++i)
    {
        if (i % 2019 == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    L %= 2019;
    R %= 2019;
    int ans;
    ans = L * R % 2019;
    for (int i = L; i < R; ++i)
    {
        for (int j = L + 1; j <= R; ++j)
        {
            if (((i * j) % 2019) < ans)
            {
                ans = (i * j) % 2019;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v) { cout << v << endl; }
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  ll sum = 0;
  bool zero = false;
  ll min_v = 100000000000000000;
  ll minus = 0;
  for (auto &&a: A) {
    ll v = abs(a);
    sum += v;
    zero |= a == 0;
    minus += a<0;
    if (min_v > v) min_v = v;
  }
  if (zero or minus%2==0) print(sum);
  else print(sum-2*min_v);
  return 0;
}


Measured memory_bytes: 4004
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var DX = Console.ReadLine().Split().Select(int.Parse);
        int D = DX.First(), X = DX.Last();
        for (int i = 0; i < N; i++)
        {
            int A = int.Parse(Console.ReadLine());
            for (int j = 0; j * A < D; j++)
            {
                X++;
            }
        }
        Console.WriteLine(X);
    }
}

Measured memory_bytes: 11348
let () =
  Scanf.scanf "%d %d %d %d %d\n" @@ fun x1 x2 x3 x4 x5 ->
  Printf.printf "%d\n" (if x1 = 0 then 1 else if x2 = 0 then 2 else if x3 = 0 then 3 else if x4 = 0 then 4 else 5)

Measured memory_bytes: 3708
A, B, C, K = map(int, input().split())
total = 0
if A >= K:
    print(K)
    exit(0)
elif A != 0:
    K = K - A
    total = A

if B >= K:
    print(total)
    exit(0)
elif B != 0:
    K = K - B

print(total-K)

Measured memory_bytes: 61928
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int n;
    cin>>n;
    
    
    int cnt[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++) cnt[i][j]=0;

    for(int i=1;i<=n;i++){
        int x=to_string(i)[0]-'0';
        int y=i%10;
        cnt[x][y]++;
    }

    int res=0;
    for(int i=1;i<=n;i++){
        int x=to_string(i)[0]-'0';
        int y=i%10;
        res+=cnt[y][x];
    }
    cout<<res<<endl;
    
    return 0;
}


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var A = Sarray()[0];
            if (N % 500 <= A)
                WriteLine("Yes");
            else
                WriteLine("No");
        }
        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28124
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, x, cnt = 1, cru = 0;
  cin >> n >> x;
  REP(i,n) {
    int a;
    cin >> a;
    cru += a;
    if(cru <= x) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int sod(int x)
{
	int ans=0;
	while(x)
	{
		ans+=x%10;
		x/=10;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int ans = int(1e9);
	for(int i=1;i<=n-1;i++)
	{
		ans=min(ans,sod(i)+sod(n-i));
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int coin[6]={1,5,10,50,100,500};
  int ans=0,a;
  for(int i=0;i<6;i++){
    cin>>a;
    ans+=a*coin[i];
  }
  if(ans<1000){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 1164
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int(): return int(input())

    def map_int_input(): return map(int, input())

    MII = map_int_input

    def MII_split(): return map(int, input().split())

    def MII_to_index(): return map(to_index, input())

    def MII_split_to_index(): return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs(): return list(map(int, input()))

    LII = list_int_inputs

    def LII_split(): return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

    N = input_int()
    dic = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
    for _ in range(N):
        S = input()
        dic[S] += 1

    for k, v in dic.items():
        print(f'{k} x {v}')

resolve()

Measured memory_bytes: 9276
fun main(args: Array<String>) = ABC165A.main()

object ABC165A {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val K = readInt()
        val (A, B) = readInts()

        val ans = (A..B).any { it%K==0 }

        println(ans.yesOrNo())
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "OK" else "NG"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 36456
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main() {
 
    int N, M, Q;
    cin >> N >> M >> Q;
 
    vector<vector<int>> B(N + 1, vector<int>(N + 1, 0));
    for (int i = 0; i < M; i++) {
        int L, R;
        cin >> L >> R;
        B[L][R]++;
    }
 
    for(int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
            B[i + 1][j + 1] += B[i][j + 1] + B[i + 1][j] - B[i][j];
        }
    }
 
    for(int i = 0; i < Q; i++) {
        int p, q;
        cin >> p >> q;
        int ans = B[q][q] - B[p - 1][q] - B[q][p - 1] + B[p - 1][p - 1];
        cout << ans << endl;
    }

}

Measured memory_bytes: 1920
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    string t;
    cin >> s >> t;
    t += s;
    cout << t << "\n";

    return 0;
}

Measured memory_bytes: 256
W,H,N = gets.split.map(&:to_i)
left = 0
right = W
top = H
bottom = 0

N.times do |i|
    x,y,a = gets.split.map(&:to_i)
    case a
    when 1
        left = [x,left].max
    when 2
        right = [x,right].min
    when 3
        bottom = [y,bottom].max
    when 4
        top = [y,top].min
    end
end

puts [right - left, 0].max * [top - bottom, 0].max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
const Int MOD = 998244353;
struct SegTree {
    int N;
    vector<Int> A, B, C;
    vector<bool> lazy;
    SegTree(int n) {
        N = 1; while (N < n) N *= 2;
        A.resize(2 * N);
        B.resize(2 * N, 1);
        C.resize(2 * N);
        lazy.resize(2 * N);
    }
    void build(const vector<Int> &ary) {
        fill(begin(A), end(A), 0);
        fill(begin(B), end(B), 1);
        fill(begin(C), end(C), 0);
        fill(begin(lazy), end(lazy), 0);
        for (int i = 0; i < ary.size(); i++) {
            A[N + i] = ary[i];
        }
        for (int i = N - 1; i > 0; i--) {
            A[i] = (A[2*i+0] + A[2*i+1]) % MOD;
        }
    }
    void down(int node, int nodeL, int nodeR) {
        if (!lazy[node]) return;
        A[2*node+0] = (B[node] * A[2*node+0] + C[node] * (nodeR - nodeL) / 2) % MOD;
        A[2*node+1] = (B[node] * A[2*node+1] + C[node] * (nodeR - nodeL) / 2) % MOD;
        B[2*node+0] = B[node] * B[2*node+0] % MOD;
        B[2*node+1] = B[node] * B[2*node+1] % MOD;
        C[2*node+0] = (B[node] * C[2*node+0] + C[node]) % MOD;
        C[2*node+1] = (B[node] * C[2*node+1] + C[node]) % MOD;
        lazy[2*node+0] = lazy[2*node+1] = 1;
        B[node] = 1, C[node] = 0, lazy[node] = 0;
    }
    Int sum_0(int L, int R, int node, int nodeL, int nodeR) {
        if (R <= nodeL || nodeR <= L) return 0;
        if (L <= nodeL && nodeR <= R) return A[node];
        down(node, nodeL, nodeR);
        Int ans = 0;
        ans += sum_0(L, R, 2*node+0, nodeL, (nodeL + nodeR) / 2);
        ans += sum_0(L, R, 2*node+1, (nodeL + nodeR) / 2, nodeR);
        return ans % MOD;
    }
    Int sum(int L, int R) {
        return sum_0(L, R, 1, 0, N);
    }
    void modify_0(int L, int R, int b, int c, int node, int nodeL, int nodeR) {
        if (R <= nodeL || nodeR <= L) return;
        if (L <= nodeL && nodeR <= R) {
            A[node] = (b * A[node] + (Int)c * (nodeR - nodeL)) % MOD;
            B[node] = b * B[node] % MOD;
            C[node] = (b * C[node] + c) % MOD;
            lazy[node] = 1;
            return;
        }
        down(node, nodeL, nodeR);
        modify_0(L, R, b, c, 2*node+0, nodeL, (nodeL + nodeR) / 2);
        modify_0(L, R, b, c, 2*node+1, (nodeL + nodeR) / 2, nodeR);
        A[node] = (A[2*node+0] + A[2*node+1]) % MOD;
    }
    void modify(int L, int R, int b, int c) {
        modify_0(L, R, b, c, 1, 0, N);
    }
};
int main() {
    int N, Q; cin >> N >> Q;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    SegTree st(N);
    st.build(A);
    for (int i = 0; i < Q; i++) {
        int type; cin >> type;
        if (type == 0) {
            int l, r, b, c; cin >> l >> r >> b >> c;
            st.modify(l, r, b, c);
        } else {
            int l, r; cin >> l >> r;
            cout << st.sum(l, r) << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 31936
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
const long double PI = 3.14159265359;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	if (s == "SUN")cout << 7 << endl;
	else if (s == "MON")cout << 6 << endl;
	else if (s == "TUE")cout << 5 << endl;
	else if (s == "WED")cout << 4 << endl;
	else if (s == "THU")cout << 3 << endl;
	else if (s == "FRI")cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;

    cin>>N;

    cout << (N-1)/2<<endl;



}


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

using namespace std;

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i=0;i<N;i++){
		cin >>A[i];
	}
	double X=0;
	for(int j=0;j<N;j++){
		X=X+(1/(double)A[j]);
	}
	X=1/X;
	cout <<X<<endl;
	return 0;
}

Measured memory_bytes: 256
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 31000000
// #define M 19
 
// #define mod  11092019
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll mul(ll a, ll b, ll mod) { return (long long) a*b%mod;}
inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b: a+b-mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
    ll ret;
    for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
    return ret;
}

static inline ll get_num() {
    ll num = 0;
    char c = getchar_unlocked();
    while(!((c>='0') & (c<='9')))  c=getchar_unlocked();
    while(c>='0' && c<='9'){
        num = (num<<1)+(num<<3)+c-'0';
        c=getchar_unlocked();
    }
    return num;
}

static inline void read(ll &x) { x = get_num();}

struct Edge{
	ll f, t, c;
	Edge(ll f, ll t, ll c): f(f), t(t), c(c){}
};
int main(){
	ll n, m, p; read(n), read(m), read(p);
	vector<Edge> graph;
	FER(i, 0, m){
		ll a, b, c; read(a), read(b), read(c); a--, b--;
		graph.pb(Edge{a, b, p-c});
	}
	vi d(n, INF);
	d[0] = 0;
	FER(i, 0, n){
		for(auto xd: graph){
			if(d[xd.f] >= INF) continue;
			ll cur = min(d[xd.t], d[xd.f] + xd.c);
			d[xd.t] = cur;
		}
	}
	FER(i, 0, n){
		for(auto xd: graph){
			if(d[xd.f] >= INF) continue;
			if(d[xd.t] > d[xd.f] + xd.c){
				d[xd.t] = -INF;
			}
		}
	}
	if(d[n-1] <= -INF) cout<<"-1\n";
	else cout<<(-d[n-1]>0? -d[n-1] : 0)<<"\n";
	return 0;
}

Measured memory_bytes: 3780
import collections
n = int(input())
a = list(map(int,input().split()))
q = int(input())
l = [list(map(int,input().split())) for i in range(q)]
b,c = [list(i) for i in zip(*l)]
x = collections.Counter(a)
y = sum(a)
for i in range(q):
    if b[i] in x:
        y -= x[b[i]] * b[i]
        y += x[b[i]] * c[i]
        x[c[i]] += x[b[i]]
        x[b[i]] = 0
    print(y)

Measured memory_bytes: 40120
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

ll gcd(ll a, ll b){
    if (a == 0)
        return b;
    else
        return gcd(b % a, a);
 }

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


void solve(){

    ll N,K;
    cin>>N>>K;
    ll i,temp;
    vector<ll> v;
    for(i=0;i<N;i++){
        cin>>temp;
        v.push_back(temp);
    }
    ll r=0;
    ll A[N]={};
    //A[1] = abs(v[1]-v[0]);
    for(i=1;i<N;i++){
        ll u = INT_MAX;
        for(ll j=1;j<=K;j++){
            if(i-j>=0)
                u = min(abs(v[i]-v[i-j])+A[i-j],u);
        }
        A[i] = max(u,A[i]);
    }
    /*for(i=0;i<N;i++){
        cout<<A[i]<<" ";
    }*/
    cout<<A[N-1];

}

int main(){
    //freopen("D:\\codes\\1input.txt","r",stdin);
    //freopen("D:\\codes\\1output.txt","w",stdout);
    ll T=1;
    //cin>>T;
    for(ll t=1;t<=T;t++){

        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<"\n";
    }
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int p[505][505] = {0};

struct N {
  int l, r;
  int level;
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;

  queue<N> q;
  q.push(N{0, n, 1});
  while (q.size()) {
    N now = q.front();
    q.pop();
    if (now.r - now.l <= 1) {
      continue;
    }
    int l1 = (now.r - now.l) / 2;
    int i2 = now.l + l1;
    for (int i = now.l; i < now.l + l1; i++) {
      for (int j = i2; j < now.r; j++) {
        p[i][j] = p[j][i] = now.level;
      }
    }
    q.push(N{now.l, now.l + l1, now.level + 1});
    q.push(N{now.l + l1, now.r, now.level + 1});
  }

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (j > i + 1)
        cout << " ";
      cout << p[i][j];
    }
    cout << endl;
  }

  return 0;
}


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

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

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

const int N = 2e5 + 5 ;
int frq[ N ] ;
int n , k , v ;
set < int > in ;


bool cmp( int s , int f ){
return frq[ s ] < frq[ f ] ;
}

int main() {

   cin >> n >> k ;
   forn( int , i , 0 , n ){
      cin >> v ;
      frq[ v ]++ ;
      in.insert( v ) ;
   }

   vector < int > s ;
   fore( i , in )
    s.pb( i ) ;

   sort( all( s ) , cmp ) ;


   int rem = sz( s ) - k ;

   if( rem < 0 ){
      cout << 0 << "\n" ;
      return 0 ;
   } else {
     int ans = 0 ;
     for( int i = 0 ; i < rem ; i++ )
        ans += frq[ s[ i ] ] ;
     cout << ans << "\n" ;
   }



   return 0 ;
}



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

typedef long long ll;
ll MOD = 1000000007;

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

    vector <pair<int, int> > r(n), b(n);
    for (int i = 0; i < n; i++) cin >> r[i].first >> r[i].second;
    for (int i = 0; i < n; i++) cin >> b[i].first >> b[i].second;

    //sort(r.begin(), r.end());
    //reverse(r.begin(), r.end());

    sort(b.begin(), b.end());
    
    int ans = 0;
    bool used[n] = {false};

    for (int i = 0; i < n; i++) {
        int idx = -1;
        int now = -1;
        
        for (int j = 0; j < n; j++) {
            if ((r[j].first < b[i].first) and (r[j].second < b[i].second) and !used[j]) {
                if (r[j].second > now) {
                    idx = j;
                    now = r[j].second;
                } 
            }
        }
        if (idx == -1) continue;
        used[idx] = true;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

def f(m):
    res = sum([-(-x//m)-1 for x in a])
    return res <= k

l, r = 0, 10**9+10

while r-l > 1:
    x = (l+r)//2
    if f(x): r = x
    else: l = x

print(r)


Measured memory_bytes: 218532
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k,c = inpm()
    s = list(input())
    circle = []
    for i in range(n):
        if s[i] == 'o':
            circle.append(i)
    pre = -c-10
    cnt = 0
    front = []
    for i in range(len(circle)):
        if pre+c < circle[i]:
            front.append(i)
            pre = circle[i]
            cnt += 1
            if cnt == k:
                break
    pre = n+c+10
    cnt = 0
    back = []
    for i in range(len(circle)-1,-1,-1):
        if pre-c > circle[i]:
            back.append(i)
            pre = circle[i]
            cnt += 1
            if cnt == k:
                break
    back.sort()
    for i in range(k):
        if back[i] == front[i]:
            print(circle[front[i]]+1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 90308
import sys
from collections import Counter
inputs = sys.stdin.readlines()

N, K, Q = map(int, inputs[0].split())
A = [int(a) for a in inputs[1:]]

counter = Counter(A)
for i in range(1, N+1):
    if i in counter:
        if K - Q + counter[i] > 0:
            print('Yes')
        else:
            print('No')
    elif K - Q > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 18156
#include<bits/stdc++.h>
using namespace std;
long long n,tot,a,b;
long long dp[101000];
int main()
{
	cin>>n>>tot;
	for(int i=0;i<=100000;i++) dp[i]=1e18;
	dp[0]=0;
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		for(int j=1000*i;j>=b;j--)
		   dp[j]=min(dp[j],dp[j-b]+a);
	}
	long long ans=0;
	for(int i=0;i<=100000;i++)
	   if(dp[i]<=tot) ans=i;
	cout<<ans<<endl;
	return 0;
}


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

int main() {
    int x;
    int h;
    int m;
    int s;
    cin >> x;
    h = x / 3600;
    m = (x % 3600)/60;
    s = x % 60;
      cout << h << ":" << m << ":" << s << endl;
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int cnt[3];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i, S.length()) cnt[S[i] - 'a']++;
    set<char>st;
    rep(i, S.length()) st.insert(S[i]);
    sort(cnt, cnt + 3);
    if(cnt[2] - cnt[0] > 1) {
        cout << "NO" << endl;
    } else if(cnt[2] - cnt[0] <= 1) {
        cout << "YES" << endl;
    }


    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int num = x;
        int result = 1;
        while (num % 360 != 0) {
            num += x;
            result++;
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35712