akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
long long int A[2000000];

int first(ll i){
  while(i>=10) i/=10;
  return i;
}
int last(ll i){
  return(i%10);
}
int main(){
  ll tot[10][10];
  memset(tot,0,sizeof tot);
    ll N,cnt=0;
    cin>>N;
  	int p=log10(N);
  	p=pow(10,p);
    for(int a=1;a<=9;a++){
      for(int b=1;b<=9;b++){
        for(ll i=1;i<=N;i++){
          
          if(first(i)==a && last(i)==b) {tot[a][b]++;}
        }
      }
    }
  ll cnt1=0, cnt2=0;
  for(int a=1;a<=9;a++){
    for(int b=1;b<=9;b++){
      if(a==b) {cnt1+=(tot[a][a]*tot[a][a]);}
      else if(tot[a][b] && tot[b][a]){cnt2+=tot[a][b]*tot[b][a];}
      
    }
  }
 
          
    cout<<cnt1+cnt2;    
      
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, i, j, minj, flag;
  int an[37], bn[37], xn;
  char am[37], bm[37], str[5], xm;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %s", str);
    am[i] = str[0];
    an[i] = str[1] - '0';
    bm[i] = am[i];
    bn[i] = an[i];
  }

  for (i = 0; i < n; i++) {
    for (j = n - 1; j > i; j--) {
      if (an[j] < an[j-1]) {
        xn = an[j];
        an[j] = an[j-1];
        an[j-1] = xn;
        xm = am[j];
        am[j] = am[j-1];
        am[j-1] = xm;
      }
    }
  }

  for (i = 0; i < n; i++) {
    minj = i;
    for (j = i; j < n; j++) {
      if (bn[j] < bn[minj]) {
        minj = j;
      }
    }
    if (i != minj){
      xn = bn[i];
      bn[i] = bn[minj];
      bn[minj] = xn;
      xm = bm[i];
      bm[i] = bm[minj];
      bm[minj] = xm;
    }
  }

  flag = 0;
  for (i = 0; i < n; i++) {
    if (am[i] != bm[i]) {
      flag = 1;
      break;
    }
  }

  for (i = 0; i < n; i++) {
    if (i <= n - 2) {
      printf("%c%d ", am[i], an[i]);
    }
    else if (i == n - 1) {
      printf("%c%d\n", am[i], an[i]);
    }
  }
  printf("Stable\n");
  for (i = 0; i < n; i++) {
    if (i <= n - 2) {
      printf("%c%d ", bm[i], bn[i]);
    }
    else if (i == n - 1) {
      printf("%c%d\n", bm[i], bn[i]);
    }
  }
  if (flag == 0) {
    printf("Stable\n");
  }
  else if (flag == 1) {
    printf("Not stable\n");
  }

  return 0;
}


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

#define ll long long

#define pii pair < int, int >
#define pll pair < ll, ll >

#define vi vector < int >
#define vs vector < string >

#define pb push_back

using namespace std;

const int N = 1e5 + 50;

int a[N], b[N];
bool vis[N];

int main()
{
    int x, n;

    cin >> x >> n;

    for(int i = 0; i < n; i++) cin >> a[i], vis[a[i]] = 1;

    int ans = -1;

    for(int i = x; i >= 0; i--){
        if(vis[i] == 0){
            ans = i;
            break;
        }
    }

    int ans1 = 106;

    for(int i = x; i <= 105; i++){
        if(vis[i] == 0){
            ans1 = i;
            break;
        }
    }

    //cout << ans << ' ' << ans1 << endl;

    if((ans1 - x) < (x - ans)) cout << ans1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
S = raw_input()
K = input()
M = ord('z')+1
ans = []
aa = ans.append
for s in S:
    o = ord(s)
    if s != 'a' and K>0 and M-o <= K:
        aa('a')
        K -= M-o
    else:
        aa(s)
if K > 0:
    K %= 26
    a = ord(ans[-1]) + K
    if a > ord('z'):
        a -= 26
    ans[-1] = chr(a)
print ''.join(ans)


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll money = 1000;
    ll kabu = 0;
    rep(i, N - 1) {
        int indexh = -1, indexl = -1;
        repd(j, i + 1, N) {
            if (A[i] < A[j]) {
                indexh = j;
                break;
            }
            else if (A[i] > A[j]) {
                indexl = j;
            }
        }
        if (indexl == -1 && indexh != -1) {
            ll cnt = money / A[i];
            money -= cnt * A[i];
            money += cnt * A[indexh];
            i = indexh - 1;
        }
    }

    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3632
N,M=map(int,input().split())
H=[int(i) for i in input().split()]
G=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
ans=0
for i in range(N):
    flag=1
    for j in G[i]:
        if H[i]<=H[j]:
            flag=0
            break
    if flag:
        ans+=1
print(ans)


Measured memory_bytes: 29484
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long[] map = new long[100002];
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        int ans = 0;
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= m; j++){
                if(m*i+n*j-i*j*2 == k){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
typedef vector<int> vii;
typedef pair<int,int> pii;
#define F first
#define S second
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve(){
	int n;
	cin>>n;
	int a;
	int o[100]={0};
	int ans =0;
	for(int i = 0; i<n;++i){
		cin>>a;
		for(int j=0;j<=63;++j){
			if(a&(1LL<<j)){
				++o[j];
			}
		}
	}

	for(int i=0;i<=63;++i){
		if(o[i]!=0 && o[i]!=n){
			int x = o[i]*(n-o[i]);
			for(int j=0;j<i;++j){
				x*=2;
				x%= 1000000007LL;
			}
			ans+=x;
			ans%=1000000007LL;
		}
	}	
	cout<<ans%(1000000007LL)<<endl;
}

signed main(){
	IOS
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

ll faf(ll x) {
  return x*x*x*x*x;
}
 

int main(void) {

  int n;
  ll a[200100];
  cin >> n;
  rep(i, n) cin >> a[i];

  ll c[200100];
  for (ll i = 0; i < n; i++) {
    c[i] = (i + 1LL) - a[i];
  }

  map<ll, ll> m;
  rep(i, n) {
    m[c[i]]++;
  }

  set<ll> s;
  map<ll, ll> ms;
  for (ll i = 0; i < n; i++) {
    s.insert((i + 1LL) + a[i]);
    ms[(i+1)+a[i]]++;
  }

  ll ans = 0;
  while (!s.empty()) {
    ll k = *s.begin();
    s.erase(k);
    if (m.end() != m.find(k)) {
      ans += ms[k]*m[k];
    }
  }

  cout << ans << endl;
}

  


Measured memory_bytes: 38580
#include <bits/stdc++.h>
using namespace std;
#define incant() cin.tie(0), ios::sync_with_stdio(false)
#define int long long
#define uint unsigned long long
#define double long double
using str = string;
template <class T> using vec = vector<T>;
template <class T> using vvec = vec<vec<T>>;
template <class T> using que = queue<T>;
template <class T> using pque = priority_queue<T>;
template <class... T> using tup = tuple<T...>;
using vint = vec<int>;
using vvint = vvec<int>;
using vstr = vec<str>;
using pint = pair<int, int>;
using vp = vec<pint>;
using tll = tup<int, int, int>;
using vt = vec<tll>;
using mint = map<int, int>;
using dict = map<str, int>;
using qint = que<int>;
using qp = que<pint>;
using pqint = pque<int>;
using pqp = pque<pint>;
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fir first
#define sec second
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define sz(x) x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define ms(v, x) memset(v, x, sizeof(v))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload3(__VA_ARGS__, revi, _rev,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) out(x), indent()
#define debug(x) cerr << __LINE__ << ": " << #x << ": " << (x) << '\n'
#define YN(x) print((x) ? "YES" : "NO")
#define Yn(x) print((x) ? "Yes" : "No")
#define yn(x) print((x) ? "yes" : "no")
#define POS(x) print((x) ? "POSSIBLE" : "IMPOSSIBLE")
#define Pos(x) print((x) ? "Possible" : "Impossible")
#define pos(x) print((x) ? "possible" : "impossible")
const int INF = LLONG_MAX - INT_MAX, MOD = 1e9 + 7, LIMIT = 100001;
const int dx4[] = {-1, 0, 1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const double EPS = 1e-9;
int gcd(int a, int b){return b == 0 ? a : gcd(b, a % b);}
int lcm(int a, int b){return a / gcd(a, b) * b;}
int factorial(int a){return a < 2 ? 1 : factorial(a - 1) * a;}
int summation(int a){return a < 1 ? 0 : (a * a + a) / 2;}
int combination(int n, int r){int res = 1; rep(i, 1, r + 1) res *= n--, res /= i; return res;}
const str alphabet = "abcdefghijklmnopqrstuvwxyz";
int a, b, c, k, n, m, x, y, z, w, h, res = 0, cnt = 0, sum = 0, mx = -INF, mn = INF;
str s, t;
bool flag = true;

signed main(){
    incant();
    cin >> n;
	int sum[n + 1] = {}, dp[n + 1][n + 1] = {}; // iからjまでのスライムを分けるのに必要なコスト
	rep(i, 1, n + 1){
		cin >> sum[i];
		sum[i] += sum[i - 1];
	}
	rev(i, n - 1){
		rep(j, i + 2, n + 1){
			dp[i][j] = INF;
			rep(k, i + 1, j){
				chmin(dp[i][j], dp[i][k] + dp[k][j] + sum[j] - sum[i]);
			}
		}
	}
    print(dp[0][n]);
}


Measured memory_bytes: 1664
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {a:usize,b:usize,x:usize}
    if a <= x && x <= a + b {
        println!("YES");
    } else {
        println!("NO")
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if(a * b % 2 == 1 || a * b * 2 % 2 == 1 || a * b * 3 % 2 == 1) {
		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(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n;cin>>n;
    vector<double> v(n);
    rep(i,n)cin>>v[i];
    vector<vector<double>> dp(n,vector<double>(n+1));
    dp[0][0]=1-v[0];
    dp[0][1]=v[0];
    REP(i,1,n){
        rep(j,n+1){
            if(j)dp[i][j]+=dp[i-1][j-1]*v[i];
            dp[i][j]+=dp[i-1][j]*(1-v[i]);
        }
    }
    double ans=0;
    REP(i,n/2+1,n+1)ans+=dp[n-1][i];
    decimal;
    out(ans);
}

Measured memory_bytes: 70656
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9*1e9;
const ll MAXN = 1e9;

vector<vector<ll> > dp;
vector<ll> a,sum;

ll f(int l,int r){
	if(dp[l][r]>=0)return dp[l][r];
	if(l==r) return 0LL;

	ll res = INF;
	for(int i = l; i < r; i++){
		res = min(res,f(l,i)+f(i+1,r));
	}
	dp[l][r] = res+(sum[r+1]-sum[l]);
	return dp[l][r];
}

int main()
{
	int n;
	cin>>n;
	a.resize(n,0);
	sum.resize(n+1,0);
	for(int i = 0; i < n; i++){
		cin>>a[i];
		sum[i+1] = sum[i]+a[i];
	}

	dp.resize(n,vector<ll>(n,-1));

	cout << f(0,n-1)<<endl;

	return 0;
}

Measured memory_bytes: 1536
N, A, B, C = gets.split.map(&:to_i)
L = N.times.map{ gets.to_i }
M = 1000000007

def dfs(n, a, b, c, aa, bb, cc)
    if n == N
        ret = M
        if aa > 0 && bb > 0 && cc > 0
            ret = [M, (a-A).abs + (b-B).abs + (c-C).abs+10*([aa-1,0].max)+10*([bb-1,0].max)+10*([cc-1,0].max)].min
        end
        #if min == 120
        #    puts "#{a} #{b} #{c} #{aa} #{bb} #{cc}"
        #end
        return ret
    end
    
    #puts $l[n]
    one = dfs(n+1, a + L[n], b, c, aa+1,bb,cc)
    two = dfs(n+1, a, b + L[n], c,aa,bb+1,cc)
    thr = dfs(n+1, a, b, c + L[n],aa,bb,cc+1)
    fou = dfs(n+1, a, b, c,aa,bb,cc)
    
    return [one,two,thr,fou].min
end

puts dfs(0, 0, 0, 0, 0, 0, 0)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

ll GCD(ll x,ll y) {return y ? GCD(y,x%y) : x;}
ll num(ll n,ll c, ll d){
    ll G=GCD(c,d);
    ll L=c/G*d;
    return n-n/c-n/d+n/L;
}

int main(void){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<num(b,c,d)-num(a-1,c,d)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {
  std::string a, b;
  std::cin >> a >> b;
  a += b;

  int n = std::stoi(a);

  for (int i = 1; i < 1000; ++i)
    if (n == i*i)
      return (std::cout << "Yes" << std::endl), 0;

  std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
char s[15];
int n;
int main(void){
    cin>>s;
    n=strlen(s);
    if(s[0]!='A')cout<<"WA\n";
    else{
        int a=0,c=0;
        for(int i=1;i<n;i++){
            if(s[i]<'a'){
                a++;
                c=i;
                if(s[i]!='C'){
                    cout<<"WA\n";
                    return 0;
                }
            }
        }
        if(a==1&&2<=c&&c<=n-2)cout<<"AC\n";
        else cout<<"WA\n";
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int A, B, K;
	cin >> A >> B >> K;
	FOR(i, A, min(B + 1, A + K)) cout << i << "\n";
	FOR(i, max(B - K + 1, A + K), B + 1) cout << i << "\n";

	return 0;
}

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

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    A[0] = A[N];

    ll ans = 1e9;
    for (int i = 1; i <= N; i++) {
        ll temp = 0;
        if (A[i] < A[i - 1]) {
            temp = A[i - 1] - A[i];
        } else {
            temp = A[i - 1] + K - A[i];
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: ABC/ARC
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int x;
  cin >> x;
  printf("A%cC\n", (x < 1200) ? 'B' : 'R');
  return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)

if n%2==1:
    print("No")
else:
    for i in range(0,n,2):
        if s[i]=="h" and s[i+1]=="i":
            if i==n-2:
                print("Yes")
            else:
                continue
        else:
            print("No")
            break

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll dp[2005];
ll modInverse(ll a, ll m=MOD){return powm(a,m-2,m);}int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,o,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>n;
// for(i=3;i<=2000;i++)
// {
//   dp[i]=1;
// }
for(i=3;i<2001;i++)
{
  dp[i]=1;
  for(j=3;j<i;j++)
  {
    dp[i]+=dp[i-j];
    dp[i]%=MOD;
  }
}
cout<<dp[n];
}


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

int main(int argc, char const *argv[])
{
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a>b)
        printf("a > b\n");
    
    else if(a<b)
        printf("a < b\n");
    
    else
        printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2092
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    double r; cin >> r;
    cout << r * 2 * M_PI << endl;
    return 0;
}

Measured memory_bytes: 3748
#include<stdio.h>
#define MAX_N 200000
int par[MAX_N];
int original_par[MAX_N];
int rank[MAX_N];
int query_list[MAX_N][2];

void init(int n){
  int i;
  for(i=0;i<n;i++){
    par[i] = i;
    rank[i] = 0;
  }
}
int find(int x){
  if(par[x]==x){
    return x;
  }else {
    return par[x] = find(par[x]);
  }
}
void unite(int x,int y){
  x =find(x);
  y =find(y);
  if(x==y){
    return ;
  }
  par[y] = x;
  /*
  if(rank[x] < rank[y]){
    par[x] = y;
  }else {
    par[y] = x;
    if(rank[x] == rank[y])rank[x]++;
  }
  */
}
int same(int x,int y){
  return find(x)==find(y);
}
int main(){
  int N,Q;
  long long int ans;
  int i,j,k;
  int marked_list[MAX_N];
//??¨??¨????????§?????????????????§1?????¬???
  while(1){
    scanf("%d %d",&N,&Q);
    if(N==0&&Q==0)break;
    for(i=0;i<N;i++){
      marked_list[i]=0;
    }marked_list[0]=1;
    original_par[0]=0;
    ans=0;

    for(i=1;i<N;i++){
      scanf("%d\n",&original_par[i]);
      original_par[i]--;
    }
    for(i=0;i<Q;i++){
      char bc;
      scanf("%c %d\n",&bc,&query_list[i][1]);
      query_list[i][0] = bc;
      query_list[i][1]--;
    }

    init(N);
    for(i=0;i<Q;i++){
      if(query_list[i][0]=='M'){
				if(marked_list[query_list[i][1]]==1){
					query_list[i][0]='N';
				}
        marked_list[query_list[i][1]]=1;
      }
    }
    for(i=0;i<N;i++){
      if(0==marked_list[i]){
        unite(original_par[i],i);
      }
    }
    for(i=Q-1;i>=0;i--){
      if(query_list[i][0]=='Q'){
        int q_a = find(query_list[i][1])+1;
        ans += q_a;
      //  printf(":%d\n",ans);
      }else if(query_list[i][0]=='M'){
        int m = query_list[i][1];
        unite(original_par[m],m);
      }
    }
    printf("%lld\n",ans);
  }
  return 0;

}

Measured memory_bytes: 2960
#include<stdio.h>
int main(){
  int i,j,N,minj,a[100],tmp,count;
  count = 0;
  scanf("%d",&N);
  for(i = 0;i < N; i++)   scanf("%d",&a[i]);
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(a[j] < a[minj]){
        minj = j;
      }
    }
    if(i != minj){
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
      count++;
    }
  }
  for(i = 0;i < N; i++){
    printf("%d",a[i]);
  if(i != N-1)
	 printf(" ");
  }
  printf("\n%d\n",count);
}



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

int main(){
  string S;
  cin >> S;
  string T;
  cin >> T;
  
  int sum = 0;
  for(int i=0; i<3; i++){
    if(S.at(i) == T.at(i)){
      sum++;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define     mod             (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     que_min         priority_queue <int, vector<int> , greater<int> >
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << endl;
    //use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif




int32_t main()

{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    IOS;

    int n;
    cin >> n;
    vector<int> v(n);

    vector<int> dp(n + 1, 0);

    for (auto &i : v)cin >> i;

    dp[1] = abs(v[0] - v[1]);

    for (int i = 2; i < n; i++)
    {
        int a  = abs(v[i] - v[i - 1]),  b = abs(v[i] - v[i - 2]);

        dp[i] = min(dp[i - 1] + a, dp[i - 2] + b);
    }

    cout << dp[n - 1] << endl;




}

Measured memory_bytes: 3984
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	vector<char>vec(4);
	rep(i, 4) {
		vec[i] = S.at(i);
	}
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < 3; j++) {
			if (vec[i] == vec[j]) {
				ans++;
			}
		}
	}
	if (ans == 4) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc121/tasks/abc121_a
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int H, W, h, w;
    cin >> H  >> W >> h >> w;
    cout << ( H * W ) - ( ( H * w ) + ( W * h ) - h * w ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int a,b,i,s;
        scanf("%d%d",&a,&b);
        for(i=1;i<=3;i++){
                s=a*b*i;
                if(s%2==1){
                        printf("Yes\n");
                        return 0;
                }
        }
        printf("No\n");
        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s,t,p;
int a,b;
bool cmp(string _i,string j)
{
	if(_i.size()==j.size())
	{
		for(int i=0;i<_i.size();i++)if(_i[i]!=j[i])return 0;
		return 1;
	}
	return 0;
}
int main()
{
	cin>>s>>t;
	scanf("%d%d",&a,&b);
	cin>>p;
	if(cmp(p,s))a--;
	else b--;
	printf("%d %d",a,b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;
const lint INF = 1LL << 60;

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

    lint res = INF;

    int m = max(x, y);

    for (int z = 0; z <= 2*m; z += 2) {
        int ar = max(x - (z/2), 0), br = max(y - (z/2), 0);
        lint total = ar * a + br * b + z * c;
        res = min(res, total);
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    int l;
    int r;
    int MAX = 100000;
    int MIN = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        MIN = max(MIN, l);
        MAX = min(MAX, r);
    }
    //cout << MIN << " " << MAX << endl;
    if (0 <= MAX - MIN + 1)
    {
        cout << MAX - MIN + 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
N, K = map(int,input().split())
P = list(map(int, input().split()))

''' 累積和 '''
cumulative_sum = [P[0]]
for i in range(len(P)-1):
    cumulative_sum.append(cumulative_sum[i] + P[i+1])

#入力
#print(P)
#累積和
#print(cumulative_sum)

#numpy 累積和（高速）
#import numpy
#res = numpy.cumsum(P)
#print(res)

''' 最大値探索 O(N-K) '''
#初期値
max = cumulative_sum[K-1]
max_index = 0
for i in range(N-K):
    now = cumulative_sum[K+i] - cumulative_sum[i]
    if max < now:
        max = now
        index = i
#print(max)
#print(max_index)


ans = (max + K)/2
print(ans)


Measured memory_bytes: 24804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N,K; cin >> N >> K;
  vector<int> V(N);
  rep(i,N) cin >> V[i];

  int G = min(N,K);
  int ans = 0;
  rep(i,G+1) {
    rep(j,G+1-i) {
      priority_queue<int, vector<int>, greater<int>> que;
      int sum = 0;
      rep(k,i) {
        sum += V[k];
        if (V[k] < 0) que.push(V[k]);
      }
      rep(k,j) {
        sum += V[N-1-k];
        if (V[N-1-k] < 0) que.push(V[N-1-k]);
      }
      rep(k,K-i-j) {
        if (!que.empty()) {
          sum -= que.top();
          que.pop();
        }
      }

      ans = max(ans,sum);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
"""
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
import math
import sys
# input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp(): #Reads integer input
    return(int(input()))
def inlt(): #Reads list of int
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr(): #Reads numbers into separate var
    return(map(int,input().split()))

n, k =map(int, input().split())
stones = inlt()
dp = [float('inf')] * n
dp[0] = 0
for i in range(n):
    for j in range(i + 1, i + k + 1): #This updates every possible path
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(stones[j] - stones[i]))
print(dp[n-1])

Measured memory_bytes: 55608
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


int arr[maxii];
int arr2[maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;
int x[]={1,-1,0,0};
int y[]={0,0,-1,1};
int x2[]={1,-1,0,0,1,-1,1,-1};
int y2[]={0,0,-1,1,1,-1,-1,1};
int bx[]={0,0,1,-1,-1,1,1,-1};
int by[]={1,-1,0,0,-1,-1,1,1};
int kx[] = {1,1,2,2,-1,-1,-2,-2};
int ky[] = {2,-2,1,-1,2,-2,1,-1};

bool isvisited(int x,int y)
{
    if(x<1 || y<1 || x>n ||y>m)
    {
        return false;
    }
    else if(check2[x][y]==true)
    {
        return false;
    }
    else return true;
}
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int res=((a)+(b-1))/b;
    cout<<res*c;

}






Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int main(void)
{
    int n;
    string s,t,ans="";
    cin >> n;
    cin >> s >> t;
    for(int i=0;i<n;i++)
    {
        ans+=s[i];
        ans+=t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define REF(j, n) for(int i = j; i <= n; i++)

int a, b, c[100000], d, count;
int main()
{
	std::cin >> a >> b;
	REF(a, b)
	{
		d = i;
		while(d > 0)
		{
			c[i] = c[i] * 10 + d % 10;
			d /= 10;
		}
		if((c[i] - i) == 0)
		{
			count++;
		}
	}

	std::cout << count << std::endl;
}

Measured memory_bytes: 640
S = str(input())
li = [0] * 2019
ans = 0
li[0] = 1

d = 1
s = 0
for i in S[::-1]:
  s += int(i) * d
  s = s % 2019
  li[s] += 1
  d *= 10
  d = d % 2019
  
for l in li:
  ans += l * (l-1) // 2

print(ans)

Measured memory_bytes: 9260
let readNum () =
  stdin.ReadLine ()
  |> System.Int32.TryParse
  |> snd

let ans =
  match readNum () with
    | 1 -> "Hello World"
    | 2 -> 
      let a, b = (readNum ()), (readNum ()) in
      sprintf "%d" (a + b)
    | _ -> failwith "Invalid Value"

printfn "%s" ans

Measured memory_bytes: 13916
n = int(input())
restaurants = [input().split() for i in range(n)]
stores = {}
for name, value in restaurants:
  stores.setdefault(name, [])
  stores[name].append(int(value))
for key, value in stores.items():
  stores[key] = sorted(value, reverse=True)
for name in sorted(stores):
  for i in stores[name]:
    print(restaurants.index([name, str(i)])+1)

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

int main()
{
    int n;
    cin >> n;
    set<string> prize;
    for(int i = 0; i < n; ++i)
    {
        string str;
        cin >> str;
        prize.insert(str);
    }
    cout << prize.size() << endl;
}

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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,x=0,i,ans;
	cin >> n;
	vector<int> v(n);
	for(i=0;i<n;i++)
	{
		cin >> v[i];
		x = x^v[i];
	}
	for(i=0;i<n;i++)
	{
		ans = x^v[i];
		cout << ans << " ";
	}
	cout << endl;
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

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

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[110][110][310];

int main() {
	ll n,w;
	cin>>n>>w;
	vector<ll> vw;
	vector<ll> vv;
	rep(i,0,n){
		ll a,b;
		cin>>a>>b;
		vw.pb(a);
		vv.pb(b);
	}
	ll w1 = vw[0];
	ll mx = 0;
	clr(dp,-1);
	dp[0][0][0] = 0;
	rep(j,1,n+1){
		rep(k,0,n){
			rep(l,0,305){
				if(dp[j-1][k][l]!=-1){
					dp[j][k][l] = max(dp[j][k][l],dp[j-1][k][l]);
					dp[j][k+1][l+vw[j-1]-w1] = max(dp[j][k+1][l+vw[j-1]-w1],dp[j-1][k][l]+vv[j-1]);
				}
			}
		}
	}
	rep(i,0,110){
		rep(j,0,305){
			if(dp[n][i][j]==-1)continue;
			if(w1*i+j<=w){
				mx = max(mx,dp[n][i][j]);
			}
		}
	}
	printf("%lld\n",mx);
	return 0;
}

Measured memory_bytes: 29568
N = int(input())
B = list(map(int, input().split()))

A = [0 for i in range(N)]
A[N-1] = B[N-2]
for i in reversed(range(1,N-1)):
    if B[i-1] <= B[i] :
        A[i] = B[i-1]
    else:
        A[i] = B[i]
A[0] = B[0]
print(sum(A))
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

LL limit = pow(10,18);

int main(){
    int n;
    cin >> n;
    vector<LL> a(n);

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

    sort(a.begin(),a.end(),greater<LL>());

    LL ans = 1;

    for(int i = 0; i < n; ++i){
        if(ans > limit / (LD)a[i]){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int N, k, i;
	scanf("%d", &N);
	for(k = 1; k < N; k <<= 1);
	if(k == N){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	k >>= 1;
	if(N == 3){
		printf("1 2\n");
		printf("2 3\n");
		printf("3 4\n");
		printf("4 5\n");
		printf("5 6\n");
		return 0;
	}
	vector<int> a(N + 1);
	for(i = 1; i < k; i++){
		a[i] = i;
	}
	swap(a[2], a[3]);
	for(i = 1; i < k - 1; i++){
		printf("%d %d\n", a[i], a[i + 1]);
		printf("%d %d\n", a[i] + N, a[i + 1] + N);
	}
	printf("%d %d\n", a[k - 1], 1 + N);
	for(i = N; i > k; i -= 2){
		int x = i, y = i - 1;
		printf("%d %d\n", x, y);
		printf("%d %d\n", x + N, y + N);
		printf("%d %d\n", x, x ^ y);
		printf("%d %d\n", y + N, x ^ y);
	}
	if(N % 2 == 0){
		printf("%d %d\n", 1, k);
		printf("%d %d\n", k + 2, k + N);
	}
	return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		
		String s=scan.next();
		String p=scan.next();
		boolean signal=true;
		
		for(int i=0;i<s.length();i++){
			signal=true;
			for(int j=0;j<p.length();j++){
				if(s.charAt((i+j)%s.length())!=p.charAt(j)){
					signal=false;
					break;
				}
			}
			if(signal){
				break;
			}
		}
		if(signal){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
		scan.close();
	}
}

Measured memory_bytes: 17320
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int x1, y3, x2, y2;
signed main(){
	cin >> x1 >> y3 >> x2 >> y2;
	cout << x2 + y3 - y2 << " " << y2 + x2 - x1 << " " << x1 + y3 - y2 << " " << y3 + x2 - x1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    int *v;
    cin >> n;
    v = new int[n];

    for(int i = 0; i < n; ++i){
        cin >> v[i];
    }

    int ans = 0;
    for(int i = 0; i < n; ++i){
        int c;
        cin >> c;
        if(v[i] > c) ans += v[i]-c;
    }

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

Measured memory_bytes: 256
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]+[j] for j in range(M)]

dic = {}
PY.sort(key = lambda x:x[1])
ken = [0 for i in range(N)]
for k,value,s in PY:
    ken[k-1] += 1
    s1 = str(k).zfill(6)
    s2 = str(ken[k-1])
    s2 = s2.zfill(6)
    dic[s] = s1+s2

ans = sorted(dic.items(),key=lambda x:x[0])

for i,j in ans:
    print(j)

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

# define x first    
# define y second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector         
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
int n;

ll a[Sz], b[Sz];
                    
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  int n; cin >> n;

  for (int i = 1; i <= n; i++)
    cin >> a[i] >> b[i];       
  ll add = 0;
  for (int i = n; i >= 1; i--) {
    add += (b[i] - ((a[i] + add) % b[i])) % b[i];
  }
  cout << add;


  return 0;
}






// Coded by Z..



Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int n;
int main(int argc,char const* argv[])
{
  int ans=0;
  string s;
  cin >> s;
  for(int i=0;i<int(s.size());i++)
    {
      if(s[i]=='2') ans++;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256