akhauriyash/Code-Regression huggingface dataset:
// template version 1.9

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int solve(){
  int n,k;cin>>n>>k;
  cout << n-k+1 << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((a + b) > (c + d))cout << "Left" << endl;
	else if ((a + b) < (c + d))cout << "Right" << endl;
	else cout << "Balanced" << endl;
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

const int INF = 1 << 29;

auto solve() {
    int N, K;
    cin >> N >> K;
    vi h(N);
    for (auto &&e:h)cin >> e;
    sort(all(h));

    int mn = 1e9 + 10;
    REP(i,N) {
        if(i+K-1 < N) {
            mn = min(mn, abs(h[i] - h[i+K-1]));
        }
    }
    return mn;
}


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

    cout << solve() << endl;
//    solve();
    return 0;
}


Measured memory_bytes: 640
module Color
  WHITE = 0
  GRAY = 1
  BLACK = 2
end
def topological_sort(n)
  $color = Array.new(n, Color::WHITE)
  n.times do |u|
    if $indeg[u].zero? && $color[u] == Color::WHITE
      bfs(u)
    end
  end
end

def bfs(s)
  q = []
  q << s
  $color[s] = Color::GRAY
  while !q.empty?
    u = q.shift

    $out << u

    for v in $g[u]
      $indeg[v] -= 1
      if $indeg[v].zero? && $color[v] == Color::WHITE
        $color[v] = Color::GRAY
        q.push(v)
      end
    end
  end
end



v, e = gets.split.map(&:to_i)
$g = Array.new(v) { [] }
$indeg = Array.new(v, 0)
e.times do
  s, t = gets.split.map(&:to_i)
  $g[s] << t
  $indeg[t] += 1
end
$out = []

topological_sort(v)

for u in $out
  puts u
end




Measured memory_bytes: 8004
bargarls = [0]*51;patyls = [0]*51
def bargar(n):
        global bargarls
        if n==1:
                bargarls[n-1] = 1
                return 1
        else:
                num = 2*bargar(n-1) + 3
                bargarls[n-1] = num
                return num
def paty(n):
        global patyls
        if n == 1:
                patyls[n-1] = 1
                return 1
        else:
                num = 2*paty(n-1) + 1
                patyls[n-1] = num
                return num
bargar(51)
paty(51)
def ans(n,x):
        global patyls 
        global bargarls
        if n >= x:return 0
        elif (bargarls[n]+1)//2 > x:return ans(n-1,x-1)
        elif (bargarls[n]+1)//2 == x:return (patyls[n]+1)//2
        elif bargarls[n] == x:return patyls[n]
        else:return (patyls[n]+1)//2 + ans(n-1,x-(bargarls[n]+1)//2)
n,x = map(int,input().split())
print(ans(n,x))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int cost[500];
int A[500];
int main(){
	int n,m,x,costt=0,t;
	scanf("%d%d%d",&n,&m,&x);
	for(int i=1;i<=m;i++){
		scanf("%d",&A[i]);
		cost[A[i]] = 1;
	}
	for(int i=x;i<=n-1;i++)
	 if(cost[i]==1) costt++;
	 t=costt;
	 costt = 0;
	 for(int i=1;i<=x;i++)
	  if(cost[i]==1) costt++;
	  costt=costt>t?t:costt;
	  printf("%d\n",costt); 
	  return 0;
}

Measured memory_bytes: 128
/// Thank you tanakh!!!
///  https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::f64::consts;

fn main() {
    input!(a: f64, b: f64);
    println!("{}", b * b * b * consts::PI * 4.0 / 3.0);
}



Measured memory_bytes: 5056
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long n,d;
  scanf("%lld%lld",&n,&d);
  long long count=0;
  for(int i=1;i<=n;i++){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    if (sqrt(a*a+b*b)<=d){
      count++;
    }
  }
  printf("%lld\n",count);
}


Measured memory_bytes: 3812
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15)+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
using pli=pair<llint,int>;
using daic=priority_queue<pli,vector<pli>,greater<pli>>;
int main(void){
	int n,m,a,b,i,j;cin>>n>>m>>a>>b;
	int ta=0,yo=0,ro=0;
	ro=2*(n/2)*(m/2);
	yo=(n%2)*(m/2);
	ta=(n/2)*(m%2);
	if((a>0&&m==0)||(b>0&&n==0)){cout<<"NO\n";RE;}
	if(a>yo+ro||b>ta+ro||a+b>yo+ro+ta){cout<<"NO\n";RE;}
	if(((n%2==0)||(m%2==0))&&a+b==yo+ro+ta&&(a-yo)%2==1){cout<<"NO\n";RE;}
	cout<<"YES\n";
	vector<string>ans(n,string(m,'.'));
	if(m%2==1){
		for(i=0;i+1<n;i+=2){
			if(b<=0){break;}b--;
			ans[i][m-1]='^';
			ans[i+1][m-1]='v';
		}
	}
	if(n%2==1){
		for(j=0;j+1<m;j+=2){
			if(a<=0){break;}a--;
			ans[n-1][j]='<';
			ans[n-1][j+1]='>';
		}
	}
	for(i=0;i+1<n;i+=2){
		for(j=0;j+1<m;j+=2){
			//cerr<<"de "<<i<<" "<<j<<endl;
			if(a>=2){a-=2;
				  ans[i][j]='<';  ans[i][j+1]='>';
				ans[i+1][j]='<';ans[i+1][j+1]='>';
			}else if(b>=2){b-=2;
				  ans[i][j]='^';  ans[i][j+1]='^';
				ans[i+1][j]='v';ans[i+1][j+1]='v';
			}else if(a>0){a--;
				ans[i][j]='<';  ans[i][j+1]='>';
			}else if(b>0){b--;
				  ans[i][j]='^';
				ans[i+1][j]='v';
			}
		}
	}
	if(b>0){//奥の手
		ans[n-2][m-3]='^';
		ans[n-1][m-3]='v';ans[n-1][m-2]='<';ans[n-1][m-1]='>';
	}
	for(auto it:ans){cout<<it<<endl;}
	RE;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  string s;
  cin>>s;
  int ans=0,tmp=0;
  set<char> st={'A','G','C','T'};
  for (int i = 0; i < s.size(); ++i)
  {
    tmp=0;
    for (int j = i; j < s.size(); ++j)
    {
      if(st.find(s[j])!=st.end())
      {
        tmp++;
      }
      else break;
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    string s,m;

    cin>>s>>m;

    int c=0;

    for(int i=0 ; i<s.size() ; i++){

        if(s[i]!=m[i]){

            c++;
        }
    }

    cout<<c<<endl;
}


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

int main() {
  int w,h,n;
  cin >> w >> h >> n;
  int x1 = 0,x2 = w,y1 = 0,y2 = h;
  for(int i = 0;i < n;i++){
    vector<int>data(3);
    for(int j = 0;j <3;j++){
      cin >> data.at(j);
    }
    if(data.at(2) == 1 && data.at(0) > x1){
      x1 = data.at(0);
    }
    else if(data.at(2) == 2 && data.at(0) < x2){
      x2 = data.at(0);
    }
    else if(data.at(2) == 3 && data.at(1) > y1){
      y1 = data.at(1);
    }
    else if(data.at(2) == 4 && data.at(1) < y2){
      y2 = data.at(1);
    }
    else{
      continue;
    }
  }
  if((x2-x1)*(y2-y1) > 0 && (x2-x1 >0 && y2-y1 > 0)){
    cout << (x2-x1)*(y2-y1) << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
  size_t N;
  intmax_t A, B;
  scanf("%zu %jd %jd", &N, &A, &B);

  std::vector<std::vector<intmax_t>> ncr(N+1, std::vector<intmax_t>(N+1));
  {
    ncr[0][0] = 1;
    for (size_t i = 1; i <= N; ++i) {
      ncr[i][0] = ncr[i][i] = 1;
      for (size_t j = 1; j <= N; ++j)
        ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
    }
  }

  std::vector<intmax_t> v(N);
  for (auto& vi: v) scanf("%jd", &vi);

  std::sort(v.rbegin(), v.rend());

  std::vector<intmax_t> vv(N+1);
  intmax_t sum = std::accumulate(v.begin(), v.begin()+A, 0L);

  printf("%.12f\n", double(sum)/A);

  size_t left = A-1;
  size_t right = A-1;
  while (left > 0 && v[left] == v[left-1]) --left;
  while (right+1 < N && v[right] == v[right+1]) ++right;

  if (v[0] != v[left])
    return !printf("%jd\n", ncr[right-left+1][A-left]);
    
  intmax_t res = 0;
  for (size_t i = A; i <= std::min<size_t>(B, right+1); ++i)
    res += ncr[right-left+1][i-left];

  printf("%jd\n", res);
}


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

int main() {
	string s;
	cin >> s;
	
	if (s == "Sunny"){
	    cout << "Cloudy" << endl;
	}else if (s == "Cloudy"){
	    cout << "Rainy" << endl;
	}else{
	    cout << "Sunny" << endl;
	}
	return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>count(N);
	for (auto &i : A) {
		cin >> i;
		count[i]++;
	}
	rep(i, N) {
		if (i!=0&&count[i] % 2 != 0 || count[0]>=2) {
			cout << 0 << endl;
			return 0;
		}
	}
	ll x=1;
	rep(i, N) {
		if (count[i] != 0) x *= count[i];
		x%=mod;
	}
	cout << x% mod << endl;
	return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
    #![allow(dead_code)]
    use std::io::prelude::*;
    use std::cmp::{max, min};
    use std::collections::BinaryHeap;

    const MOD: i64 = 1e9 as i64 + 7; 

    fn main(){
        let s: String = read();
        let ans = {
            match &*s{
                "Sunny" => "Cloudy".to_string(),
                "Cloudy" => "Rainy".to_string(),
                "Rainy" => "Sunny".to_string(),
                _ => "".to_string(),
            }
        };
        println!("{}", ans);
    }

    fn read<T>() -> T
    where
        T: std::str::FromStr,
    {
        let stdin = std::io::stdin();
        let token: String = stdin
            .lock()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        token.parse().ok().unwrap()
    }


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
const long long INF = 1LL << 40;

using namespace std;

int main() {
  long long n, max_w;
  cin >> n >> max_w;
  long long w[n], v[n];
  for(int i=0; i < n; i++) {
    cin >> w[i] >> v[i];
  }

  long long v_max = 100100;

  long long dp[n+1][v_max+1];
  for(int i=0; i <= n; i++) {
    for(int j=0; j <= v_max; j++) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;

  for(int i=0; i < n; i++) {
    for(int j=0; j <= v_max; j++) {
      if (j - v[i] >= 0) { 
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
      }
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }

  long long ans = 0;
  for(long long sum=0; sum <= v_max; sum++) {
    if (dp[n][sum] <= max_w) ans = sum;
  }

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

Measured memory_bytes: 79232
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;

int main(){
  int cnt = 0;
  long long a, b;
  cin >> a >> b;
  for (int i = a; i <= b; i++){
    if (i/10000 == i%10 && i/1000%10 == i/10%10){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
/*
First, solve the problem.Then write the code. - John Johnson
@author: returnAC
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define need_for_speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // Thanks Joshua :)
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long
int countDivisibles(int A, int B, int M) 
{ 
    // Add 1 explicitly as A is divisible by M 
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
}
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	need_for_speed;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int res = b-a+1;
	res-=countDivisibles(a,b,c);
	res-=countDivisibles(a,b,d);
	res+=countDivisibles(a,b,(c*d)/__gcd(c,d));
	cout<<res<<endl;
}

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

#define int long long
#define PB push_back
#define PPB pop_back
#define MK make_pair
#define ALL(V) V.begin(), V.end()
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef pair<int, pii> pipii;

static const int INF = 1LL << 61;
//static const int MOD = 1000000007;
static const int MAX_N = 1 << 18;

struct Seg {
    int n;
    int dat[MAX_N * 2];

    void Init(int pn, int def) {
        n = 1;
        while (n < pn) n *= 2;
        fill(dat, dat + MAX_N * 2, def);
    }
};

struct SegMin : Seg {
    int Min(int s, int t) {
        return Min(s, t, 0, 0, n);
    }

    int Min(int s, int t, int k, int l, int r) {
        if (r <= s || t <= l) return INF;
        if (s <= l && r <= t) return dat[k];

        int t1 = Min(s, t, k * 2 + 1, l, (l + r) / 2);
        int t2 = Min(s, t, k * 2 + 2, (l + r) / 2, r);
        return min(t1, t2);
    }

    void Update(int k, int x) {
        k += n - 1;
        dat[k] = x;
        while (0 < k) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
};

struct SegMax : Seg {
    int Max(int s, int t) {
        return Max(s, t, 0, 0, n);
    }

    int Max(int s, int t, int k, int l, int r) {
        if (r <= s || t <= l) return 0;
        if (s <= l && r <= t) return dat[k];

        int t1 = Max(s, t, k * 2 + 1, l, (l + r) / 2);
        int t2 = Max(s, t, k * 2 + 2, (l + r) / 2, r);
        return max(t1, t2);
    }

    void Update(int k, int x) {
        k += n - 1;
        dat[k] = x;
        while(0 < k) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
};

SegMin xmin, ymin;
SegMax xmax, ymax;
int n, d;
vector<pipii> st;

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

    cin >> n >> d;
    for (int i = 0; i < n; ++i) {
        int x, y, b;
        cin >> x >> y >> b;
        st.PB(MK(b, MK(x, y)));
    }
    sort(ALL(st));
    
    xmin.Init(n, INF);
    ymin.Init(n, INF);
    xmax.Init(n, 0);
    ymax.Init(n, 0);
    for (int i = 0; i < n; ++i) {
        int x = st[i].second.first, y = st[i].second.second;
        xmin.Update(i, x);
        xmax.Update(i, x);
        ymin.Update(i, y);
        ymax.Update(i, y);
    }

    int ans = 0;

    for (int i = 0; i < n - 1; ++i) {
        int b = st[i].first;
        int s = lower_bound(ALL(st), MK(b, MK(-INF, -INF))) - st.begin();
        int t = lower_bound(ALL(st), MK(b + d, MK(INF, INF))) - st.begin();

        int lx = xmin.Min(s, t);
        int rx = xmax.Max(s, t);
        int by = ymin.Min(s, t);
        int uy = ymax.Max(s, t);
        ans = max(ans, (rx - lx) * (uy - by));
    }

    cout << ans << endl;
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum = 0;
    if(k>=a){
        sum += a;
        k-=a;
    }else{
        cout<<k<<endl;
        return 0;
    }

    if(k>=b){
        k-=b;
    }else{
        cout<<a<<endl;
        return 0;
    }

    if(k>=c){
        sum -= c;
    }else{
        sum -= k;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

// 11
class Main{
	static int breakNumber(int n) {
		if (n % 2 == 0) {
			int tmp = n;
			int count = 0;
			while (tmp > 0) {
				if(tmp / 2 == 1) {
					++count;
					break;
				}
				tmp /= 2;
				++count;
			}
			return count;
		}
		
		return 0;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int ans = 0;
		for(int i = 2; i <= N; i++)
			ans = Math.max(ans, breakNumber(i));
		
		System.out.println((int)Math.pow(2, ans));
	}

}


Measured memory_bytes: 35916
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,d,x,y,ans=0;
	scanf("%lld%d",&n,&d);d*=d;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&x,&y);
		ans+=(x*x+y*y<=d);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    ll c[n-1],s[n-1],f[n-1];
    for(ll i=0;i<n-1;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    ll ans;
    for(ll i=0;i<n;i++){
        ans=0;
        for(ll j=i;j<n-1;j++){
            if(ans>s[j]){
                if(ans%f[j]!=0){
                    ans=ans-(ans%f[j])+f[j]+c[j];
                }else{
                    ans=ans+c[j];
                }
            }else{
                ans=s[j]+c[j];
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int a, b, c;
	int max, min;
	scanf("%d %d %d", &a, &b, &c);
	if (a > b && a > c)
	{
		max = a;
	}
	else if (b > a && b > c)
	{
		max = b;
	}
	else 
	{
		max = c;
	}
	if (a < b && a < c)
	{
		min = a;
	}
	else if (b < a && b < c)
	{
		min = b;
	}
	else 
	{
		min = c;
	}
	printf("%d %d %d\n", min, a+b+c-max-min, max);
	
	return 0;
	
}


Measured memory_bytes: 2732
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;

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

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }




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

	lint a[10];
	rep(i, 10)cin >> a[i];
	sort(a, a + 10);
	rep(i, 3)co(a[9 - i]);
	gc();
}


Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(3 * N);
	for (int i = 0; i < 3 * N; i++) cin >> a[i];
	long long ans = 0;
	sort(a.begin(), a.end());
	int index = 3 * N - 2;
	for (int i = 0; i < N; i++) {
		ans += a[index];
		index -= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g;

vector<double> e;
vector<double> ans;
void dfs1(int v, int p = -1){
	double res = 0;
	int ch = 0;
	for(auto nv : g[v]){
		if(nv == p)continue;
		dfs1(nv, v);
		res += e[nv] + 1.0;
		++ch;
	}
	e[v] = 0;
	if(ch >= 1)e[v] += res / ch;
}

void dfs2(int v, int p = -1, double d_par = 0){
	double res = 0;
	for(auto nv : g[v]){
		if(nv == p)res += d_par + 1.0;
		else res += e[nv] + 1.0;
	}
	ans[v] = res / g[v].size();
	for(auto nv : g[v]){
		if(nv == p)continue;
		dfs2(nv, v, (res - e[nv] - 1.0) / max(1, (int)g[v].size() - 1));
	}
}

int main(){
  int n;
  cin >> n;
  g.resize(n);
  for(int i = 0; i < n - 1; ++i){
  	int u, v;
  	cin >> u >> v;
  	--u;
  	--v;
  	g[u].push_back(v);
  	g[v].push_back(u);
  }

  e.assign(n, 0);
  ans.assign(n, 0);
  dfs1(0);
  dfs2(0);
  for(int i = 0; i < n; ++i)printf("%.12f\n", ans[i]);
  return 0;
}


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

/*
int main(){
    int n; cin>>n;
    vector<int> a(n);
    int cnt=0,m=1e9;
    long long ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0) cnt++;
        m=min(m,abs(a[i]));
        ans+=abs(a[i]);
    }
    if(cnt%2) ans-=2*m;
    
    cout<<ans<<endl;
}
*/

long long dp[100005][2];

int main(){
    int n; cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    dp[0][1]=-1e9;
    for(int i=0;i<n;i++){
        dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
        dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
    }
    cout<<dp[n][0]<<endl;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n, a, b;
    cin >> n >> a >> b;
    vector<int> v0;
    vector<int> v1;
    for (int i = 0; i < n; i++) {
        if (((a >> i) & 1) == ((b >> i) & 1)) {
            v0.push_back(i);
        } else {
            v1.push_back(i);
        }
    }
    if (v1.size() % 2 == 0) {
        cout << "NO\n";
        return 0;
    };
    vector<int> p;
    int i = v1.back();
    v1.pop_back();
    p.push_back(a & (1 << i));
    p.push_back(b & (1 << i));

    for (int i : v0) {
        int c = (a >> i) & 1;
        vector<int> pp;
        for (int x : p) {
            pp.push_back(x | (c << i));
            c = 1 - c;
            pp.push_back(x | (c << i));
        }
        p = pp;
    }

    while (v1.size() > 0) {
        int i = v1.back();
        v1.pop_back();
        int j = v1.back();
        v1.pop_back();

        int ci = (a >> i) & 1;
        int cj = (a >> j) & 1;

        vector<int> pp;
        for (int x : p) {
            pp.push_back(x | (ci << i) | (cj << j));
            ci = 1 - ci;
            pp.push_back(x | (ci << i) | (cj << j));
            cj = 1 - cj;
            pp.push_back(x | (ci << i) | (cj << j));
            ci = 1 - ci;
            pp.push_back(x | (ci << i) | (cj << j));
        }
        p = pp;

        if (((p.back() >> i) & 1) != (((b >> i) & 1))) {
            std::swap(p[p.size() - 3], p[p.size() - 1]);
        }
    }

    cout << "YES\n";
    for (int x : p) {
        cout << x << " ";
    }
    cout << "\n";

    return 0;
}

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

map<string,bool> cek;

int main(){
	int n,ans=0;
	cin >> n;
	while(n--){
		string x;
		cin >> x;
		if (!cek[x]){
			cek[x]=1;
			ans++;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 19232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		
		if(500*k >= x) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  ll a, b, x;
  cin >> a >> b >>x;
  ll ans = b / x - max((ll)0,a-1) / x;
  ans += (a == 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#define N 200001
#include <stdlib.h>

int compare(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}


int main()//リニューアル
{

    int a;

    long long Big[N];
    long long small[N];

    scanf("%d", &a);

    for (int i = 0; i < a; i++)
    { //道を読み取る

        scanf("%lld %lld", &small[i],&Big[i]);

    }
    qsort(Big, a, sizeof(long long), compare);
    qsort(small,a, sizeof(long long), compare);

    if(a%2==0){
        long long distance =(Big[a / 2] + Big[a / 2-1] )- (small[a / 2]+small[a / 2-1]);//わる２して普通に差
        printf("%lld", distance+1);
    }
    else{//基
        printf("%lld", Big[a / 2] - small[a / 2] + 1);
    }


    printf("\n");
}


Measured memory_bytes: 6804
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn inner_rate(join_cnt: u32, show_rate: u32) -> u32 {
    if join_cnt > 10 {
        show_rate
    } else {
        show_rate + (100 * (10 - join_cnt))
    }
}

fn main() {
    input!{n: u32, r: u32,}
    println!("{}", inner_rate(n, r));
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRF(f) printf("%.10lf\n",f)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define MOD 1000000007
typedef long long int ll;
int main(void){
  int n;
  ll m,ans=0,x;
  int sum=0,sam=0;
  scanf("%d %lld",&n,&m);
  x=(m*(m-1)/2)%MOD;
  m=(m*(m+1)/2)%MOD;
  int a[n];
  FOR(n)scanf("%d",&a[i]);
  FOR(n){
    FORJ(i)if(a[i]>a[j])sam++;
    for(int j=i+1;j<n;j++)if(a[i]>a[j])sum++;
  }
  FOR(sum)ans=(ans+m)%MOD;
  FOR(sam)ans=(ans+x)%MOD;
  PRL(ans);
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind ufr(n), uft(n);
    for (int i = 0; i < k; ++i) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        ufr.unite(p, q);
    }
    for (int i = 0; i < l; ++i) {
        int r, s;
        cin >> r >> s;
        r--, s--;
        uft.unite(r, s);
    }
    map<pii, ll> cnt;
    for (int i = 0; i < n; ++i) {
        int r = ufr.root(i);
        int t = uft.root(i);
        cnt[{r, t}]++;
    }
    for (int i = 0; i < n; ++i) {
        int r = ufr.root(i);
        int t = uft.root(i);
        cout << cnt[{r, t}];
        if (i == n - 1)
            cout << endl;
        else
            cout << " ";
    }
    return 0;
}

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

#define lpsbd(i, s, b, d) for(size_t i = s; i < b; i+=d)
#define lpsb(i, s, b) for(size_t i = s; i < b; i++)
#define lpn(i, n) for(size_t i = 0; i < n; i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int N;
    cin>> N;
    auto A = vc(int, N);
    fa(i, A) cin >> i;
    int M = 0;
    vector<int> ans = {-1, 1000000001};
    int l, r, c;
    for (int i = 0; i < N; i++)
    {
        l = 0;
        r = ans.size() - 1;
        while(r - l > 1)
        {
            c = (l + r) / 2;
            if (ans[c] < A[i]) l = c;
            else r = c;
        }
        if (l) ans[l] = A[i];
        else ans.insert(ans.begin() + 1, A[i]);
    }
    cout << ans.size() - 2 << endl;
    return 0;
}

Measured memory_bytes: 1276
#include <cstdio>
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
const int N = 1e5 + 10;
int n, K, ans, a[N], q[N], deg[N], dis[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

int main() {
	int u, v, l = 0, r = 0; in(n), in(K);
	for (int i = 1; i <= n; ++i) in(a[i]), ++deg[a[i]];
	if (a[1] != 1) --deg[a[1]], a[1] = 1, ++ans;
	for (int i = 1; i <= n; ++i) if (!deg[i]) q[++r] = i;
	for (; l < r;) {
		v = a[u = q[++l]]; if (u == 1) break; 
		if (v != 1 && dis[u] == K - 1) ++ans;
		else dis[v] = max(dis[v], dis[u] + 1);
		if (!(--deg[v])) q[++r] = v;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1664
#!/usr/bin/env python3
import sys


def solve(N: int, p: "List[int]"):
    p.sort(reverse=True)
    ans = int(p[0]/2)

    for i in range(1,N):
        ans += p[i]

    print(ans)
    
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	long long x;

	scanf("%lld", &x);
	
	for (long long a = -200; a <= 200; a++){
		for (long long b = -200; b <= 200; b++){
			if (a == b)
				continue;
			long long a5 = a * a * a * a * a;
			long long b5 = b * b * b * b * b;
			if (a5 - b5 == x){
				printf("%lld %lld\n", a, b);
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3816
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{

    static final FastReader in = new FastReader();
    static final FastWriter out = new FastWriter();

    public static void main(String[] args) throws IOException{
        String s = in.nextLine();

        int ans = 0, cs = 0;
        for (int i = 0; i < 3; i++){
            char c = s.charAt(i);
            if (c == 'R'){
                cs++;
            }
            else{
                cs = 0;
            }
            ans = Math.max(ans, cs);
        }
        out.pl(ans);
        out.close();
    }
}
class FastReader{
    BufferedReader br;
    StringTokenizer st;
    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    }
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 32804
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
a_ = -float('inf')
for a in A:
    a = a - 1
    ans += B[a]
    if a_ == a - 1:
        ans += C[a_]
    a_ = a
    
print(ans)    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
static const int INF=100000000000;
int main(){
int N; int64_t W;
  cin>>N>>W;
  vector<int64_t>w(N);
  vector<int>v(N);
  for(int i=0;i<N;i++){
  cin>>w.at(i);
    cin>>v.at(i);
  }vector<vector<int64_t>>dp(1+N,vector<int64_t>(100001,0));
  for(int j=1;j<=100000;j++)
    dp[0][j]=INF;
  for(int i=1;i<=N;i++){
  for(int j=1;j<=100000;j++){
  if(v[i-1]<=j)
    dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
  else
    dp[i][j]=min(dp[i-1][j],w[i-1]);
  }
  
  }auto itr=upper_bound(dp[N].begin(),dp[N].end(),W);
    int ans=distance(dp[N].begin(),itr)-1;
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 80256
#include <iostream>
using namespace std;
int main(void){
    string str="";
    int flag=0;
    cin >> str;
    for(int i=0;i<2;i++){
        if(str.at(i)!=str.at(i+1)){
            flag=1;
        }
    }
    if(flag==1){
        cout << "Yes" <<endl;
    }
    else
    cout << "No" <<endl;
}


Measured memory_bytes: 256
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
方針
#差分をとって、0を抜いた数列をつくる
    これにて非単調減少・増加を単調増加、単調減少として捉えられる
#隣り合う2つ正負が違うなら積は負になるので
#負になった2つの間で切ればよい
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
A=list(pin())
B=[(A[j+1]-A[j])for j in range(len(A)-1)]
C=[]
for i in range(len(B)):
    if B[i]!=0:
        C.append(B[i])

k=0
ans=0
#print(A)
#print("",B)
#print(C)
while(k<len(C)-1):
    #print(k)
    if C[k+1]*C[k]<0:
        #print("crak is right of A[",k+1,"]")
        k+=1#１っことばす
        ans+=1
    k+=1
print(ans+1)

Measured memory_bytes: 64364
N = int(input())
A = list(map(int, input().split()))
#import random
#N = 3000
#A = [random.randint(1, 10**9) for _ in range(N)]


dp = [[0] * (N+1) for _ in range(N+1)]
for g in range(N):
  for l in range(N-g):
    r = l + g
    n = r - l
    s = -1 if (N-n) % 2 == 0 else 1
    lv = dp[l+1][r] + s*A[l]
    rv = dp[l][r-1] + s*A[r]
    if s*lv > s*rv:
      dp[l][r] = lv
    else:
      dp[l][r] = rv

print(dp[0][N-1])



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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int k, n;
    cin >> k >> n;

    vi a(n);
    rep(i, 0, n) { cin >> a[i]; }

    sort(a.begin(), a.end());

    int maxv = a[0] - a[n - 1] + k;
    rep(i, 0, n - 1) { maxv = max(maxv, a[i + 1] - a[i]); }

    cout << k - maxv << endl;
    return 0;
}

Measured memory_bytes: 1024
MOD = 10 ** 9 + 7
s = input()
n = len(s)
dp = [[0] * 4 for _ in range(n + 1)]
dp[0][0] = 1
for i in range(n):
  if s[i] == '?':
    dp[i + 1][0] += dp[i][0] * 3
    dp[i + 1][0] %= MOD
  else:
    dp[i + 1][0] += dp[i][0]
  for j in range(3):
    if s[i] == 'ABC'[j] or s[i] == '?':
      dp[i + 1][j + 1] += dp[i][j]
    dp[i + 1][j + 1] += dp[i][j + 1] * (3 if s[i] == '?' else 1)
    dp[i + 1][j + 1] %= MOD
print(dp[n][3] % MOD)

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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s / 100;
  s = s % 100;
  s2 = s / 10;
  s3 = s % 10;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,T;
  string s;
  cin >> n >> s >> T;
  while(T--) {
    ll d;
    R d;
    ll x=0,y=0,sum=0,ans=0;
    queue<P> que;
    rep(i,n) {
      while(!que.empty()) {
        P p=que.front();
        if(p.S==1) {
          que.pop();
          y--;
        } else if(i-p.F>=d) {
          que.pop();
          sum-=y;
          x--;
        } else break;
      }
      if(s[i]=='C') {
        ans+=sum;
      } else if(s[i]=='D') {
        que.push(P(i,0));
        x++;
      } else if(s[i]=='M') {
        que.push(P(i,1));
        y++;
        sum+=x;
      }
    }
    pr(ans);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 20588
N = int(input())
A = list(map(int, input().split()))

mod = 1000000007
S = {}
S[0] = A[0]
for i in range(1, len(A)):
    S[i] = S[i-1] + A[i]

ans = 0
for i in range(len(A)):
    sum = S[len(S)-1] - S[i]
    ans += A[i] * sum
print(ans%mod)


Measured memory_bytes: 126760
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
others = 0
for i in range(N):
  case = input()
  if case == "AC":
    AC += 1
      
  elif case == "WA":
    WA += 1
      
  elif case == "TLE":
    TLE += 1
      
  elif case == "RE":
    RE += 1
      
print("AC"+" x "+str(AC))
print("WA"+" x "+str(WA))
print("TLE"+" x "+str(TLE))
print("RE"+" x "+str(RE))

Measured memory_bytes: 9112
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(ll i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(ll i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;

ll nCr(ll n, ll r) {
    long ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
////////////////いろいろあるよ//////////////////////////////////
int main(){
	ll N;
  	cin >>N;
  	ll data[N]; REP(i,N)cin >> data[i];
  	map<ll,ll> datata;
  	REP(i,N){
      bool iii=false;
      REP(j,datata.size()){
        if(datata.count(data[i]))iii = true;
        datata[data[i]]++;
        break;
      }
      if(iii==false)datata[data[i]] = 1;
    }
  
  	map<ll,ll> sum;
  
  	// Keyの値が小さい順にループ
for (auto p : datata) {
  auto key = p.first;
  auto value = p.second;
  // key, valueを使う
  	sum[key] = nCr(value,2);
}
  ll sumsum = 0;
for (auto p : sum) {
  auto key = p.first;
  auto value = p.second;
  // key, valueを使う
  	sumsum+= value;
}
  	REP(i,N){
      	
    	cout << sumsum - (datata[data[i]]-1) << endl;
    }
  	
}


Measured memory_bytes: 18944
import sys
input = sys.stdin.readline

class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def build(self, lis):
        self.value = lis
        for i, x in enumerate(lis):
            self.add(i+1, x)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
    
    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
    
    def get_sum(self, i, j):
        return self.sum(j) - self.sum(i)


def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    bit = FenwickTree(n)
    bit.build(a)
    
    for i in range(q):
        a, b, c = map(int, input().split())
        if a == 0:
            bit.add(b+1, c)
        else:
            print(bit.get_sum(b, c))
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 127604