akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <string>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

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

    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        int sum = a[i] + a[i + 1];
        if(sum > x) {
            int temp = a[i + 1];
            ans += min(sum - x, temp);
            a[i + 1] -= min(sum - x, temp);
            if(a[i] + a[i + 1] > x) {
                ans += sum - min(sum - x, temp) - x;
                a[i] -= sum - min(sum - x, temp) - x;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
ll mod=1e9+7;

ll fac[1000010];
 
ll modinv(ll a){
    ll b=mod,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
        }
        u%=mod;
        if(u<0) u+=mod;
    return u;
}
 
void modfac(){
    fac[0]=1;
    for(ll i=1;i<1000010;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}
 
ll modperm(ll n,ll k){
    if(n<0||k<0||n<k) return 0;
    else return (fac[n]*modinv(fac[n-k]))%mod;
}
 
ll modcomb(ll n,ll k){
    if(n<0||k<0||n<k) return 0;
    else return ((fac[n]*modinv(fac[k]))%mod*modinv(fac[n-k]))%mod;
}
 
ll modpow(ll a,ll b){
  ll ans=1;
  a%=mod;
  while(b){
    if(b&1) ans=ans*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  return ans;
}

ll a[3000],b[3000];

int main(){
  ll n,k;
  cin >> n >> k;
  modfac();
  for(ll i=1;i<=k;i++) a[i]=modcomb(k-1,k-i);
  for(ll i=1;i<=n-k;i++) b[i]=modcomb(n-k-1,n-k-i);
  if(n==k) b[0]=1;
  for(ll i=1;i<=k;i++){
    cout << a[i]*(b[i-1]+2*b[i]+b[i+1])%mod << endl;
  }
}

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


using namespace std;

int main(){
    int N,X,L,D = 0,cnt = 1;
    int flag = 1;
    int ans = 0;
    cin >> N >> X;

    for(int i = 0; i < N; i++){
        cin >> L;
        D += L;
        
        if(D > X && flag){
            ans = cnt;
            flag = 0;
        }
        
        cnt++;
    }

    
    if(flag) ans = cnt;
    
    
    cout << ans <<endl;

    

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n),b(n);
  REP(i,n)cin>>a[i]>>b[i];
  sort(ALL(a));
  sort(ALL(b));
  ll ans;
  if(n%2==1)
    ans=b[n/2]-a[n/2]+1;
  else
    ans=(b[n/2-1]+b[n/2])-(a[n/2-1]+a[n/2])+1;
  cout<<ans<<endl;



}



Measured memory_bytes: 6372
from itertools import count, takewhile
 
def dfs(n, d={}):
  if n < 6:
    return n
  if n in d:
    return d[n]
  max9 = max(takewhile(lambda x: x<=n, (9**i for i in count())))
  max6 = max(takewhile(lambda x: x<=n, (6**i for i in count())))
  d[n] = min(dfs(n-max9), dfs(n-max6))+1
  return d[n]
 
print(dfs(int(input())))

Measured memory_bytes: 3064
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		String S = sc.next();
		int N = S.length();
		String s2 = S.substring(0, ((N - 1) / 2));
		String s3 = S.substring(((N + 3) / 2) - 1, N);
		System.out.println(judge(S) && judge(s2) && judge(s3) ? "Yes" : "No");
	}

	boolean judge(String s){
		char[] chars = s.toCharArray();
		for (int i = 0; i < chars.length / 2; i++) {
			if (chars[i] != chars[chars.length - 1 - i]) {
				return false;
			}
		}
		return true;
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

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

#define deb(x) cout << #x << " " << x << "\n";
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
#define endl "\n"
#define ll long long
#define vi vector<int>

// memset(arr, value, size);

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t, i;
	cin >> t;
	i = ceil((float)t / 1000);
	cout << (i * 1000 - t);

	return 0;
}

Measured memory_bytes: 3644
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-04-30(Thu)
   note   
**********************************************************************/

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

int main() {
  int n; 
  cin >> n;
  string s = to_string(n);
  bool isgood = false;

  if (s.at(0) == s.at(1) && s.at(1) == s.at(2)){
    isgood = true;
  } 
  else if (s.at(1) == s.at(2) && s.at(2) == s.at(3)) {
    isgood = true;
  }

  if (isgood) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

ll gcds[210][210];

void gcdInit() {
	repk(i,1,201) {
		repk(j,1,201) {
			gcds[i][j] = gcd(i, j);
		}
	}
}

// 最大公約数のll版
ll gcd(ll a, ll b) {
	if (a < b) swap(a, b);
	return b == 0 ? a : gcd(b, a%b);
}

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

	ll K;
	cin >> K;


	gcds[1][1] = 1;

	//gcdInit();



	repk(a,1,K+1) {
		repk(b, 1, K + 1) {
			int ab = gcd(a, b);
			repk(c, 1, K + 1) {
				ans += gcd(ab, c);
			}
		}
	}
	

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
int t;
LL x,y;
LL Sqrt(LL x) {
    LL l=0,r=1e9+1;
    while (l<r) {
	LL mid=(l+r+1)/2;
	if (mid*mid<=x) l=mid;
	else r=mid-1;
    }
    return l;
}
int main() {
    scanf("%d",&t);
    while (t--) {
	scanf("%lld%lld",&x,&y);
	LL sum=x*y-1;
	LL now=Sqrt(sum);
	LL ans=now+sum/(now+1)-1;
	if (x==y) ans++;
	printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[5];
		for (int i = 0; i < 5; i++) {
			arr[i] = sc.nextInt();
		}
		int k = sc.nextInt();
		if (arr[4] - arr[0] > k) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}
	}
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 4e4 + 5;
const ll LINF = 1e18 + 5;
const int mod = 1e9 + 7;
int n, k;
ll f[105][N], g[105][N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	ll d = sqrt(n);
 	f[0][1] = 1;
 	for(int i=1; i<=k; i++)
 	{
 		for(int j=1; j<=d; j++) (f[i-1][j] += f[i-1][j-1]) %= mod;
		for(int j=1; j<=d; j++) (g[i-1][j] += g[i-1][j-1]) %= mod;
		for(int j=1; j<=d; j++)
		{
			f[i][j] = (f[i-1][d] + g[i-1][d] - g[i-1][j-1] + mod)%mod;
			g[i][j] = (n/j - n/(j+1))*f[i-1][j]%mod;
			g[i][j] = (g[i][j] + mod)%mod;
			if(j==n/j) g[i][j] = 0;
		}
 	}
 	ll ans = 0;
 	for(int i=1; i<=d; i++) (ans += f[k][i]) %= mod;
 	for(int i=1; i<=d; i++) (ans += g[k][i]) %= mod;
 	cout << ans;
	return 0;
}


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

char a[100][101], b[102][102];

int main(){
  int h, w;
  cin >> h >> w;
  
  for(int i = 0; i < h; i++){
    cin >> a[i];
  }
  
  for(int i = 0; i < h + 2; i++){
    for(int j = 0; j < w + 2; j++){
      b[i][j] = '#';
    }
  }
   
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      b[i + 1][j + 1] = a[i][j];
    }
  }
  
  for(int i = 0; i < h + 2; i++){
    for(int j = 0; j < w + 2; j++){
      cout << b[i][j];
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    cout << "Christmas" << "\n";
    REP(i,25-N)cout << "Eve" << "\n";
}

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

typedef long long ll;
const int N = 1e5 + 100;

ll a, b, c, n, ans;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> a >> b >> c >> n;
	for (ll i = 0; i * a <= n; i++)
		for (ll j = 0; i * a + j * b <= n; j++)
			ans += ((n - i * a - j * b) % c == 0);
	cout << ans;
	return 0;
}

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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

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

	cin>>N;
	long double a=(N+1)/2;
	cout<<setprecision(15)<<a/N<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));


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

    int n,k,ans = 0;
    cin >> n >> k;
    rep(i,n){
        int h;
        cin >> h;
        if(h >= k){
            ans++;
        }
    }
    cout << ans << endl;
    cout << endl;
    return 0;
}


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

using namespace std;
const int maxn = 1e5 + 1000;
const int mod = 1e9 + 7;
int s[maxn],t[maxn];
char str[maxn];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie();
    int te;
    cin>>str;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]=='A') s[i+1]=s[i]+1;
        else s[i+1]=s[i]+2;
    }
    cin>>str;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]=='A') t[i+1]=t[i]+1;
        else t[i+1]=t[i]+2;
    }
    int n;
    int a,b,c,d;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>a>>b>>c>>d;
        if(((s[b]-s[a-1])-(t[d]-t[c-1]))%3==0){
            cout<<"YES"<<endl;
        }
        else {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

int main () {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int g[1003][1003] = {0};
	rep(i, h) {
		rep(j, w) {
			g[i][j] = 1;
		}
	}
	rep(i, h) {
		rep(j, w) {
			if (j < a && i < b) {
				g[i][j] = 0;
			}
			if (j >= a && i >= b) {
				g[i][j] = 0;
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			cout << g[i][j];
			cout << ((j == w-1) ? "\n" : "");
		}
	}
	return 0;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	string S; cin >> S;



	long long ans = 0;
	long long sum;
	int S_len = S.length();
	int N = 1 << (S_len - 1);
	REP(i,N){
		bitset<10> b(i);
		sum = S[0] - '0';
		REP(j,S_len-1){
			if(b[j] == true){
				ans += sum;
				sum = S[j+1] - '0';
			}
			else{ 
				sum *= 10;
				sum += S[j+1] - '0';
			}
		}
		ans += sum;


	}

	cout << ans << endl;
	return 0;

}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long x, long long y){
    set<long long> s1{1, 3, 5, 7, 8, 10, 12}, s2{4, 6, 9, 11};
    if ((s1.count(x) && s1.count(y)) || (s2.count(x) && s2.count(y)) ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return;


}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    solve(x, y);
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

void solve(long long N, std::vector<long long> v) {
  sort(v.begin(), v.end());
  double ans = 0;
  ans += v[0];
  for (int i = 1; i < N; i++) {
    ans = (ans + v[i]) / 2.0;
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> v(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &v[i]);
  }
  solve(N, std::move(v));
  return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

int n,m,ans[5];
bool vis[6];
map<int,int> mp;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    bool no=0;
    for(int i=1; i<=m; i++)
    {
        int s,c;
        cin >> s >> c;
        if (mp.find(s) != mp.end() && mp[s] != c) no=1;
        mp[s] = c;
    }

    if (n>1 && mp.find(1) != mp.end() && mp[1] == 0) no=1;
    if (no) return cout << "-1\n" , 0;

    for(auto it :mp)
        ans[it.f] = it.s , vis[it.f]=1;

    if (!vis[1] && n==1) vis[1]=1 , ans[1]=0;
    
    for(int i=1; i<=n; i++)
    {
        if (!vis[i])
        {
            if (i==1) ans[i]=1;
            else ans[i]=0;
        }
    }

    for(int i=1; i<=n; i++)
        cout << ans[i];

    return 0;
}

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

int main() {
	int k, s;
	cin >> k >> s;
	int ans = 0;
	for (int i = 0; i < k+1; i++) {
		for (int j = 0; j < k+1; j++) {
			if(s-i-j<=k&&s-i-j>=0){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, M, count = 0;
	
	cin >> N >> M;
	
	int K[N], num[M+1] = {};
	
	for(int i=0; i<N; i++){
		cin >> K[i];
		int A[K[i]];
		for(int j=0; j<K[i]; j++){
			cin >> A[j];
			num[A[j]]++;
		}
	}
	
	for(int i=0; i<=M; i++){
		if(num[i] == N)
			count++;
	}
	
	cout << count;
	
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var N, A, B int
	fmt.Scanf("%d %d %d", &N, &A, &B)

	var result int

	result = A * (N / (A + B))

	if (N % (A + B)) >= A {
		result += A
	} else {
		result += (N % (A + B))
	}

	fmt.Println(result)
}


Measured memory_bytes: 1836
import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    n = int(sys.stdin.readline())*3
    s = 0
    p = 0
    while n>0:
        log = sys.stdin.readline()
        if "HIT" in log:
            if p >= 3:
                s += 1 
            else:
                p += 1
        elif "OUT" in log:
            n -= 1
            if n % 3 == 0:
                print(s)
                s = 0
                p = 0
                if n == 0:
                    break
        else:
            s += p + 1
            p = 0  
solve()
        

Measured memory_bytes: 7768
#include<stdio.h>
int main()
{
	int n,a,b;
	scanf("%d",&n);
	a=n%1000;
	//printf("a=%d\n",a);
	if(a!=0){
		b=n/1000;
		b=(b+1)*1000;
		 //printf("b=%d\n",b);
		 printf("%d\n",b-n);
	}
	else printf("%d\n",a);
	return 0;
}


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

using namespace std;

#ifdef LOCAL
#include "/Users/thakchir/Desktop/CP/Library/Debug/Debug.cpp"
#else
#define debug(...) 42
#endif

void RunTestCase() {
  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<int64_t> up = {a, a + 1, b, b - 1};
  vector<int64_t> down = {c, c + 1, d, d - 1};
  int64_t ans = INT64_MIN;
  for (auto &i : up) {
    for (auto &j : down) {
      if (a <= i && i <= b && c <= j && j <= d) {
        ans = max(ans, i * j);
      }
    }
  }
  cout << ans << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  RunTestCase();
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n,p;
    while(cin >> n >> p,n){
        vector<int> ca;
        for(int i=0;i<n;i++) ca.push_back(0);
        int s=p;
        for(int i=0;;i++){
            if(i>=n) i=0;
            if(p){
                p--;
                ca[i]++;
            } else {
                vector<int>::iterator it = find(ca.begin(),ca.end(),s);
                if(it != ca.end()){
                    cout << distance(ca.begin(), it) << endl;
                    break;
                }
                p = ca[i];
                ca[i] = 0;
            }
        }
    }
}

Measured memory_bytes: 1220
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var AB = ReadSplitLong();
            var A = AB[0];
            var B = AB[1];

            var kuchi = 1L;
            var ans = 0;
            while (kuchi < B)
            {
                kuchi--;
                kuchi += A;
                ans++;
            }

            Println(ans);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



//AtCoder
int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    ll a[n], b[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n, greater<>());


    ll ans = 0;
    int l = 0, r = n - 1, mid;
    while (l <= r) {
        ll done[n];
        mid = (l + r) / 2;
        done[mid] = m;
        copy(a, a + n, b);
        ll rem = m * v - m;
        b[mid] += m;
        for (int i = 0; i < n; i++) {
            if (i == mid) continue;
            if (b[i] > b[mid]) {
                ll here = min(m, rem);
                b[i] += here;
                rem -= here;
                done[i] = here;
            }

            else {
                ll here = min({rem, m, b[mid] - b[i]});
                rem -= here;
                done[i] = here;
                b[i] += here;
            }
        }

        for (int i = 0; i < n; i++) {
            if (rem && done[i] < m) {
                ll here = min(rem, m - done[i]);
                rem -= here;
                b[i] += here;
            }
        }

        int g = 0;
        for (ll e : b) g += e > b[mid];
        if (g < p) {
            ans = mid;
            l = mid + 1;
        }

        else {
            r = mid - 1;
        }
    }

    cout << ans + 1;
}

Measured memory_bytes: 2560
#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<ll,ll>;

int main() {
  ll n,m;cin>>n>>m;
  ll n1 = n,m1=m;
  ll sum=1,INF = 1e9+7;
  if (abs(n-m) > 1){
    cout << 0 << endl;
    return 0;
  }
  else {
    while (n>0){
      sum*=n;
      n--;
      sum%=INF;
    }
    while(m>0){
      sum*=m;
      m--;
      sum%=INF;
    }
  }
  if ((n1+m1)%2 == 0){
    cout << (sum*2)%INF << endl;
    return 0;
  }
  else if((n1+m1)%2 == 1){
    cout << sum%INF << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>

int main()
{
  	int K;
  	std::cin >> K;
    auto ll = std::vector<int>(10);
    auto stk = std::stack<std::pair<int, int>>();

    auto count = int(0);
    auto n = int(0);
    while (count != K)
    {
        for (int i = 9; i > 0; --i) stk.emplace(i, n);

        while (!stk.empty() && count != K)
        {
            auto [num, digit] = stk.top();
            ll[static_cast<std::size_t>(digit)] = num;
            stk.pop();

            if (digit != 0)
            {
                for (int j = 1; j >= -1; --j)
                {
                    if (num + j <= 9 && 0 <= num + j)
                    {
                        stk.emplace(num + j, digit - 1);
                        ll[static_cast<std::size_t>(digit - 1)] = num + j;
                    }
                }
            }
            else if (digit == 0)
            {
                ++count;
                ll[0] = num;
            }
        }
        ++n;
    }

    for (int i = n - 1; i >= 0; --i) std::cout << ll[i];
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 3160
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;
int main() {
	cin >> N;
	ans = 0;
	cin >> L;
	for (int i = 1; i < N; i++) {
		cin >> M;

		if (L >= M) {
			ans++;
		}
		L = min(L, M);
	}

	cout << ans+1<< endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define printP(x) "(" << (x).first << ", " << (x).second << ")"
#define mod 998244353
using namespace std;
typedef pair<llint, llint> P;
typedef pair<llint, P> E;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, m, Q;
UnionFind uf(100005);
vector<P> vec[2];
set<llint> S;

int main(void)
{
	cin >> n >> m >> Q;
	llint u, v, t;
	for(int i = 1; i <= Q; i++){
		cin >> u >> v >> t;
		u++, v++;
		vec[t].push_back(P(u, v));
	}
	
	llint lb = 0;
	for(int i = 0; i < vec[0].size(); i++){
		if(!uf.same(vec[0][i].first, vec[0][i].second)) lb++;
		uf.unite(vec[0][i].first, vec[0][i].second);
	}
	
	for(int i = 0; i < vec[1].size(); i++){
		if(uf.same(vec[1][i].first, vec[1][i].second)){
			cout << "No" << endl;
			return 0;
		}
	}
	
	for(int i = 1; i <= n; i++) S.insert(uf.root(i));
	llint c = S.size(), ub = lb + c*(c-1)/2;
	
	if(vec[1].size()) lb = n;
	else lb = n-1;
	
	if(lb <= m && m <= ub) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];

    int sum = 0;
    int max = 0;
    for(int i = 0; i < n; i++){
        sum += p[i];
        if(max < p[i]) max = p[i];
    }

    cout << sum - max/2 << endl;
    return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            var ls = new List<long>();
            for (int i = 0; i < n; i++)
            {
                long tmp = long.Parse(ReadLine());
                ls.Add(tmp);
            }

            ls.Sort();

            long cnt = ls[0];
            int ans = ls.Count;
            bool flug = false;
            for (int i = 1; i < ls.Count; i++)
            {
                if (cnt == ls[i] && !flug)
                {
                    ans -= 2;
                    flug = true;
                }
                else if (cnt == ls[i] &&flug)
                {
                    flug = false;
                }
                else
                {
                    flug = false;
                }

                cnt = ls[i];
            }

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17432
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define pii pair<int, int>
#define pb push_back
#define vec vector
#define beg begin
#define dbg(x) cout << #x << " = " << x << endl;
 
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
 
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i;
    }
    return str;
}
 
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
 
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int n = sz(s);
    if (s[0] == s.back()) {
        if (n % 2 == 0) {
            cout << "First" << endl;
        }
        else {
            cout << "Second" << endl;
        }
    }
    else {
        if (n % 2 == 0) {
            cout << "Second" << endl;
        }
        else {
            cout << "First" << endl;
        }
    }
}

Measured memory_bytes: 3788
from sys import stdin
n,k = map(int,stdin.readline().rstrip().split())
mod = 10**9+7
def combination(n,r,mod=mod):
    r=min(r,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod
for i in range(1,k+1):
    if n-k+1 < i:
        print(0)
    else:
        print(combination(n-k+1,i)*combination(k-1,i-1)%mod)

Measured memory_bytes: 3316
result1 = Array.new
result2 = Array.new
n=1
while true
	n = gets.to_i
	if n==0
	break
	end	
	score1=0
	score2=0
	n.times do
num1,num2 = gets.split.map(&:to_i)
if num1>num2
	score1 += num1+num2
elsif num1<num2
	score2+= num1+num2
else
	score1 += num1
	score2 += num2
end
end
result1.push(score1)
result2.push(score2)
end

while !result1.empty?
puts "#{result1.shift} #{result2.shift}"
end

Measured memory_bytes: 8788
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int count = scn.nextInt();
		int[] mochi = new int[count];
		for (int i = 0; i < count; i++) {
			 mochi[i] = scn.nextInt();
		}
		//int[] mochiSort = new int[count];
		Arrays.sort(mochi);
		int total = 0;
		int tmp = 0;
		for (int i = 0; i < mochi.length; i++) {
			if(tmp != mochi[i] ) {
				tmp = mochi[i];
				total++;
			}
		}
		System.out.println(total);

	}

}


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

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

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

bool f(ll a, ll b){
    return !a || b <= std::numeric_limits<ll>::max() / a;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;
    vector<ll> a(n);

    ll ans = 1;
    rep(i, n){
        cin >> a[i];
    }

    sort(all(a));

    if(a[0] == 0){
        ans = 0;
    }else{
        rep(i, n){
            if(f(a[i], ans)){
                ans *= a[i];
                if(ans > (ll)1e18){
                    cout << -1 << "\n";
                    return 0;
                }
            }else{
                cout << -1 << "\n";
                return 0;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 4008
using System;
public class MA {
    public static void Main() {
        string read = Console.ReadLine();
        int N = int.Parse(read);
        long[] A = new long[N];
        long[] B = new long[N];
        string[] read2 = new string[2];
        for (int i = 0; i < N; i++) {
            read2 = Console.ReadLine().Split(' ');
            A[i] = long.Parse(read2[0]);
            B[i] = long.Parse(read2[1]);
        }
        long button = 0;
        for (int i = N-1; i >=0; i--) {
            if ((A[i]+button) % B[i] != 0) {
                button += (B[i] - (A[i]+button) % B[i]);
            }
        }
        Console.WriteLine(button);
    }
}

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


/*long long int Set(long long int N,long long int pos){return N=N | (1<<pos);}
long long int reset(long long int N,long long int pos){return N= N & ~(1<<pos);}
bool check(long long int N,long long int pos){return (bool)(N & (1<<pos));}*/




int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    long long int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;


    cin>>a;
    if(a>=30)
        cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;


}


Measured memory_bytes: 3640
#include<stdio.h>

int main()
{
  int n,i,j,v,vv,m;
  int map[101][101];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",map[i][j]);
    }
    printf("%d\n",map[i][j]);
  }
  return 0;
}

Measured memory_bytes: 636
#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;
    cin >> n;
    std::vector<std::vector<int>> abc(n, std::vector<int>(3, 0));
    int asum = 0;
    int bsum = 0;
    rep(i, n)
    {
        cin >> abc[i][0];
        asum += abc[i][0];
    }
    rep(i, n)
    {
        cin >> abc[i][1];
        bsum += abc[i][1];
        abc[i][2] = abc[i][0] - abc[i][1];
    }

    if (asum < bsum) {
        cout << -1 << endl;
        return 0;
    }

    std::sort(abc.begin(), abc.end(), [](const std::vector<int>& a, const std::vector<int>& b) { return a[2] < b[2]; });
    int r = n - 1;
    int out = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (abc[i][2] >= 0) {
            break;
        }
        if (sum + abc[i][2] < 0) {
            sum += abc[r][2];
            out++;
            r--;
            i--;
            continue;
        } else {
            sum += abc[i][2];
            out++;
        }
    }
    cout << out << endl;

    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define pb push_back
#define opr iterator
typedef long long ll;
ll a[1001];
ll s[1001];
using namespace std;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> d;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	s[1]=a[1];
	for(int i=2;i<=n;i++)
	{
		s[i]=s[i-1]+a[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
//			cout<<s[j]-s[i]<<" ";
			d.pb(s[j]-s[i]);
		}
//		cout<<endl;
	}
	ll ans=0;
	for(int i=50;i>=0;i--)
	{
		vector<ll>::opr j;
		vector<ll> e;
		sort(d.begin(),d.end());
		for(j=d.begin();j!=d.end();j++)
		{
			if(*j>>i&1)
			{
				e.pb(*j);
			}
		}
		if(e.size()>=k)
		{
			ans+=1ll<<i;
			d=e; 
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6384
#include<iostream>
using namespace std;
int main(){
	int a[7] = { 1, 3, 5, 7, 8, 10, 12 },
		b[4] = { 4, 6, 9, 11 };
	int x, y;
	bool flag=false;

	cin >> x >> y;
	for (int i = 0; i < 7; i++){
		if (a[i] == x){
			for (int j = 0; j < 7; j++){
				if (a[j] == y)
					flag = true;
			}
		}
	}
	for (int i = 0; i < 4; i++){
		if (b[i] == x){
			for (int j = 0; j < 7; j++){
				if (b[j] == y)
					flag = true;
			}
		}
	}
	if (x == 2 && y == 2)
		flag = true;
	else
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=200005;
int n;
char s[maxn];

int main(){
	scanf("%s",s);n=strlen(s);
	int i=0,last=0,ans=0;
	while(i<n){
		ans++;
		if(last==1&&s[i]==s[i-1]){
			if(i==n-1)ans--;
			last=2;
		}
		else last=1;
		i+=last;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 384
while 1:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    ts = dict(zip(range(m), [0] * m))
    for i in range(n):
        for j, p in enumerate(map(int, raw_input().split())):
            ts[j] += p
    print ' '.join([str(k + 1) for k, v
            in sorted(ts.items(), key=lambda x: x[1], reverse=True)])

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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

int main() {
  int n, k; cin >> n >> k;
  if (k == 0) cout << (long long)n*(long long)n << endl;
  else {
    long long ans = 0;
    FOR(i, k+1, n+1) ans += (i-k)*((n+1)/i) + max(0, (n+1)%i - k);
    cout << ans << endl;;
  }
  return 0;
}

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

int main() {
  cin.sync_with_stdio(false);
  int n, q; cin >> n >> q;
  queue<pair<string, int>> Q;
  for(int i = 0; i < n; i++) {
    string s; int t;
    cin >> s >> t;
    Q.emplace(s, t);
  }
  int k = 0;
  while(!Q.empty()) {
    auto p = Q.front(); Q.pop();
    k += min(p.second, q);
    p.second -= min(p.second, q);
    if(p.second == 0) {
      cout << p.first << ' ' << k << '\n';
    }
    else {
      Q.push(p);
    }
  }
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int n;
    cin >> n;
    Int a[n];
    map<Int, Int> mp;
    Int su = 0;
    rep(i,n) {
        cin >> a[i];
        mp[a[i]]++;
        su += a[i];
    }
    int q;
    cin >> q;
    Int ans[q];
    rep(i,q) {
        int b, c;
        cin >> b >> c;
        su -= mp[b] * b;
        su += mp[b] * c; 
        mp[c] += mp[b];
        mp[b] = 0;
        ans[i] = su;
    }
    rep(i,q) cout << ans[i] << endl;
}

Measured memory_bytes: 11000
#traveling plan
n=int(input())
lists=list(map(int,input().split()))
a=[0 for i in range(n+2)]
for i in range(n):
    a[i+1]=lists[i]

sums=0
for i in range(1,n+2):
    sums+=abs(a[i]-a[i-1])

for i in range(n):
    c=0
    c+=sums
    c+=abs(a[i+2]-a[i])
    c-=abs(a[i+1]-a[i])
    c-=abs(a[i+2]-a[i+1])
    print(c)

Measured memory_bytes: 13920
#include<bits/stdc++.h>
#define rint register int
using namespace std;
inline int read(){
	int s=0,f=1; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=0;c=getchar();}
	while(c>='0'&&c<='9') s=(s<<1)+(s<<3)+(c^48),c=getchar();
	return f?s:-s;
}
const int Mod=1e9+7;
int n,X,Y,Z,ed,ans=1;
int f[50][1<<18];
int main(){
	n=read(); X=read(); Y=read(); Z=read();
	ed=(1<<X+Y+Z-1)|(1<<Y+Z-1)|(1<<Z-1);
	f[0][0]=1;
	for(rint i=1;i<=n;++i,ans=1ll*ans*10%Mod)
		for(rint S=0;S<(1<<X+Y+Z);++S){
			if(!f[i-1][S]) continue;
			for(rint j=1;j<=10;++j){
				int now=(S<<j)|(1<<j-1);
				now=now&((1<<X+Y+Z)-1);
				if((now&ed)!=ed) f[i][now]=1ll*(f[i][now]+f[i-1][S])%Mod;
			}
		}
	for(rint S=0;S<(1<<X+Y+Z);++S)
		if((S&ed)!=ed) ans=1ll*(ans-f[n][S]+Mod)%Mod;
	printf("%d",ans); 
	return 0;
}

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

int main() {
  string n;

  cin >> n;

  int sum = 0;
  for (int i = 0; i < n.length(); i++) {
    sum += n[i] - '0';
  }

  int n_int = atoi(n.c_str());
  if (n_int % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main(void){
    int A,B; cin >> A >> B;
    int ans=0;
    for(int i=A; i<=B; i++){
        string s=to_string(i);
        bool palindrome=true;
        for(int j=0; j<s.size()-1; j++){
            if(s[j]!=s[s.size()-1-j]) palindrome=false;
        }
        if(palindrome) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *    author:  zjsdut
 *    created: 2020/03/10 11:40:20
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define rep(n)                                                                 \
  for (int _iter_##n = 0, _num_##n = (int)n; _iter_##n < _num_##n; ++_iter_##n)
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  int A, B, M;
  scan(A, B, M);
  vi a(A), b(B);
  scan(a, b);
  int mi = *min_element(all(a)) + *min_element(all(b));
  rng (i, 0, M) {
    int x, y, c;
    scan(x, y, c);
    --x, --y;
    chkmin(mi, a[x] + b[y] - c);
  }
  println(mi);
  return 0;
}

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

#define xin() main()
#define ru(a) if(a)
#define ruguo(a) else if(a)
#define baai(a) while(a)
#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define gsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define gkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define ta else
#define datu break
#define zi continue;
#define hen return
#define zen(h) (h).begin(),(h).end()
#define seiri(h) sort(zen(h))
#define yu(h) h.erase(unique(zen(h)), h.end())
#define gyaku(a) reverse(zen(a))
#define katu &&
#define mata ||
#define nyu(a) cin >> a
#define syutu(a) cout << a << endl
#define tuika(a,b) a.push(b)
#define huka(a,b) a.push_back(b)
#define tou(a) a.top()
#define kuu(a) a.empty()
#define xya(a) a.pop()
#define cyou(a) a.size()
#define tyou(a) a.length()
#define sen first
#define go second
#define sosei(a,b) make_pair(a,b)
#define kouzoutai struct
#define kigou operator
#define sin true
#define gi false
#define tei const
#define mugen 10000000111
#define yo 10000000711
#define kyou 1e-9

using namespace std;

typedef int seisu;
typedef void mu;
typedef long long sei;
typedef long double xyo;
typedef string moji;
typedef pair<sei, sei> so;
typedef pair<xyo, xyo> sox;
typedef vector<sox> hsox;
typedef vector<sei> hs;
typedef vector<hs> hhs;
typedef vector<xyo> hx;
typedef vector<hx> hhx;
typedef vector<moji> hm;
typedef vector<so> hso;
typedef vector<hso> hhso;
typedef bool singi;
typedef vector<singi>  hsi;
typedef vector<hsi> hhsi;
typedef priority_queue<sei> nibungi;
typedef map<int, int> zisyos;

const seisu h1[8] = {1,1,0,-1,-1,-1,0,1};
const seisu h2[8] = {0,1,1,1,0,-1,-1,-1};

sei dai(sei a, sei b){return max(a,b);}
sei syou(sei a, sei b){return min(a,b);}

sei n;
hm w(110);
singi s = gi;

mu kai(){
    sai(j,n){
        kan(k,j+1,n){
            ru(w[j] == w[k]){
                s = sin;
            }
        }
    }

    sai(j,n-1){
        sei c = cyou(w[j]);
        ru(w[j][c-1] != w[j+1][0]){
            s = sin;
        }
    }

    ru(s){
        syutu("No");
    }
    ta{
        syutu("Yes");
    }
}
seisu xin(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    nyu(n);
    sai(j,n){
        nyu(w[j]);
    }
    kai();
    hen 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<long long> a(N+1);
    REP(i, N) cin >> a[i+1];

    vector<long long> s(a);
    REP(i, N) s[i+1] += s[i];

    // dp[i][j]: 1-index で [i,j] のスライムを一つにするのに必要な最小のコスト
    vector<vector<long long>> dp(N+1, vector<long long>(N+1, 1e+18));

    FOR(i, 1, N+1) dp[i][i] = 0;
    FOR(len, 2, N+1){
        FOR(l, 1, N+1){
            int r = l+len-1;
            if(r > N) break;
            FOR(k, l, r){ 
                dp[l][r] = min(dp[l][r], dp[l][k]+dp[k+1][r]+s[r]-s[l-1]);
            }
        }
    }
    cout << dp[1][N] << endl;

    return 0;
}

Measured memory_bytes: 1536