akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int64_t n,ans;
  cin>>n;
  ans=0;
  if(n%2==0)
  {
    for(int64_t i=10;;i*=5)
    {
      int64_t v=n/i;
      ans+=v;
      if(v==0)
        break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
/*
g++ -std=c++11 -o2 -Wall sound_hound_C.cpp.cpp -o ./out/sound_hound_C.cpp.out
./out/sound_hound_C.cpp.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

constexpr ll INF = 10000000000000000;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  double n, m, d;
  cin >> n >> m >> d;
  double ans;
  if (d == 0) {
    ans = (m - 1) / n;
  } else {
    ans = 2 * (n - d) * (m - 1) / (n * n);
  }
  printf("%.10lf \n", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <string>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;

int f[55][55];
int g[55][3];
int vis[105][55][55];
int dp[55];
int dp1[55][3];

int C[3];

int main() {
    int n, m;
    scanf("%d%d%d%d%d", &n, &m, &C[0], &C[1], &C[2]);
    
    for (int i = 1; i <= m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        f[y][x] = 1;
    }
    for (int i = 1; i <= n; ++i)
        vis[0][i][i] = 1;
    for (int k = 0; k < 100; ++k)
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                if (vis[k][i][j]) {
                    for (int l = 1;  l <= n; ++l)
                        vis[k + 1][i][l] |= vis[k][i][j] & f[j][l];
                }
    queue<int> que;
    memset(dp, 63, sizeof(dp));
    memset(dp1, 63, sizeof(dp1));
    dp[n] = 0;
    dp1[n][0] = dp1[n][1] = dp1[n][2] = 0; 
    que.push(n);
    while (!que.empty()) {
        int x = que.front(); que.pop();
        //out << x << endl;
        for (int i = 1; i <= n; ++i)
            if (dp[i] > n * n) {
                for (int j = 0; j < 3; ++j)
                    if (vis[C[j]][x][i])
                        dp1[i][j] = min(dp[x] + 1, dp1[i][j]);
                if (dp1[i][0] <= n * n && dp1[i][1] <= n * n && dp1[i][2] <= n * n) {
                    dp[i] = 0;
                    for (int j = 0; j < 3; ++j)
                        dp[i] = max(dp[i], dp1[i][j]);
                    que.push(i);
                }
            }
    }
    if (dp[1] > n * n) puts("IMPOSSIBLE");
    else printf("%d\n", dp[1]);
    return 0;
}

Measured memory_bytes: 2404
N = int(input())
T = list(map(int,input().split()))
M = int(input())
info = [list(map(int,input().split())) for i in range(M)]
s = sum(T)
for e in info:
    p = e[0]
    x = e[1]
    ans = s - T[p-1] + x
    print(ans)

Measured memory_bytes: 3060
def primes(n):
    ass = []
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**0.5)+1):
        if not is_prime[i]:
            continue
        #i**2から始めてOK
        for j in range(i*2,n+1,i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

p_list = primes(55555)
ans = []
for p in p_list:
    if p%5 == 1:
        ans.append(p)

n = int(input())

print(' '.join(map(str,ans[:n])))


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s;
    cin >> s;
    int x = 700;
    rep(i, s.size()) {
        if (s[i] == 'o') {
            x += 100;
        }
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3588
program abc159f
  integer :: n, s, i, ans=0, a(3000), dp(0:3000)=0
  read *, n, s
  read *, a(:n)
  do i = 1,n
     dp(0) = i
     dp(a(i):s) = mod(dp(:s-a(i))+dp(a(i):s),998244353)
     ans = mod(ans+dp(s),998244353)
  end do
  print *, ans
end program abc159f


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

int main () {
  int n,yen;
  int x,y,z;
  cin >> n;
  cin >> yen;
  
  for(x=0; x<=n && x<=yen/10000; x++) {
    for(y=0; y<=n-x && y<=((yen-10000*x)/5000); y++) {
      z=n-(x+y);
      if (10000 * x + 5000 * y + 1000 * z == yen) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5,MAX_M=1e5,INF=1e18;
ll N,M,n2;
struct intv{
	ll L,R,C;
};
intv itv[MAX_M];
bool operator<(intv i,intv j){
	return i.L<j.L;
}
ll seg[MAX_N<<2];
void lazpro(ll k,ll a,ll b){
	if(b-a==1||seg[k]==INF){
		return;
	}
	seg[k*2+1]=min(seg[k*2+1],seg[k]);
	seg[k*2+2]=min(seg[k*2+2],seg[k]);
	seg[k]=INF;
}
	
void segchange(ll l,ll r,ll x,ll k,ll a,ll b){
	if(r<=a||b<=l){
		return;
	}
	lazpro(k,a,b);
	if(l<=a&&b<=r){
		seg[k]=min(seg[k],x);
	}else{
		ll m=(a+b)>>1;
		segchange(l,r,x,k*2+1,a,m);
		segchange(l,r,x,k*2+2,m,b);
	}
}
ll segquery(ll i,ll k,ll a,ll b){
	lazpro(k,a,b);
	if(b-a==1){
		return seg[k];
	}
	ll m=(a+b)>>1;
	if(i<m){
		return segquery(i,k*2+1,a,m);
	}else{
		return segquery(i,k*2+2,m,b);
	}
}	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M;
	REP(i,M){
		cin>>itv[i].L>>itv[i].R>>itv[i].C;
		itv[i].L--;
	}
	sort(itv,itv+M);
	int ite=0;
	n2=1;
	while(n2<N)n2<<=1;
	REP(i,n2){
		seg[i+n2-1]=(i==0?0:INF);
	}
	REP(i,n2-1){
		seg[i]=INF;
	}
	REP(v,N-1){
		while(ite<M&&itv[ite].L==v){
			segchange(itv[ite].L+1,itv[ite].R,segquery(v,0,0,n2)+itv[ite].C,0,0,n2);
			ite++;
		}
	}
	ll ans=segquery(N-1,0,0,n2);
	if(ans==INF)ans=-1;
	cout<<ans<<endl;
}

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

using namespace std;

int main()
{
   int i,cnt=0;
   string s;
   cin>>s;
   
   for(i=0;i<s.length();++i)
       {
           if(s[i]=='1')
              cnt++;
       }
       
       cout<<cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#define _USE_MATH_DEFINES
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    int h1, m1, h2, m2, k;
    cin>>h1>>m1>>h2>>m2>>k;
    int t1 = h1*60 + m1, t2 = h2*60+m2;

    int ans = max(0, t2-k-t1);

    cout<<ans<<"\n";

    return 0;
}






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

long long N;
int main(){
	cin >> N;
	int count = 0;
	for(int i = 1; i<=N; i++){
		if(to_string(i).size() % 2 == 1){
			count++;
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
    int a,b,c,d,ans,tmp;
    string s;
 
    a = b = c = d = ans = tmp = 0;
    //vector<int>a();

    cin >> a >> b >> c >> d;
    for(int i = 0; i < d;i++){
        if(a >= b){
            b = b*2;
        }else if(b >= c){
            c = c*2;
        }else{
           c = c*2; 
        }
    }
       if(b > a && c > b){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    
  

}


Measured memory_bytes: 3616
#include<iostream>;
using namespace std;
int main(){
	int cntAC = 0 , cntWA = 0 , cntTLE = 0, cntRE = 0;
	int N;
	cin>>N;
	
	string S[N];
	
	for(int i=0; i<N;i++){
		cin>> S[i];
	}
	
	for(int i=0; i<N;i++){
		if(S[i] == "AC"){
			cntAC++;
		}
		
		else if(S[i] == "WA"){
		cntWA++;
		}
		
		else if(S[i] == "TLE"){
			cntTLE++;
		}
		
		else {
			cntRE++;
		}
	}
	
	cout<<"\n";
	cout<< "AC x " << cntAC <<"\n";
	cout<< "WA x " << cntWA  <<"\n";
	cout<< "TLE x " << cntTLE <<"\n";
	cout<< "RE x " << cntRE << "\n";
	
	return 0;
}


Measured memory_bytes: 6740
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())

l = []
for i in range(100//4):
    for j in range(100//7):
        l.append(i*4+j*7)
if n in l:
    print("Yes")
else:
    print("No")





Measured memory_bytes: 9120
#include<stdio.h>
int main(void){  
    int i, n;    
    int arr[100];   
    scanf("%d", &n);    
    for(i=0;i<n;i++){        
        scanf(" %d", &arr[i]);   
        }    
        for(i=0;i<n;i++){     
            if(i)printf(" "); 
            printf("%d", arr[n-i-1]);   
            }  
            printf("\n");   
            return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int n; cin >> n;
    ll ans = 0;
    rep(i, 1, n + 1)
    {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    res = ['AC', 'WA', 'TLE', 'RE']
    n = ii()
    ans = [0 for i in range(4)]
    for i in range(n):
        tmp = input()
        for j in range(4):
            if tmp == res[j]:
                ans[j] += 1

    print('AC x ' + str(ans[0]))
    print('WA x ' + str(ans[1]))
    print('TLE x ' + str(ans[2]))
    print('RE x ' + str(ans[3]))


main()


Measured memory_bytes: 10040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define repd(i, a, b) for (int i = a; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main()
{
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    for (int i = k + 1; i <= n; i++)
    {
        int t = max(0, i - k);
        ans += (n / i) * t + (max(0, n % i - k + (k != 0)));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3508
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;
  cin>>N>>M;
  cout<<(N*(N-1)+M*(M-1))/2<<endl;

}

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

const int MAX = 2500000;
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 r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  
  ll ans = (COM(r2+c2+2, c2+1) + COM(r1+c1, r1)) % MOD;
  ans = (ans - COM(r2+c1+1, c1)% MOD + MOD) % MOD;
  ans = (ans - COM(r1+c2+1, c2+1)% MOD + MOD) % MOD;
  
  cout << ans << endl;

}

Measured memory_bytes: 58880
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main(){
    fast;
    ll a; cin>>a;
    vec<ll> m(a-1);
    ll o = 0;
    for(int q=0; q<a-1; q++) cin>>m[q];
    vec<ll> n(a, 1e9);
    for(int q=a-2; q>=0; q--){
        n[q] = min(m[q], n[q]);
        n[q+1] = min(m[q], n[q+1]);
    }
    for(ll i : n) o+=i;
    cout<<o;
}

Measured memory_bytes: 256
R, G, B, N = map(int, raw_input().split())

count = 0
r_max = int(N / R)+1
g_max = int(N / G)+1

for r in xrange(r_max):
    rest_val = N - R*r
    for g in xrange(g_max):
        rest_val2 = rest_val - G * g
        if rest_val2 < 0: break
        if rest_val2 % B == 0:
            # print "r="+str(r)+",g="+str(g)+",b="+str(rest_val2/B)
            count += 1

print count

Measured memory_bytes: 2568
import math

A, B, H, M = map(int, input().split())


kakuA = 2*math.pi*(H*60+M) / (12*60)
kakuB = 2*math.pi*M / 60
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(abs(kakuA-kakuB))))

Measured memory_bytes: 62376
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] p = new int[N];
        for (int i = 0; i < N; i++) {
            p[i] = Integer.parseInt(sc.next());
        }

        int ctn = 0;
        for (int i = 0; i < N; i++) {
            if (p[i] == i + 1) {
                continue;
            }
            ctn++;
        }
        if (ctn > 2) {
            System.out.println("NO");
        } else {
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 23892
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

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

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> data(2,vector<int>(n));
	rep(i, 0, 2) {
		rep(j, 0, n) {
			cin >> data[i][j];
		}
	}
	vector<vector<int>> amax(2, vector<int>(n));
	amax[0][0] = data[0][0];
	amax[1][0] = data[0][0] + data[1][0];
	int ans = 0;
	rep(i, 1, n) {
		
		amax[0][i] = amax[0][i - 1] + data[0][i];
		amax[1][i] = max(amax[0][i], amax[1][i - 1]) + data[1][i];
		
	}
	
	cout << amax[1][n-1] << endl;

	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
   if(a%b==0)return b;
   else return gcd(b,a%b);
}
int main()
{
    int a[100010],n,b,c,ans,i;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];

    }
    b=gcd(a[0],a[1]);
    ans=b;
    for(i=2;i<n;i++)
    {
        ans=gcd(b,a[i]);
        b=ans;
    }
    cout<<ans<<endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int a;
  int n = N;
  int f = 0;
  for(int i = 0; i < 8; i++){
    a = n % 10;
    f += a;
    n = (n - a) / 10;
  }
  
  if(N % f == 0){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import scala.io.StdIn._
import scala.math._

object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val x = sc.nextInt
  val a = sc.nextInt
  val b = sc.nextInt
  if(abs(x-a)<abs(x-b)){
    println("A")
  }
  else{
    println("B")
  }
}


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

int main(void) {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    printf("%lf ", W * H / 2.0);
    if (x * 2 == W && y * 2 == H) {
        printf("1\n");
    } else {
        printf("0\n");
    }
    return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<long long int> a(n);
    vector<long long int> dp(n,10000*1000000);
    for(int i =0;i<n;i++){
        cin >> a[i];
    }
    dp[0] = 0;dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        int c = min(i, k);
        for(int l=1; l <= c;l++){
            dp[i] = min(dp[i], dp[i-l]+abs(a[i]-a[i-l]));
        }
    }
    cout << dp[n-1] << endl;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

struct Edge {
    int to, id;
    Edge(int t, int i) : to(t), id(i) {}
};

vector<vector<Edge>> g;
vi ans;
void dfs(int v, int p=-1, int c=-1) {
    int k = 1;
    for (Edge te : g[v]) {
        int ti = te.to, ei = te.id;
        if (ti == p) continue;
        if (k == c) ++k;
        ans[ei] = k;
        dfs(ti, v, k);
        ++k;
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    ans.resize(n-1);
    dfs(0);
    int dmx = 0;
    rep(i, n) dmx = max(dmx, sz(g[i]));
    cout << dmx << endl;
    rep(i, n-1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 11024
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi a(n);
  
  rep(i,n){
    cin>>a[i];
    a[i]-=i+1;
  }

  sort(all(a));

  int b=a[n/2];

  int ans=0;
  rep(i,n){
    ans+=abs(a[i]-b);
  }

  cout<<ans<<endl;


}

Measured memory_bytes: 1792
#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 main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  cout << max(0, a - 2 * b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
#define REP(i, n) for(int i=0; i<n; i++)
#define ll long long
ll INF = 10e16+1;
ll n, t;
ll a[100000];
 
int main(){
    cin >> n >> t;
    REP(i, n) cin >> a[i];
 
    ll tmin = INF;
    ll p = 0;
    REP(i, n){
        tmin = min(tmin, a[i]);
        p = max(p, a[i] - tmin);
    }
 
    ll tmin2 = INF;
    ll c = 0;
    REP(i, n){
        tmin2 = min(tmin2, a[i]);
        if(a[i] - tmin2 == p){
            c += 1;
        }
    }
    cout << c << endl;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in();
    vll a = in(n);
    vll s(n + 1);
    rep(i, n) s[i + 1] = s[i] + a[i];

    ll ans = LINF;
    rep(i, n - 1)
    {
        ll x = s[i + 1] - s[0];
        ll y = s[n] - s[i + 1];
        ans = min(ans, abs(x - y));
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3456
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

m = b[a[0]-1]
now = a[0]
for i in range(1, len(a)):
   if (now == a[i] - 1):
      m += b[a[i]-1] + c[now-1]
   else:
      m += b[a[i]-1]
   now = a[i]

print(m)


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

int main()
{
    int n,m;
    cin>>n>>m;
    int arr[m],sum=0;
    for(int i=0;i<m;i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    int out=-1;
    if(sum<=n)
    {
        out=n-sum;
    }
    cout<<out<<endl;
    return 0;

}



Measured memory_bytes: 3636
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve(parseProblem())
}

func parseProblem() scorer {
	d := scanInt(sc)
	v := 26
	cs := make([]int, v)
	for i := 0; i < v; i++ {
		cs[i] = scanInt(sc)
	}
	ss := make([][]int, d)
	for i := range loop0(d) {
		ss[i] = make([]int, v)
		for j := range loop0(v) {
			ss[i][j] = scanInt(sc)
		}
	}
	return scorer{
		d: d, v: v,
		cs: cs, ss: ss,
	}
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}

type scorer struct {
	// 0-indexed
	d, v int
	cs   []int
	ss   [][]int // [<d][<v]
}

func (scr scorer) greedyGen() []int {
	result := make([]int, scr.d)
	lasts := make([]int, scr.v)
	for i := range loop0(scr.d) {
		max, maxT := math.MinInt32, 0
		for j := range loop0(scr.v) {
			v := scr.ss[i][j] + scr.cs[j]*(j+1-lasts[j])
			if max < v {
				max = v
				maxT = j
			}
		}
		lasts[maxT] = i + 1
		result[i] = maxT + 1
	}
	return result
}

func (scr scorer) receiveInput(sc *bufio.Scanner) []int {
	satisfaction := 0
	lasts := make([]int, scr.v)
	results := make([]int, scr.d)
	for day := range loop0(scr.d) {
		tipe := scanInt(sc) - 1
		satisfaction += scr.ss[day][tipe]
		lasts[tipe] = day + 1
		for cType := range loop0(scr.v) {
			satisfaction -= scr.cs[cType] * (day + 1 - lasts[cType])
		}
		results[day] = satisfaction
	}
	return results
}

func resolve(scr scorer) {
	for _, v := range scr.greedyGen() {
		fmt.Println(v)
	}
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,K;
string S;
cin>>N>>K;
cin>>S;

transform(S.begin()+K-1,S.begin()+K,S.begin()+K-1,::tolower);
cout<<S<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    if(s[0]=='9' or s[1]=='9') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

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

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

char A[55][55], B[55][55];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int N, M; cin >> N >> M;

    FOR(i,1,N+1) FOR(j,1,N+1) {
        cin >> A[i][j];
    }

    FOR(i,1,M+1) FOR(j,1,M+1) {
        cin >> B[i][j];
    }

    bool ok = false;
    FOR(i,1,N+1) FOR(j,1,N+1) {
        if (i+M-1 > N || j+M-1 > N) continue;
        bool e = true;
        FOR(ii,1,M+1) FOR(jj,1,M+1) {
            e &= B[ii][jj] == A[i+ii-1][j+jj-1];
        }
        ok |= e;
    }

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

}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int r,d;
  ll x;
    cin >> r >> d >> x;
  int tmp;
    rep(i,10)
    {
      x = r * x - d;
      cout << x << endl;
    }
      
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
color = [0, 0, 0]
ans = 1
for i in a:
    if i in color:
        ans *= (color.count(i))
        ans %= mod
        color[color.index(i)] += 1
    else:
        ans = 0
        break
print(ans)

Measured memory_bytes: 13964
/************************************************************
	>>--> Author: Frederick
	>>--> Mail: 197***3881@qq.com
************************************************************/
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
#define ull unsigned long long
#define CIN ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int MAXN=2e5+10;
const ll MOD=1e9+7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
	CIN;
	ll n;
	cin>>n;
	ll k,s;
	cin>>k>>s;
	ll sum=k+s,ans=0;
	if(s==n&&k==s-1) ans=1;
	else if(n==2) ans=1;
	else if(sum%2==0) ans=(s-k)/2;
	else {
		if(k<=(n-s)){
			ans+=k;
			s-=k;
			k=1;
			if(s!=k) ans+=(s-k)/2;
		}
		else{
			if(n%2!=0) ans+=n-s+1;
			else ans+=n-s;
			k+=n-s+1;
			s=n;
			if(s!=k&&n%2==0) ans+=(n-k+1+n-s+1)/2;
			else ans+=(s-k)/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

// 7  1  3  1 2 3 4 5  
// 1 2 3 4 5 6 7     2 5  1 5 
// 1 2 3 4 5 6 7 8 9  10  6 9    2 7 1 7  4
// 2 5  4 9 6    2 5  1 3

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s;
    cin>>s;
    int n = s.size(), i;
    bool is = true, is1 = true, is2 = true;
    FOR0(i, n)
    {
        if(s[i] != s[n-1-i]) is = false;
    }
    FOR0(i, (n-1)/2)
    {
        if(s[i] != s[(n-1)/2 -1 -i]) is1 = false;
    }
    int j = n-1;
    i = (n+3)/2 - 1;
    while(i < n)
    {
        if(s[i] != s[j]) is2 = false;
        i++;
        j--;
    }
    if(is && is1 && is2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
def count_if(f, lst):
    count = 0

    for l in lst:
        count += 1 if f(l) else 0

    return count

def main():
    count = 0

    word = input().lower()

    while True:
        line = input();

        if line == 'END_OF_TEXT':
            break

        count += count_if(lambda w: word == w.lower(), line.split())

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
  int n;
  cin >> n;
  cout << n/2 + n%2 << endl;
return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	ll N=in<ll>(),M=in<ll>();
	vector<vector<ll>> T(M);
	priority_queue<ll> Q;
	REP(i,N){
		ll a = in<ll>(), b = in<ll>();
		if(a-1>=M) continue;
		T[a-1].emplace_back(b);
	}

	int start=0,end=N;
	ll sum = 0;
	for(int n=0;n<M;n++){
		for(auto& x:T[n]){
			Q.push(x);
		}
		if(!Q.empty()){
			auto v = Q.top();
			Q.pop();
			sum += v;
		}
	}
	
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5632
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
  int i,j;
  int n,max,min,bf,swap;
  scanf("%d",&n);
  char s[n][9];
  for(i=0;i<n;i++)
    scanf("%s",s[i]);
  for(i=0;i<n;i++){
    do{
      bf=0;
      for(j=1;j<strlen(s[i]);j++){
	if(s[i][j-1]<s[i][j]){
	  swap=s[i][j-1];
	  s[i][j-1]=s[i][j];
	  s[i][j]=swap;
	  bf=1;
	}
      }
    }while(bf);
    max=0;
    min=0;
    for(j=0;j<8;j++){
      min+=(s[i][j]-'0')*pow(10,j);
      max+=(s[i][j]-'0')*pow(10,7-j);
    }
    printf("%d\n",max-min);
  }
  return 0;
}

Measured memory_bytes: 0
loop do
	nums = gets.chomp.split(" ").map(&:to_i)
	break if nums == [0,0]
	for h in (0...nums[0]) do
		for w in (0...nums[1]) do
			if h == 0 || h == nums[0]-1 || w == 0 || w == nums[1]-1
				print "#"
			else
				print "."
			end
		end
		puts
	end
	puts
end

Measured memory_bytes: 8684
#include <stdio.h>
#define NIL -1

struct node{
	int p,l,r;
};

struct node T[100000];
int n,D[100000];

void print(int u){
	int i,c;
	printf("node %d:",u);printf(" ");
	printf("parent = %d",T[u].p);printf(", ");
	printf("depth = %d",D[u]);printf(", ");
	if(T[u].p==NIL){
		printf("root");printf(", ");
	}
	else if (T[u].l==NIL){
		printf("leaf");printf(", ");
	}
	else {
		printf("internal node");printf(", ");
	}
	printf("[");
	for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
		if(i!=0)
			printf(", ");printf("%d",c);
	}
	printf("]\n");
}

	void rec(int u,int p){
		D[u]=p;
		if(T[u].r!=NIL)
			rec(T[u].r,p);
		if(T[u].l!=NIL)
			rec(T[u].l,p+1);
	}

	int main(){
		int i,j,k,id,c,r,l;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			T[i].p=T[i].l=T[i].r=NIL;
		}
		for(i=0;i<n;i++){
			scanf("%d%d",&id,&k);
			for(j=0;j<k;j++){
				scanf("%d",&c);
				if(j==0)
					T[id].l=c;
				else
					T[l].r=c;
				l=c;
				T[c].p=id;
			}
		}
		for(i=0;i<n;i++){
			if(T[i].p==NIL)
				r=i;
		}
		rec(r,0);
		for(i=0;i<n;i++)
			print(i);
		return 0;
}


Measured memory_bytes: 6380
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    sort(ar, ar+n);
    int ans=ar[n-1];
    int k=n-2;
    for(int i=n-2;i>=0&&k>0;i--)
    {
        ans+=ar[i];
        k--;
        if(k>0)
        {
            ans+=ar[i];
            k--;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 5168
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin>>n;
	int dp[n+1][3];
	for(int j=0;j<3;j++){
		cin>>dp[1][j];
	}
	for(int i=2;i<=n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c;
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]});
}


Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,x_max=0,x_min=1000;
  cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++) cin>>v.at(i);
  for(int i=0;i<N;i++){
    x_max=max(x_max,v.at(i));
    x_min=min(x_min,v.at(i));
  }
  cout<<x_max-x_min<<endl;
}

Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
c,d=map(int,input().split())
a-=1;b-=1;c-=1;d-=1
def f(x, y, z):
    return abs(x//(z+1)-y//(z+1))+abs(x%(z+1)-y%(z+1))
print(min([f(a,b,i+1)+f(c,d,i+1) for i in range(n)]))


Measured memory_bytes: 5608
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MOD = (int)1e9 + 7;
const int M = (1 << 17);

int mem[M];
int dp[2][M];
int n, x, y, z;
int ans;

int addMod(int a, int b, int m = MOD) {
  a += b;
  
  if (m <= a) {
    a -= m;
  }
  
  return a;
}

bool bit(int x, int p) {
  return x & (1 << p);
}

int good(int mask) {
  int &ret = mem[mask];
  
  if (ret != -1) {
    return ret;
  }
  
  vector<int> vec;
  int prv = -1;

  for (int i = 16; i >= 0; --i) {
    if (bit(mask, i)) {
      if (prv != -1) {
        vec.pb(prv - i);
      }
      
      prv = i;
    }
  }
  
  if (prv != -1) {
    vec.pb(prv + 1);
  }
  
  int n = (int)vec.size();
  
  for (int i = 0; i < n; ++i) {
    int state = 0, cur = 0;
    
    for (int j = i; j < n; ++j) {
      cur += vec[j];
      
      if (state == 0 && cur == x) {
        state = 1;
        cur = 0;
      }
      else if (state == 1 && cur == y) {
        state = 2;
        cur = 0;
      }
      else if (state == 2 && cur == z) {
        state = 3;
        cur = 0;
      }
    }
    
    if (state == 3) {
      return ret = 0;
    }
  }
  
  return ret = 1;
}

void solve() {
  scanf("%d %d %d %d", &n, &x, &y, &z);
  dp[0][0] = 1;
  
  for (int mask = 0; mask < M; ++mask) {
    mem[mask] = -1;
  }
  
  for (int i = 1; i <= n; ++i) {
    for (int mask = 0; mask < M; ++mask) {
      for (int j = 1; j <= 10; ++j) {
        int nmask = (mask << j) + (1 << (j - 1));
        nmask &= (M - 1);
        
        if (good(nmask)) {
          dp[1][nmask] = addMod(dp[1][nmask], dp[0][mask]);
        }
      }
    }
    
    for (int mask = 0; mask < M; ++mask) {
      dp[0][mask] = dp[1][mask];
      dp[1][mask] = 0;
    }
  }
  
  for (int mask = 0; mask < M; ++mask) {
    ans = addMod(ans, dp[0][mask]);
  }
  
  int rest = 1;
  
  for (int i = 1; i <= n; ++i) {
    rest = (rest * 10ll) % MOD;
  }
  
  printf("%d\n", addMod(rest, MOD - ans));
}

int main() {
  int tt = 1;
  
  while (tt--) {
    solve();
  }

  return 0;
}



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

int field[100][100];
int gain[100][100];

int main(){
    int N, W, H, x, y, i, j, k, l, s, t, max_p;
    while( cin >> N, N ){
        cin >> W >> H;
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                field[i][j] = 0;
                gain[i][j] = 0;
            }
        }
        while( N-- > 0 ){
            cin >> x >> y;
            field[y-1][x-1] = 1;
        }
        cin >> s >> t;
        max_p = 0;
        for(i = 0; i < H; i++){
            for(j = 0; j < W; j++){
                if( field[i][j] ){
                    for(k = 0; k < t && i+k < H; k++){
                        for(l = 0; l < s && j+l < W; l++){
                            gain[i+k][j+l] += 1;
                        }
                    }
                }
                if( gain[i][j] > max_p ) max_p = gain[i][j];
            }
        }
        cout << max_p << endl;
    }
    return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
struct qwq{int a,b;}s[200010];
ll dp[200010][31];
bool operator<(const qwq&a,const qwq&b){
	if(!a.a&&!b.a)return a.b<b.b;
	if(!a.a||!b.a)return a.a>b.a;
	return 1.*a.b/a.a<1.*b.b/b.a;
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),T=gi();
	for(int i=1;i<=n;++i)s[i].a=gi(),s[i].b=gi();
	for(int i=1;i<=n;++i)s[i].b+=s[i].a+1;
	std::sort(s+1,s+n+1);
	for(int i=1;i<=30;++i)dp[0][i]=T+1;
	dp[0][0]=0;
	int p=n+1;
	for(int i=1;i<=n;++i)
		if(s[i].a){
			dp[i][0]=0;
			for(int j=1;j<=30;++j)dp[i][j]=std::min(dp[i-1][j],dp[i-1][j-1]*(s[i].a+1)+s[i].b);
		}else{p=i;break;}
	int ans=0;
	for(int i=0;i<=30;++i){
		ll S=dp[p-1][i];if(S>T)continue;
		for(int j=p;j<=n+1;++j){
			if(S+s[j].b<=T&&j<=n)S+=s[j].b;
			else{cxk(ans,i+j-p);break;}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 50304
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,a,b=mp()
x=lmp()
ans=0
for i in range(n-1):
    ans+=min((x[i+1]-x[i])*a,b)
print(ans)

Measured memory_bytes: 16304
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ? (int)2e18 : (int)1e9+10;
signed main(){
    int n;
    int sos[400000]={0,0,1};
    loop(i,3,400000){
        int t=1;
        for(int j=2;j*j<=i;j++)if(i%j==0)t=0;
        sos[i]=t;
    }
    while(cin>>n,n){
        int co=0;
        loop(i,n+1,n+n+1)co+=sos[i];
        cout<<co<<endl;
    }

}



Measured memory_bytes: 4540