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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  for(int i=0;i<n-1;i++){
    cin >> b[i];
  }
  vector<int> a(n,0);
  a[n-1]=b[n-2];
  a[0]=b[0];
  for(int i=n-2;1<=i;i--){
    if(b[i]<=b[i-1]){
      a[i]=b[i];
    }
    else{
      a[i]=b[i-1];
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans += a[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <vector>

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

vector<string> split(const string &s, char d) {
    vector<string> ret;
    string s2;
    for (auto e : s) {
        if (d == e) {
            ret.push_back(s2);
            s2 = "";
        } else {
            s2 += e;
        }
    }
    if (s2.size()) ret.push_back(s2);
    return ret;
}

int N;
vector<string> words;
char query;

void solve() {
    map<string, int> cnt;
    for (auto word : words) {
        cnt[word]++;
    }
    vector<pair<int, string>> vec;
    for (auto e : cnt) {
        if (e.first[0] == query) {
            vec.push_back(make_pair(-e.second, e.first));
        }
    }
    sort(vec.begin(), vec.end());
    int M = min(5, (int)vec.size());
    if (vec.size()) {
        rep(i, M) {
            cout << vec[i].second;
            if (i + 1 != M) cout << " ";
        }
    } else {
        cout << "NA";
    }
    cout << endl;
}
int main() {
    while (cin >> N, N) {
        words.clear();
        cin.ignore();
        rep(i, N) {
            string s;
            getline(cin, s);
            auto vec = split(s, ' ');
            for (auto e : vec) words.push_back(e);
        }
        cin >> query;
        solve();
    }
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N + 2];
		A[0] = 0; A[N + 1] = 0;
		for(int i = 1; i <= N; i++) A[i] = sc.nextInt();
		int[] left = new int[N + 2];
		int[] right = new int[N + 2];

		// left
		for(int i = 1; i < N + 2; i++) left[i] = left[i - 1] + Math.abs(A[i] - A[i - 1]);
		// right
		for(int i = N; i >= 0; i--) right[i] = right[i + 1] + Math.abs(A[i] - A[i + 1]);

		for(int i = 1; i <= N; i++) {
			// remove A_i
			System.out.println(left[i - 1] + right[i + 1] + Math.abs(A[i - 1] - A[i + 1]));
		}
	}
}

Measured memory_bytes: 64008
#include<stdio.h>
int main(void){
    int w,w_c;
    while(scanf("%d",&w)!=EOF){
        int i=512,g[10]={0},j=0;
        while(i>=1){
            w_c=w;
            w%=i;
            if(w_c!=w){
                g[j]=i;
                j++;
            }
            i/=2;
        }
        for(i=j-1;i>0;i--){
            printf("%d ",g[i]);
        }
        printf("%d\n",g[0]);

    }
    return 0;
}

Measured memory_bytes: 592
N = int(input())
bricks = [int(x) for x in input().split()]

next_number = 1
num_broken = 0

for brick in bricks:
  if brick == next_number:
    next_number += 1
  else:
    num_broken += 1
    
if next_number == 1:
  print(-1)
else:
  print(num_broken)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
vector<int> fa;
int Find(int x) {
	return x == fa[x] ? x : fa[x] = Find(fa[x]);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<int> > f;
	vector<vector<int> > g;
	fa.resize(n);
	f.resize(n);
	g.resize(n);
	for(int i = 0; i < n; ++i) {
		fa[i] = i;
	}
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
		if(Find(a) != Find(b)) {
			fa[Find(a)] = Find(b);
		}
	}
	for(int i = 0; i < k; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		f[a].emplace_back(b);
		f[b].emplace_back(a);
	}
	vector<int> sz;
	sz.resize(n);
	for(int i = 0; i < n; ++i) {
		++sz[Find(i)];
	}
	for(int i = 0; i < n; ++i) {
		int ans = sz[Find(i)] - 1;
		for(auto x : f[i]) {
			if(Find(x) == Find(i)) {
				--ans;
			}
		}
		ans -= g[i].size();
		cout << ans << ' ';
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 13304
n = input()
total = 0
first = 0
for i in range(len(n)):
	first += int(n[i])
if len(n) == 1:
	print(n)
else:
	for i in range(len(n)):
		if i == 0:
			total += int(n[i]) -1
		else:
			total += 9
	if first < total:
		print(total)
	else:
		print(first)

Measured memory_bytes: 3060
s=input()
t=input()
min_len=min(len(s),len(t))
slist=sorted(s)
tlist=sorted(t)
tlist.reverse()
for i in range(min_len):
    x=ord(slist[i])
    y=ord(tlist[i])
    if(x<y):
        print("Yes")
        exit()
if(slist[:len(s)]==tlist[:len(s)] and len(s)!=len(t)):
    print("Yes")
    exit()
print("No")



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

signed main(){
  int N;
  cin>>N;
  int ans=0;
  rep(i,N){
    int A,B;
    cin>>A>>B;
    ans+=B-A+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3608
#                         author:  kagemeka 
#                         created: 2019-11-06 22:04:18(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n = int(sys.stdin.readline().rstrip())
    red = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]
    blue = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]
    reversed_b_sorted_by_a= [ab[1] for ab in sorted(red, reverse=1)]
    bd_sorted_by_ac = [acbd[1] for acbd in sorted(red + blue)]


    count = 0
    for b in reversed_b_sorted_by_a:
        b_index = bd_sorted_by_ac.index(b)
        if b_index == len(bd_sorted_by_ac) - 1:
            bd_sorted_by_ac.remove(b)
            continue
        
        range_to_scope = bd_sorted_by_ac[b_index+1:]
        possible_elements = [x for x in range_to_scope if x > b]
        if not possible_elements:
            bd_sorted_by_ac.remove(b)
            continue

        bd_sorted_by_ac.remove(min(possible_elements))
        bd_sorted_by_ac.remove(b)
        count += 1
    print(count)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int N = 0;
	cin >> N;
	vector<int> numbers(N,0);
	for (int i = 0; i < N; ++i) {
		cin >> numbers[i];
	}
	int min = *min_element(numbers.begin(), numbers.end());
	int max = *max_element(numbers.begin(), numbers.end());

	int ans = 0;
	for (int n = min; n <= max; ++n) {
		int tmp = 0;
		for (auto itr = numbers.begin(); itr < numbers.end(); ++itr) {
			tmp += pow(*itr-n, 2);
		}
		if (n == min)
			ans = tmp;
		else {
			if (ans > tmp)
				ans = tmp;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
long long int a[2000005];
int main()
{
    long long int n,t,i,s,e,sum;
	while(scanf("%lld%lld",&n,&t)!=EOF)
	{
		for(i=1;i<=n;i++)
		scanf("%lld",&a[i]);
		s=a[1];
		e=a[1]+t;
		sum=0;
		for(i=2;i<=n;i++)
		{
			if(a[i]<=e)
			{
				sum+=a[i]-s;
				s=a[i];
				e=a[i]+t;
			}
			else
			{
				sum+=t;
				s=a[i];
				e=a[i]+t;
			}
		}
		sum+=t;
		printf("%lld\n",sum);
	}
    return 0;
}

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

#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF	INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

/*
struct point{
	ll x;
	ll y;
	point(){x = 0;y = 0;}
	point(ll x, ll y):x(x), y(y){}
};
*/


int main() {

	int k, s;
	cin >> k >> s;
	int ans = 0;
	rep(i, k + 1)rep(j, k + 1){
		int tmp = s - i - j;
		if(0<= tmp && tmp <= k) ans++;
	}

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


Measured memory_bytes: 256
#include <iostream>

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

        int atai = n%10;

        if(atai == 3)
                std::cout << "bon" << std::endl;
        else if(atai==0 || atai==1 || atai==6 || atai==8)
                std::cout << "pon" << std::endl;
        else
                std::cout << "hon" << std::endl;

}

Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void selectSort(int[] data, int n) {
        int count = 0, minInx, tmp;

        for (int i = 0; i < n; i++) {
            minInx = i;
            for (int j = i; j < n; j++) {
                if (data[j] < data[minInx]) {
                    minInx = j;
                }
            }
            if (minInx != i) {
                tmp = data[i];
                data[i] = data[minInx];
                data[minInx] = tmp;
                count++;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i > 0)
                System.out.print(" ");
            System.out.printf("%d", data[i]);
        }
        System.out.print("\n");
        System.out.println(count);
    }

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n = Integer.parseInt(br.readLine());
            int nums[] = new int[n];
            String[] input_string = br.readLine().split(" ");

            for (int i = 0; i < n; i++)
                nums[i] = Integer.parseInt(input_string[i]);

            selectSort(nums, n);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

template <class T> void readVal(vector<T>& vec, int idx) {
    T input;
    std::cin >> input;
    vec[idx] = input;
}

int main()
{
    char ans = '1';
    int size;
    cin >> size;
    vector<int> x(size); 
    vector<int> y(size);
    int dir(0), vecx(0), vecy(0);
    for (int i = 0; i < size; i++) {
        readVal(x, i);
        readVal(y, i);
    }
    for (int i = 0; i <= size; i++) {
        int new_vecx = x[(i + 1) % size] - x[i % size];
        int new_vecy = y[(i + 1) % size] - y[i % size];
        int cross_prod = (vecx * new_vecy - vecy * new_vecx);
        if (cross_prod != 0) {
            if (cross_prod * dir >= 0) {
                dir = cross_prod > 0 ? 1 : -1;
            }
            else {
                ans = '0';
                break;
            }
        }
        vecx = new_vecx;
        vecy = new_vecy;
    }

    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

/*template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
*/

int main(){
	ll n,k;cin>>n>>k;
	ll a[n];
	
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	ll c=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]){
				c++;
			}
		}
	}
	
	ll ans=c*k;
	sort(a,a+n);
	
	c=0;
	
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]<a[j]){
				c++;
			}
		}
	}
	
	ans%=MOD;
	
	ans+=(((k*(k-1))/2)%MOD)*(c%MOD);
	ans%=MOD;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,a,b;
    cin>>n;
    a=n/2;
    b=ceil(n/2.0);
    cout<<(a*b)<<endl;

    
    
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000007

int main(){

    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    if(a*b == c*d){
        cout << a*b << endl;
    }else if(a*b > c*d){
        cout << a*b << endl;
    }else{
        cout << c*d << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define pi 3.141592653589793
using namespace std;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	h*=30;
	h+=m/2;
	m*=6;
	double ans;
	double kbir=((h>m)?h:m);
	double sghir=((h>m)?m:h);
	double zaw=(((kbir-sghir)>180)?360-(kbir-sghir):(kbir-sghir));

	double e=static_cast<double>(((a>=b)?a:b));
	double f=static_cast<double>(((a>=b)?b:a));

	double tmp=cos(zaw*pi/180)*f;
	tmp=e-tmp;
	double tmpo=sin(zaw*pi/180)*f;
	ans=sqrt(tmp*tmp+tmpo*tmpo);
	cout<<setprecision(15)<<ans<<endl;

}


Measured memory_bytes: 4044
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := map[int]string{
		0: "pon",
		1: "pon",
		2: "hon",
		3: "bon",
		4: "hon",
		5: "hon",
		6: "pon",
		7: "hon",
		8: "pon",
		9: "hon",
	}

	fmt.Println(a[n%10])
}


Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
#define N 200100
#define ll long long

int n;
int a[N];
ll dp[N][10],ans;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	memset(dp[0],0x3f,sizeof(dp[0]));
	dp[0][1]=0;
	for (int i=1;i<=n;i++) {
		ll now=dp[i-1][1];
		for (int j=1;j<=5;j++) {
			now=min(now,dp[i-1][j]);
			if (j==1 || j==5) dp[i][j]=now+a[i];
			if (j==2 || j==4) dp[i][j]=now+(a[i]==0 ? 2 : a[i]&1);
			if (j==3) dp[i][j]=now+(a[i]&1^1);
		}
	}
	ans=dp[0][0];
	for (int i=1;i<=5;i++) ans=min(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}

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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T> inline bool chkmax(T &x, const T &y){ return y > x ? x = y, 1 : 0; }
template <typename T> inline bool chkmin(T &x, const T &y){ return y < x ? x = y, 1 : 0; }

#ifdef ONLINE_JUDGE
#define debug(...) ;
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 2e5 + 100;

int n;
int sg[maxn];
vi g[maxn];

void dfs(int u, int p)
{
	sg[u] = 0;
	for(int v: g[u]) if(v != p) dfs(v, u), sg[u] ^= (sg[v] + 1);
	return;
}

int main()
{
	scf(n);
	rep(i, n - 1)
	{
		int u, v; scf(u, v);
		g[u].pb(v); g[v].pb(u);
	}
	dfs(1, 0);
	puts(sg[1] ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 14720
import sys
sys.setrecursionlimit(4100000)
import math
import fractions
import bisect

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行ありl
x = []
y = []
for i in range(5):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

'''


S = input()
T = input()

s_hash = [0]*28
t_hash = [0]*28

s_next = 0
t_next = 0


for i in range(len(S)):

    if s_hash[ord(S[i])-ord("a")] !=  t_hash[ord(T[i])-ord("a")]:
        print("No")
        sys.exit()

    else:
        
        if s_hash[ord(S[i])-ord("a")] == 0:
            s_next+=1
        s_hash[ord(S[i])-ord("a")] += 1

        if t_hash[ord(T[i])-ord("a")] == 0:
            t_next+=1
        t_hash[ord(T[i])-ord("a")] += 1



print("Yes")


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------
int N;
int A[1000002];

signed main(){
	cin >> N;
	int max = 0;
	REP(i, 1 , N+1) {
		scanf("%d", &A[i]);
		max += abs(A[i-1] - A[i]);
//		cout << i << " max = " << max << endl;
	}
	max += abs(A[N]);
//	cout << "last max = " << max << endl;
	
	int c;
	REP(i, 1, N+1) {
		// 通り過ぎるので費用は変わらない
		if((A[i-1] <= A[i] && A[i] <= A[i+1])
				|| (A[i-1] >= A[i] && A[i] >= A[i+1])) {
//			cout << "through " << endl;
			cout << max << endl;
		// 折り返すが、前は超えない（→から←への折り返しと　←から→への折り返し）
		} else if((A[i-1] <= A[i] && A[i-1] <= A[i+1]) 
				|| (A[i-1] >= A[i] && A[i-1] >= A[i+1])) {
//			cout << "uturn 1  " << abs((A[i+1]-A[i]) * 2) << endl;
			cout << (max - abs((A[i+1]-A[i]) * 2)) << endl;
		// 折り返し、前を超える（→から←への折り返しと　←から→への折り返し）
		} else if((A[i-1] <= A[i] && A[i-1] > A[i+1]) 
				|| (A[i-1] >= A[i] && A[i-1] < A[i+1])) {
//			cout << "uturn 2  " << abs((A[i-1]-A[i]) * 2) << endl;
			cout << (max - abs((A[i-1]-A[i]) * 2)) << endl;
		}
	}
	
	return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a;
    cin >> a;
    N -= a;
  }
  if(N < 0){
    cout << "-1" << endl;
  }
  else if(N>=0){
    cout << N << endl;
  }
}




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

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

    int n,x,t;
    cin>>n>>x>>t;
    int igrachki=x;
    int vreme=t;
    while(x<n){
        x+=igrachki;
        t+=vreme;
    }
    cout<<t;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll n;
cin>>n;
ll i;
ll a,b,c,d;a=b=c=d=0;
for(i=0;i<n;i++)
{
	string s;
	cin>>s;
	if(s=="AC")
	a++;
	if(s=="WA")
	b++;
	if(s=="TLE")
	c++;
	if(s=="RE")
	d++;
}
cout<<"AC x "<<a<<endl;
cout<<"WA x "<<b<<endl;
cout<<"TLE x "<<c<<endl;
cout<<"RE x "<<d<<endl;
	return 0;
}

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

typedef long long ll;

using namespace std;

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

template<class T>
using vi = vector<T>;
template<class T>
using vvi = vector<vector<T>>;

int main(){
    ll N,M;
    cin >> N >> M;
    if(N >= M/2) cout << M/2 << endl;
    else {
        cout <<  N+(M/2-N)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define ll long long
#define nl '\n'
using namespace std;

int main() {
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
    #endif
    int a;
    cin >> a;
    cout << a+a*a+a*a*a << nl;
    return 0;
}


Measured memory_bytes: 3168
#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 ans = 0 ;
  for(int i=1;i<n-1;i++){
    if((p[i]>p[i-1]) && (p[i+1]>p[i])){
      ans++;
    }else if((p[i]<p[i-1]) && (p[i+1]<p[i])){
      ans++;
    }
  }
  cout << ans ;
}

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


long long solve(int n, vector<int>&A){
    
    // DP solution 
    // dp[i] == max value possible on the ith day
    vector<long long>dp(n);
    dp[0] = 1000;
    for(int i = 1; i < n; i++){
        dp[i] = dp[i-1];
        for(int j = 0; j < n; j++){
            long long stocks = dp[j]/A[j];
            long long current_value = dp[j] + (A[i] - A[j])*stocks;
            dp[i] = max(dp[i], current_value);
        }
    }  
    
    return dp[n-1];
    
}






int main(){
    
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i= 0; i < n; i++){
        cin >> a[i];
    }
    
    cout << solve(n, a) << endl;
    
    
    return 0;
    
}


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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  ll n, k;
  cin>>n>>k;
  combination c = combination(max(n-k+1,k-1));
  rep(i,k) std::cout << c(n-k+1,i+1)*c(k-1,i) << std::endl;
  return 0;
}


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

int main() {
    int n, x;
    cin >> n >> x;
    auto l = vector<int>(n);
    for (auto &l_i : l)
        cin >> l_i;

    auto cnt = 1;
    auto pos = 0;
    for (int i = 0; i < n; i++) {
        pos += l[i];
        if (pos <= x)
            cnt++;
    }

    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	int k;
	cin >> k;
	if (k == n) {
		cout << "0" << endl;
	    return 0;
	}
	vector<int> a;
	a.pb(0);
	for (int i = 0; i < n; ++i) {
	    int x;
		cin >> x;
		a.pb(x);
	}
	++n;
	int64 inf = 1000000000;
	inf *= inf;
	vector<vector<int64>> dp(n, vector<int64> (k + 1, inf));
    dp[0][0] = 0;
    int64 ans = inf;
	for (int i = 1; i < n; ++i) {
	    for (int j = 0; j <= k; ++j) {
			for (int prev = 0; prev < i; ++prev) {
				if (j - (i - prev - 1) < 0) continue;
			    dp[i][j] = min(dp[i][j], dp[prev][j - (i - prev - 1)] + max(a[i] - a[prev], 0));
			}
			if (i + (k - j) >= n - 1) {
			    ans = min(ans, dp[i][j]);
			}
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}		
	cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int64_t m=*max_element(A.begin(),A.end());
  if(K>m){cout<<"IMPOSSIBLE"<<endl;}
  else{
    int g=A[0];
    for(int i=0;i<N;i++){
      g=__gcd(A[i],g);
    }//cout<<g<<endl;
    if(K%g==0){cout<<"POSSIBLE"<<endl;}
    else{cout<<"IMPOSSIBLE"<<endl;}
  }
  return 0;
}

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

const int N = 1e5 + 5;

int n;
long long a[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	long long sum = 0;
	for (int i = 1; i <= n; ++i) sum += a[i];
	long long tot = 1LL * n * (n + 1) / 2LL;
	if (sum % tot) return cout << "NO\n",0;
	tot = sum / tot;
	for (int i = 1; i <= n; ++i) {
		long long d = a[i] - (i == 1 ? a[n] : a[i - 1]);
		d -= tot;
		if (d > 0) return cout << "NO\n",0;
		d = -d;
		if (d % n) return cout << "NO\n",0;
	}
	cout << "YES\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if(n == 0) {
        out(0);
        re0;
    }

    ll x = 2;
    string ans = "";
    for(ll i = 0; ; i++) {
        if(n == 0) {
            break;
        }
        if(n%x == 0) {
            ans = "0" + ans;
        }
        else {
            ans = "1" + ans;
            if(i%2 == 0) {
                n -= x/2;
            }
            else {
                n += x/2;
            }
        }
        x *= 2;
    }

    out(ans);
    re0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<double, double> P;
static const double EPS = 1e-5;

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

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    double x,y;
    vector<P> point;
    REP(i,n){
      scanf("%lf,%lf",&x,&y);
      point.push_back(P(y,x));
    }
    sort(point.begin(),point.end());
    reverse(point.begin(),point.end());
    REP(i,point.size()){
      swap(point[i].first,point[i].second);
    }
    P f,n;
    double arg;
    f = point[0];
    REP(i,point.size()){
      if(point[i].second==f.second&&point[i].first<f.first) f = point[i];
    }
    vector<pair<double,P> > tmp;
    REP(i,point.size())if(point[i]!=f){
      arg = atan2(point[i].second-f.second,point[i].first-f.first);
      tmp.push_back(pair<double,P>(arg,point[i]));
    }
    sort(tmp.begin(),tmp.end());
    n = tmp[0].second;
    int ans = 2;
    arg = tmp[0].first;
//printf("%lf %lf\n",f.first,f.second);
//printf("%lf %lf\n",(n).first,(n).second);
    while(n!=f){
      double arg2;
      vector<pair<double,P> > argvec;
      REP(i,point.size()){
        if(n==point[i]) continue;
        int nx = point[i].first; int ny = point[i].second;
        arg2 = atan2(ny-n.second, nx-n.first);
        argvec.push_back(pair<double,P>(arg2,point[i]));
      }
      vector<pair<double,P> >::iterator it;
      sort(argvec.begin(),argvec.end());
      it = upper_bound(argvec.begin(),argvec.end(),pair<double,P>(arg,n));
//printf("%lf %lf\n",(*it).second.first,(*it).second.second);
      if(it==argvec.end()) it = argvec.begin();
      if(f==(*it).second){
        cout<<point.size()-ans<<endl;
        break;
      }else{
        arg = (*it).first;
        n = (*it).second;
        ans++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

typedef P<int, int> pii;
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
int x, k, q;
V<P<pii, pii>> v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x >> k;
  v.eb(mp(0, 0), mp(0, x));
  {
    int l=0, r=x, c=0;
    FOR(i, 0, k){
      int t;
      cin >> t;
      int d = t-v.back().fi.fi;
      if(i%2){
        c += d;
        mins(c, x);
        mins(r, x-c);
        mins(l, r);
      }else{
        c -= d;
        maxs(c, -x);
        maxs(l, -c);
        maxs(r, l);
      }
      v.eb(mp(t, c), mp(l, r));
    }
  }
  cin >> q;
  FOR(_, 0, q){
    int t, a;
    cin >> t >> a;
    auto itr = upper_bound(all(v), mp(mp(t, IINF), mp(IINF, IINF)));
    itr--;
    maxs(a, itr->se.fi);
    mins(a, itr->se.se);
    a += itr->fi.se;
    if((itr-v.begin())%2) a += t-itr->fi.fi;
    else a -= t-itr->fi.fi;
    maxs(a, 0);
    mins(a, x);
    cout << a << endl;
  }
}

Measured memory_bytes: 2928
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

struct SegmentTree {
  const int INF = numeric_limits<int>::max();
  int n;
  vector<int> node;

  SegmentTree(vector<int> v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, INF);
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; 0 <= i; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }

  // x番目の要素をvalに更新する
  void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // 区間[a, b)の要素の最小値を返す. k := 自分がいるノードのインデックス
  int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return INF;

    if (a <= l && r <= b) return node[k];
    int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};

int main() {
  int n, q, com, x, y;
  cin >> n >> q;
  SegmentTree seg(vector<int>(n, numeric_limits<int>::max()));
  for (int i = 0; i < q; i++) {
    cin >> com >> x >> y;
    if (com)
      cout << seg.getmin(x, y + 1) << endl;
    else
      seg.update(x, y);
  }

  return 0;
}



Measured memory_bytes: 4144
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int INF = 1e18 + 239;
const int MOD = 1e9 + 7;

int add(int a, int b) {
	int res = (a + b) % MOD;
	return (res + MOD) % MOD;
}

struct Fenwick {
	int n;
	vector<int> f;

	void af(int pos, int val) {
		for (int i = pos; i < n; i = (i | (i + 1))) {
			f[i] = add(f[i], val);
		}
	}

	int sum(int pos) {
		int ans = 0;
		for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
			ans = add(ans, f[i]);
		}
		return ans;
	}

	Fenwick(int n_) {
		n = n_;
		f.resize(n);
	}
};

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, A, B;
	cin >> n >> A >> B;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	Fenwick f(n);
	Fenwick s(n);
	vector<map<int, int>> sub_f(n);
	vector<map<int, int>> sub_s(n);
	vector<int> nx_A(n);
	vector<int> nx_B(n);
	vector<int> min_gap(n);
	{
		nx_A[n - 1] = n;
		nx_B[n - 1] = n;
		for (int i = n - 2; i >= 0; i--) {
			if (a[i + 1] - a[i] < A) {
				nx_A[i] = i + 1;
			} else {
				nx_A[i] = nx_A[i + 1];
			}
			if (a[i + 1] - a[i] < B) {
				nx_B[i] = i + 1;
			} else {
				nx_B[i] = nx_B[i + 1];
			}	
		}
		min_gap[0] = INF;
		for (int i = 1; i < n; i++) {
			min_gap[i] = min(a[i] - a[i - 1], min_gap[i - 1]);
		}
	}
	auto slv = [&](int x) {
		return (int)(upper_bound(a.begin(), a.end(), x) - a.begin());
	};

	f.af(0, 1);
	if (nx_A[0] < n) sub_f[nx_A[0]][0] = add(sub_f[nx_A[0]][0], 1);
	s.af(0, 1);
	if (nx_B[0] < n) sub_s[nx_B[0]][0] = add(sub_s[nx_B[0]][0], 1);
	
	for (int i = 0; i < n; i++) {
		for (auto [j, val] : sub_f[i]) {
			f.af(j, -val);
		}
		for (auto [j, val] : sub_s[i]) {
			s.af(j, -val);
		}
		//
		int As = 0;
		if (i + 1 < n) {
			int can_f = slv(a[i + 1] - B);
			int c = f.sum(can_f);
			if (nx_B[i + 1] < n) {
				sub_s[nx_B[i + 1]][i + 1] = add(sub_s[nx_B[i + 1]][i + 1], c);
			}
			As = c;
		}
		int Af = 0;
		if (i + 1 < n) {
			int can_s = slv(a[i + 1] - A);
			int c = s.sum(can_s);
			if (nx_A[i + 1] < n) {
				sub_f[nx_A[i + 1]][i + 1] += add(sub_f[nx_A[i + 1]][i + 1], c);
			}
			Af = c;
		}

		if (i + 1 < n) {
			f.af(i + 1, Af);
			s.af(i + 1, As);
		}
	}
	int ans = 0;
	ans = add(ans, f.sum(n - 1));
	ans = add(ans, s.sum(n - 1));
	cout << ans << '\n';
}

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

//typedef
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef tuple<LL, LL, LL> TLL3;
typedef tuple<LL, LL, LL, LL> TLL4;
typedef set<LL, greater<LL> > setdownLL;
#define PQ priority_queue
typedef PQ<LL, vector<LL>, greater<LL> > pqupLL;
//container utill
#define ALL(v) (v).begin(),(v).end()
#define CR [](auto element1, auto element2){return element1>element2;}
#define LB lower_bound
#define UP upper_bound
#define PB push_back
#define MP make_pair
#define MT make_tuple
//constant
#define PI 3.141592653589793

LL dp[51][5001];

int main(){
    //input
    LL N,A;
    cin >> N >> A;
    LL x[N+1];
    LL i,j;
    for(i=1; i<=N; i++){
        cin >> x[i];
        x[i]-=A;
    }

    //calc
    for(i=0; i<N; i++){
        for(j=0; j<=5000; j++){
            dp[0][j]=0;
        }
    }
    dp[0][2500]=1;
    for(i=1; i<=N; i++){
        for(j=-2450; j<=2450; j++){
            dp[i][2500+j]+=dp[i-1][2500+j];
            dp[i][2500+j+x[i]]+=dp[i-1][2500+j];
        }
    }

    //output
    cout << dp[N][2500]-1LL << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 5592
// https://beta.atcoder.jp/contests/abc098/tasks/arc098_a
#include<iostream>
#include<vector>
#include<string>
#include <climits>
using namespace std;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;

	vector< int > A(N);
	
	for(int i = 0; i < N; i++)
	{
		if(S[i] == 'E'){
			A[i] = 1;
		}else{
			A[i] = 0;
		}
	}
	
	
	for(int i = 1; i < N; i++)
	{
		A[i] = A[i-1] + A[i];
	}
	
	int minv = INT_MAX;
	
	for(int i = 0; i < N; i++)
	{
		int sum = 0;
		if(i==0){
			sum = A[N-1] - A[i];
		}else if(i==N-1){
			sum = i - A[i-1];
		}else{
			sum += A[N-1] - A[i];
			sum += i - A[i-1];
		}
		minv = min(minv, sum);

	}
	cout << minv << endl;

	return 0;

}



Measured memory_bytes: 1796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  
  if(A+B>N+1 || A*B<N) co(-1);
  else{
    vector<ll> ANS;
    ll gra=N-A,last=0;
    
    RREP(i,A){
      vector<ll> L;
      L.PB(last+1ll);
      ll cnt=1;
      while(cnt<B && gra>0){
        cnt++;
        gra--;
        L.PB(last+cnt);
      }
      last=L.back();
      
      REVERSE(L);
      REP(l,(ll)L.size()) ANS.PB(L[l]);
    }
    REP(i,N) cout<<ANS[i]<<" ";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 8080
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		while(N>0) {
			if(N%10 == 9) {
				System.out.println("Yes");
				System.exit(0);
			}
			N/=10;
		}
		
		System.out.println("No");
	}

}


Measured memory_bytes: 23124
package main

import (
	"fmt"
)

func main() {
	var A, B, K int
	fmt.Scan(&A, &B, &K)

	for i := A; i <= min(A+K-1, B); i++ {
		fmt.Println(i)
	}
	for i := max(B-(K-1), A+K); i <= B; i++ {
		fmt.Println(i)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; 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()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;

  cout << (a<=c&&c<=b ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

ll N;
double dp[310][310][310];

double rec(ll i, ll j, ll k)
{
    if (dp[i][j][k] >= 0.0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i-1, j, k) * i;
    if (j > 0) res += rec(i+1, j-1, k) * j;
    if (k > 0) res += rec(i, j+1, k-1) * k;
    res += N;
    res *= 1.0 / (i + j + k);
    dp[i][j][k] = res;

    return dp[i][j][k];
}


int main()
{
    cin >> N;
    ll one = 0, two = 0, three = 0;
    ll a;
    REP(i,0,N) {
        cin >> a;
        if (a == 1) ++one;
        else if (a == 2) ++two;
        else ++three;
    }
    
    memset(dp, -1, sizeof(dp));

    double res = rec(one, two, three);
    cout << fixed << setprecision(10) << res << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 233088
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;

  if (n <= a * b && a + b <= n + 1)
  {
	vector<int> width(a);
	vector<int> cluster(a);
	cluster[0] = b;
	width[0] = b;
	for (int i = 1; i < a; i++)
	{
	  cluster[i] = b + (n - b) * i / (a - 1);
	  width[i] = (n - b) * i / (a - 1) - (n - b) * (i - 1) / (a - 1);
	}
	vector<int> vs(n);
	int index = 0;
	for (int i = 0; i < a; i++)
	{
	  for (int j = 0; j < width[i]; j++)
	  {
		vs[index++] = cluster[i] - j;
	  }
	}
	for (int i = 0; i < n; i++)
	{
	  if (i > 0) cout << " ";
	  cout << vs[i];
	}
	cout << endl;
  }
  else
  {
	cout << -1 << endl;
  }
}


Measured memory_bytes: 5120
#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;


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

    ll a, b, n;
    cin >> a >> b >> n;

    ll ans = max((a * n)/b - a * (n/b), (a * (n-1))/ b - a * ((n-1)/b));
    if(b - 1 <= n){
        ans = max(ans, (a * (b-1)) / b - a * ((b-1) / b));
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3612
n =int(input())
if n%2==0:
    print(-1)
elif n==1 or n==7:
    print(1)
else:
    ans =1
    start = 7
    while True:
        start = ((start%n*10%n)+7)%n
        #start = start%n
        #print(start)
        if start ==0:
            ans+=1
            print(ans)
            break
        if ans>=1000000:
            print(-1)
            break
        ans+=1

Measured memory_bytes: 9188
a, b, c, d = map(int, input().split())

def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

mc = b // c - (a-1) // c
md = b // d - (a-1) // d
mcd = b // (c*d//gcd(c, d)) - (a-1) // (c*d//gcd(c, d))

print(int((b - a + 1) - mc - md + mcd))

Measured memory_bytes: 3060