akhauriyash/Code-Regression huggingface dataset:
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, parser) => {
        $next
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
    }

    let mut sum = 0;
    for i in 1..n + 1 {
        if i % 3 != 0 && i % 5 != 0 {
            sum += i;
        }
    }
    println!("{}", sum);
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

template<class T> inline bool chmin(T& a, const T b) { if (a>b) { a=b; return true; } return false; }
template<class T> inline bool chmax(T& a, const T b) { if (a<b) { a=b; return true; } return false; }


int n,a;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>a;
    int ans = n*n - a;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n],s;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==0)
        {
            s=~a[i];
        }
        else
        s=s^(~a[i]);
    }
    for(ll i=0;i<n;i++)
    {
        a[i]=a[i]^s;
    }
    for(ll i=0;i<n;i++)
    cout<<a[i]<<" ";

    return 0;
}

Measured memory_bytes: 5076
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<cstring>
#include<set>
#include<ctime>
using namespace std;

#define rep(i,m) for(int i=0;i<m;i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define mm1(x) memset(x,-1,sizeof(x))
#define ms(x,n) memset(x,n,sizeof(x))
#define SORT(x) sort((x).begin(),(x).end())
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

/*
const int INF = 100000000;
const int mod = 1e9 + 7;


int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);

}

int main() {
	int h, w; cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	rep(i, h)rep(j, w)cin >> a[i][j];
	int st = false;
	while (!st) {
		rep(i, h) {
			rep(i, w) {

			}
		}
	}
}
/*
		  , -- 、
		/;;;;;;', 　　　WA（４）（順位表から得られない情報）
		i二二二i	
	  , ' 　    ヽ		
	 i　ﾉﾉﾉﾉﾉﾍ .', 　　←彼女はRedCoderです
	 〉ﾘi' ﾟ ヮﾟﾉﾚく　			
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
	  ,ｒ/ー i-ヽヽ 　　　
	 ｀｀i_ﾗi_ﾗ
	 pass System test WAYON!!

	
*/

int main() {
	int a, b, k; cin >> a >> b >> k;
	if (k % 1000 > 500) {
		cout << min(a, 2 * b)*((k + 999) / 1000) << endl;

	}
	else if (k % 1000 == 0) {
		cout << min(a, 2 * b)*(k / 1000) << endl;
	}
	else {
		cout << min(a, 2 * b)*(k / 1000) + min(a, b)<< endl;
	}

}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main() {
    int r, c, k;
    cin >> r >> c >> k;
    unordered_map<ll, ll> mp;
    for(int i = 0; i < k; i++){
        int tr, tc, tv;
        cin >> tr >> tc >> tv;
        mp[c*tr+tc] = tv;
    }


    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(c+1, vector<ll>(4, 0)));
    for(int i = 1; i <= r; i++){
        for(int j = 1; j <= c; j++){
            dp[i%2][j][0] = max({dp[(i+1)%2][j][0], dp[(i+1)%2][j][1], dp[(i+1)%2][j][2], dp[(i+1)%2][j][3], dp[i%2][j-1][0]});
            ll val = mp[i*c+j];
            if(val == 0){
                dp[i%2][j][1] = dp[i%2][j-1][1];
                dp[i%2][j][2] = dp[i%2][j-1][2];
                dp[i%2][j][3] = dp[i%2][j-1][3];
            }else{
                dp[i%2][j][1] = max({dp[(i+1)%2][j][0]+val, dp[(i+1)%2][j][1]+val, dp[(i+1)%2][j][2]+val, dp[(i+1)%2][j][3]+val, dp[i%2][j-1][1], dp[i%2][j-1][0]+val});
                dp[i%2][j][2] = max(dp[i%2][j-1][2], dp[i%2][j-1][1]+val);
                dp[i%2][j][3] = max(dp[i%2][j-1][3], dp[i%2][j-1][2]+val);
            }
        }
    }
    ll ans = max({dp[r%2][c][0], dp[r%2][c][1], dp[r%2][c][2], dp[r%2][c][3]});
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 489416
#include<iostream>
#include<vector>

using namespace std;

int main(){
    double w,h,x,y;
    cin>>w>>h;
    cin>>x>>y;
    if(2*x==w && 2*y==h){
        cout<<w*h/2.0<<" "<<1<<endl;
    }else{
        cout<<w*h/2.0<<" "<<0<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int n;
    cin >> n;
    REP(i,n){
	string s;
	cin >> s;
	ll m = strtol(s.c_str(),NULL,16);
	string ans = "";
	int it = 0;
	double ft = 0;
	if((m&(1<<31))!=0) ans+="-";
	REP(i,24){
	    it += (m&(1<<(7+i)))>>7;
	}
	ans += to_string(it);
	ans += ".";
	REP(i,7){
	    if((m&(1<<(6-i)))!=0){
		ft += pow(0.5,i+1);
	    }
	}
	if(ft == 0) {
	    ans += "0";
	    cout << ans << endl;
	}else{
	    string fs = to_string(ft);
	    while(ft != 0){
		ft *= 10;
		ans += to_string((int)ft);
		ft -= (int)(ft);
	    }
	    while(ans.back()=='0'){
		ans.erase(ans.begin()+ans.size()-1);
	    }
	    cout << ans << endl;
	}
    }

    return 0;
}

Measured memory_bytes: 3428
#include <stdio.h>

int main(void)
{
	int a,b,c,w;
	scanf("%d%d%d",&a,&b,&c);
	
	if (a>b){
		w=a;
		a=b;
		b=w;
	}
	if (b>c){
		w=b;
		b=c;
		c=w;
	}
	if (a>b){
		w=a;
		a=b;
		b=w;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}


Measured memory_bytes: 2056
#include<stdio.h>
#define N 200000
int main()
{
  int x,i,j,a[N],maxv,minv;
  scanf("%d",&x);
  for(i=0;i<x;i++)
    scanf("%d",&a[i]);
  maxv=a[1]-a[0];
  minv=a[0];
  for(j=1;j<x;j++){
    if(maxv < a[j]-minv) maxv = a[j]-minv;
    if(minv > a[j]) minv = a[j];
  }
    printf("%d\n",maxv);
    return 0;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	ll S;
	cin >> S;

	const ll C = 1000000000LL;

	if (C * C == S) {
		cout << "0 0" << " " << C << " 0" << " " << "0 " << C << endl;
		return 0;
	}

	const ll a = C;
	const ll b = 1LL;

	const ll c = C - S % C;
	const ll d = (S + c) / C;

	cout << "0 0" << " " << a << " "  << b << " " << c << " " << d << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    d = list(input().split())
    i = n
    while True:
        stri = list(str(i))
        flg = True
        for j in d:
            if j in stri:
                flg = False
        if flg:
            print(i)
            return
        i += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
from math import ceil, log


def solve(string):
    n = int(string)
    max_number = 10**5
    can_operate = [1] + [6**(i + 1) for i in range(ceil(log(max_number, 6)))
                        ] + [9**(i + 1) for i in range(ceil(log(max_number, 9)))]
    can_operate = sorted(can_operate)
    dp = [0]
    for _ in range(n + 0):
        tmp = n
        for o in can_operate:
            index = len(dp) - o
            if index < 0:
                break
            tmp = min(tmp, dp[index] + 1)
        dp.append(tmp)
    return str(dp[-1])


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 45424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
 
int main(){
    ll N;
    cin >> N;
    vector<string> W(N);
    map<string, ll> v;
    cin >> W[0]; v[W[0]]++;
    rep(i, 1, N){
        cin >> W[i];
        if(W[i][0] != W[i-1][W[i-1].size()-1] || v.count(W[i]) > 0){
            cout << "No" << endl;
            return 0;
        }
        v[W[i]]++;
    }
    
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int main()
{
  int n;
  string ss;
  cin >> ss;

  int sum = 0;
  for (int i = 0; i < ss.size(); i++)
  {
    char ch = ss[i];
    sum += atoi(&ch);
  }

  if (sum % 9 == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int n, tmp, c=pow(10,5)+1;
	cin >> n;
	int num[c] = {0};
	REP(i, 0, n){
		cin >> tmp;
		++num[tmp];
	}
	
	int ans = 0;
	REP(i, 0, c){
		if(i == 0) ans = max(ans, num[i]+num[i+1]);
		else if(i== c-1) ans = max(ans, num[i]+num[i-1]);
		else ans = max(ans, num[i]+num[i+1]+num[i-1]);
	}
	cout << ans;

}


Measured memory_bytes: 640
<?php
  
  list($A,$B,$M) = explode(" ",trim(fgets(STDIN)));

  $a = explode(" ",trim(fgets(STDIN)));
  $b = explode(" ",trim(fgets(STDIN)));
  $amin=1000000;
  $bmin=1000000;
  for($i=0;$i<$A;$i++){
    if($amin > $a[$i]){
      $amin=$a[$i];
    }
  }
  for($i=0;$i<$B;$i++){
    if($bmin > $b[$i]){
      $bmin=$b[$i];
    }
  }
  $min = $amin+$bmin;
  for($i=0;$i<$M;$i++){
    list($x,$y,$m) = explode(" ",trim(fgets(STDIN)));
    if($min > $a[$x-1]+$b[$y-1]-$m){
      $min = $a[$x-1]+$b[$y-1]-$m;
    }
  }

  echo $min;

Measured memory_bytes: 21108
def f n
s=r=0
((2..n).map{r+=i=gets.to_i;i}<<360-r).map{|i|s+=Math.sin Math::PI/180*i}
s
end
while 0<n=gets.to_i
s=f n
t=f gets.to_i
p [1,[s,t].max].any?{|i|1e-9*i>(s-t).abs}?0:s>t ?1:2
end

Measured memory_bytes: 6156
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
P ball[200001];
int idx;
ll solve1(){
  ll Rmin = ball[0].first;
  ll Bmax = ball[idx].second;
  ll Rmax = ball[n-1].first;
  ll Bmin = Bmax;
  for(int i=0;i<n;++i)
    Bmin = min(Bmin,ball[i].second);
  return (Rmax-Rmin)*(Bmax-Bmin);
}

ll solve2(){
  ll Rmin = ball[0].first;
  ll Rmax = ball[idx].second;
  set<P> S;
  S.insert(P(ball[0].second,1000000));
  for(int i=0;i<n;++i)
    if(i)
      S.insert(P(ball[i].second,i));
  ll ret = 1LL<<60;
  while(1){
    ll dif = S.rbegin()->first - S.begin()->first;
    ret = min(ret, (Rmax-Rmin)*dif);
    auto a = *S.rbegin();
    S.erase(*S.rbegin());
    if(a.second>=1000000) break;
    S.insert(P(ball[a.second].first,1000000));
  }
  return ret;
}
int input(){
  int x;
  scanf("%d",&x);
  return x;
}
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;++i){
    ball[i]=P(input(),input());
    if(ball[i].first > ball[i].second)
      swap(ball[i].first, ball[i].second);
  }
  sort(ball,ball+n);
  int MAX = 0;
  idx = -1;
  for(int i=0;i<n;++i){
    if(MAX < ball[i].second){
      MAX = ball[i].second;
      idx = i;
    }
  }
  //  cout<<solve1() << " " << solve2() << endl;
  cout << min(solve1(),solve2()) << endl;
  
  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  s[3] = '8';
  cout << s << endl;

  return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a < b){
    cout << "a < b" << endl;
  }else if(a > b){
    cout << "a > b" << endl;
  }else{
    cout << "a == b" << endl;
  }
  return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <cmath>
#define EPS (1.0e-8)

using namespace std;
 
int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double a[2], b[2];
  double A, B;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    a[0] = x2 - x1;
    a[1] = y2- y1;
    b[0] = x3 - x1;
    b[1] = y3 - y1;
    if(fabs(a[0] * b[0] + a[1] * b[1]) != 1) {
      A = (b[1] * (xp - x1) - b[0] * (yp - y1)) / (a[0] * b[1] - b[0] * a[1]);
      B = (a[1] * (xp - x1) - (yp - y1) * a[0]) / (a[1] * b[0] - b[1] * a[0]);
      if ((A+B < 1) && (A > 0) && (B > 0)) {
        cout << "YES" << endl;
      }
      else {
        cout << "NO" << endl;
      }
    }
    else
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int ans;
	if(a==1)
	{
		if(b==2)
			ans=3;
		else
			ans=2;
	}	
	if(a==2)
	{
		if(b==1)
			ans=3;
		else
			ans=1;
	}
	if(a==3)
	{
		if(b==1)
			ans=2;
		else
			ans=1;
	}
	cout<<ans;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    int N;
    int A, B, C;

    int INF = 1000000000;

    int[] l;

    public void Do()
    {
        cin = new Scanner();
        N = cin.nextInt();
        A = cin.nextInt();
        B = cin.nextInt();
        C = cin.nextInt();

        l = new int[N];
        for (int i = 0; i < N; i++)
        {
            l[i] = cin.nextInt();
        }

        Console.WriteLine(dfs(0, 0, 0, 0));
    }

    int dfs(int cur, int a, int b, int c)
    {
        if (cur == N)
        {
            if (a != 0 && b != 0 && c != 0)
            {
                return Math.Abs(A - a) + Math.Abs(B - b) + Math.Abs(C - c) - 30;
            }
            return INF;
        }

        int ret0 = dfs(cur + 1, a, b, c);
        int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
        int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
        int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;

        return Math.Min(Math.Min(ret0, ret1), Math.Min(ret2, ret3));
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 13140
from collections import Counter
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    hoge = list(map(int,input().split()))
    a.append(hoge[0])
    b.append(hoge[1])

tenbo = []
for i in range(m):
    if h[a[i]-1] > h[b[i]-1]:
        tenbo.append(b[i])
    elif h[a[i]-1] < h[b[i]-1]:
        tenbo.append(a[i])
    elif h[a[i]-1] == h[b[i]-1]:
        tenbo.append(a[i])
        tenbo.append(b[i])

print(n - len(Counter(tenbo)))

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

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

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");


signed main(){
    int n;cin>>n;
    int a[114514],b[114514],c[114514];
    rep(i,0,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    int time=0;
    int h=0,w=0;
    rep(i,0,n){
        int key=a[i]-time-(abs(b[i]-h)+abs(c[i]-w));
        if(key<0||key%2==1){
            cout<<"No"<<endl;
            return 0;
        }
        else {
            time=a[i];
            h=b[i];w=c[i];
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 2816
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;

namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            label:
            long n = long.Parse(ReadLine());
            long result = 0;
            for (int a = (int)Math.Sqrt(n); 1 <= a; --a)
            {
                var m = (n - a) / a;
                if (a < m && m * a + a == n)
                {
                    result += m;
                }
            }
            WriteLine(result);
            //goto label;
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main{
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    int a= scan.nextInt();
    int b= scan.nextInt();
    int c= scan.nextInt();
    int divisor = 0;
    for (int i = a; i <= b; i++) {
      if (c%i == 0) {
        divisor++;
      }
    }
    System.out.println(divisor);
  }
}


Measured memory_bytes: 26056
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut money: u64 = 1000;
    let mut stock: u64 = 0;
    let mut i: usize = 0;
    while i < n - 1 {
        if a[i] < a[i + 1] {
            stock += money / a[i];
            money -= money / a[i] * a[i];
        } else if a[i] > a[i + 1] {
            money += stock * a[i];
            stock = 0;
        }
        i += 1;
    }
    println!("{}", money + stock * a[i]);
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for(ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")



ll power(ll b,ll e,ll m)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(b==0) return 0;
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
}

int check(string str) 
{ 
    // Compute sum of digits 
    int n = str.length(); 
    int digitSum = 0; 
    for (int i=0; i<n; i++) 
        digitSum += (str[i]-'0'); 
  
    // Check if sum of digits is divisible by 9. 
    return (digitSum % 9 == 0); 
}

void solve()
{
  string s;
  cin>>s;
  if(check(s)) cout<<"Yes";
  else cout<<"No";
}

int main()
{
  fastio
  ll tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
}

Measured memory_bytes: 3784
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M, a;
cin >> N >> M;
vector<int> town(N, 0); 
for (int i = 0; i < M * 2; ++i) {
        cin >> a;
        --a;
        town[a] += 1;  
}
for (int i = 0; i < N; ++i) cout << town[i] << endl; 
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
class problem
{
    static void Main()
    {
        var v = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        int a = v[0], p = v[1];
        Console.WriteLine( ( 3 * v[0] + v[1] ) / 2 );

    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long n,m,x[200005],fa[200005],l,r,d;
int find(int now)
{
	if(now == fa[now]) return now;
	int ret=find(fa[now]);
	x[now]+=x[fa[now]];
	return fa[now]=ret;
}
int main()
{
	cin >> n >> m;
	for(int i=1; i<=n; i++) fa[i]=i;
	int l,r,d;
	for(int i=1; i<=m; i++)
	{
		cin >> l >> r >> d;
		if(find(l) != find(r))
		{
			int k=find(r);
			fa[k] = r; x[k] = -x[r];
			fa[r] = l; x[r] = d;
		}
		else
		{
			find(l); find(r);
			if(x[r] != x[l]+d)
			{
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 5172
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  lines.shift();
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
    //   [arr[i], arr[largest]] = [arr[largest], arr[i]];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 140160
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[i] < L[j] < L[k] and L[i] + L[j] > L[k]:
                ans += 1
print(ans)


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  string S;
  cin >> S;
  S.erase(unique(begin(S), end(S)), end(S));
  cout << S.size() - 1 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
    int R[MAX], n;
    
    cin >> n;
    for (int i = 0; i < n; i++ )
        cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for (int i = 1; i < n; i++ ) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int v, e; cin >> v >> e;
    Graph G(v);
    vector<int> indegree(v);
    for(int i = 0; i < e; i++){
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        indegree[b]++;
    }
    queue<int> que;
    for(int i = 0; i < v; i++){
        if(indegree[i] == 0) que.push(i);
    }
    while(!que.empty()){
        int now = que.front();
        que.pop();
        for(int nv: G[now]){
            if(--indegree[nv] == 0) que.push(nv);
        }
        G[now].clear();
        cout << now << endl;
    }
}


Measured memory_bytes: 3672
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll n,m;
    cin >> n >> m;
    ll a, b;
    vvll jobs(1e5+2);

    REP(i, n){
        cin >> a >> b;
        jobs[a].push_back(b);
    }

    priority_queue<ll> pq;

    ll ans = 0;
    REP(i, m){
        for(auto j : jobs[i+1]){
            pq.push(j);
        }
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
    }

    cout << ans << endl;
}

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

int main() {
  int d; cin >> d;
  int n = 26;
  vector<int> c(n), t(d);
  vector<vector<int>> s(d, vector<int>(n));
  int sumc = 0;
  rep(i,n) {
    cin >> c[i];
    sumc+=c[i];
  }
  int m = sumc / n;
  rep(i,d) {
    rep(j,n) {
      cin >> s[i][j];
    }
  }
  rep(i,d) {
    int d = 0;
    rep(j,n) {
      if (c[j] < m) {
        if (d < s[i][j]) {
          t[i] = j+1;
          d = s[i][j];
        }
      }
    }
  }
  for (auto ti : t) {
    cout << ti << endl;
  }
}

Measured memory_bytes: 3676
N = int(input())
H =[int(i)for i in input().split()]
ans = 0
now_height = 0
n = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        n += 1
    else:
        if ans < n:
            ans = n
        n = 0
print(max(ans,n))

Measured memory_bytes: 14252
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

int main()
{
	int a,b,c,x,y;
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
	int f=std::min(x,y),ans=0;
	if (c*2<=a+b) ans+=f*c*2,x-=f,y-=f;
	ans+=x*std::min(a,c*2)+y*std::min(b,c*2);
	printf("%d",ans);
	return 0;
}

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

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

typedef long long ll;

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

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);

  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];

  int ret = 0;

  rep(i, n){
    ret += b[a[i]-1];

    if(i != n-1){
      if(a[i] + 1 == a[i+1]){
        ret += c[a[i]-1];
      }
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

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

    string t; cin>>t;

    string ans;
    for(auto i : t){
        if(i == '?') ans += 'D';
        else ans += i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3900
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main()
{
  std::string A;
  std::cin >> A;
  
  std::vector<unsigned> z('z' - 'a' + 1, 0);
  for (unsigned i = 0; i < A.size(); ++i) {
    ++z[A[i] - 'a'];
  }
  
  ulli s = 0;
  for (unsigned i = 'a'; i <= 'z'; ++i) {
    ulli x = z[i - 'a'];
    s += (x * (x - 1)) >> 1;
  }
  
  ulli m = A.size(), n = (m * (m - 1)) >> 1;
  
  std::cout << (n - s + 1) << std::endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B;
  cin>>A>>B;
  if(A<=8 && B<=8) cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define maxn 200100
using namespace std;
vector <int> indices[130];
string s;
map <int, int> mymap;
map <int, int> bestchar;
int dp(int index){
	if(mymap.count(index))
		return mymap[index];
	int best_size = INT_MAX;
	// cout<<"exploring "<<index<<" "<<s[index]<<endl;
	for (int ch = 'a'; ch <= 'z'; ++ch)
	{
		vector<int>::iterator next = upper_bound(indices[ch].begin(), indices[ch].end(), index);
		if(next == indices[ch].end()){
			bestchar[index] = -ch;
			return 1;
		}
	}
	for (int ch = 'a'; ch <= 'z'; ++ch)
	{
		vector<int>::iterator next = upper_bound(indices[ch].begin(), indices[ch].end(), index);
		if(next == indices[ch].end()){
			// bestchar[index] = -1;
			bestchar[index] = -ch;
			return 1;
		}
		// cout<<"going in "<<*next<<" "<<s[*next]<<endl;
		int curr_size = dp(*next) + 1;
		if(curr_size < best_size)
			bestchar[index] = *next;
		best_size = min(best_size, curr_size);
	}
	mymap[index] = best_size;
	return best_size;
}
int main(int argc, char const *argv[])
{
	cin>>s;
	for (int i = 0; i < s.size(); ++i)
		indices[s[i]].push_back(i);
	int best_size = INT_MAX;
	char charr = -1;
	for (char ch = 'a'; ch <= 'z'; ++ch){
		if(indices[ch].size() != 0){
			int size2 = dp(indices[ch][0]) + 1;
			if(size2 < best_size)
				charr = ch;
			best_size = min(best_size, size2);
		}
		else
		{
			cout<<ch<<endl; return 0;
		}
	}
	// cout<<best_size<<endl;
	int best_index = bestchar[indices[charr][0]];
	cout<<charr;
	
	while(best_index > 0){
		cout<<s[best_index];
		best_index = bestchar[best_index];
	}
	cout<<(char)(-best_index);
	cout<<endl;
	return 0;
}

Measured memory_bytes: 20868
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int n,p; //cin >>n >>p;
  string s; cin >>s; n=s.size(); p=2019;
  if(p==2 or p==5){
    li cnt=0;
    rep(i,n){
      if((s[i]-'0')%p==0) cnt+=i+1;
    }
    print(cnt);
    return 0;
  }
  reverse(s.begin(),s.end());
  
  vector<int> rem(n);
  int r10=1,r=0;
  rep(i,n){
    r+=(s[i]-'0')*r10;
    rem[i]=r%=p;
    (r10*=10)%=p;
  }
  if(df)  print(rem);
  vector<li> memo(p,0);
  li cnt=0;
  rep(i,n){
    cnt+=memo[rem[i]]++;
  }
  print(cnt+memo[0]);
}


Measured memory_bytes: 4372
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

size_t N;
vector<ll> a;
ll mindiff = 0;

int main()
{
    cin >> N;
    a.resize(N);

    ll x = 0, y = 0;

    for (size_t i = 0; i < N; i++) {
        cin >> a[i];
        if (i == 0) {
            x = a[i];
        } else {
            y += a[i];
        }
    }

    ll mindiff = abs(x - y);

    for (size_t i = 1; i < N - 1; i++) {
        x += a[i];
        y -= a[i];
        mindiff = min(mindiff, abs(x - y));
    }

    cout << mindiff << endl;
    return 0;
}

Measured memory_bytes: 1920
/*
Original problem: https://atcoder.jp/contests/abc135/tasks/abc135_a
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)

#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9+7;

namespace SOLVE {
    void main() {
        int a, b;
		cin >> a >> b;
		int d = abs(a+b);
		if (d % 2 == 1) {
			cout << "IMPOSSIBLE" << endl;
		} else {
			cout << d / 2 << endl;
		}
    }
}


signed main() {
	int t;
	t = 1;
	// cin >> t;
	while (t--) {
		SOLVE::main();
	}

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

#import sys

#def input():
#    return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort()
price = [a[i][0] for i in range(N)]
stock = [a[i][1] for i in range(N)]
bought = 0
total_price = 0

for i in range(N):
    if bought + stock[i] <= M:
        total_price += price[i] * stock[i]
        bought += stock[i]
    else:
        total_price += price[i] * (M - bought)
        break
print(total_price)

Measured memory_bytes: 29284
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int x=sc.nextInt();
        int a[]=new int[n];
        int mem[][]=new int[n][n];

        for(int i=0; i<n; i++) {
            a[i]=sc.nextInt();
        }

        long d=0;
        long ans=0;

        for(int i=0; i<n; i++) {
            mem[0][i]=a[i];
            for(int t=1,w; t<n; t++) {
                w= i-t <0 ? i-t+n : i-t;
                mem[t][i] = min(mem[t-1][i], a[w]);
            }
        }

        ans = 1L<<62;
        for(int i=0; i<n; i++) {
            long s=(long)x*i;
            for(int t=0; t<n; t++) {
                s+=mem[i][t];
            }
            ans=min(ans,s);
        }
   
        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 54228
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int N = s.length();
		for(int i = 0 ; i < N ; i++) {
			if(i % 2 == 0) {
				System.out.print(s.charAt(i));
			}
		}
		System.out.println();
	}
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if(a<=c){
        if(b<=c)
            cout << 0 << endl;
        else if(d>=b)
            cout << b-c << endl;
        else
            cout << d-c << endl;
    }
    else if(c<a){
        if(d<=a)
            cout << 0 << endl;
        else if(b>=d)
            cout << d-a << endl;
        else
            cout << b-a << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
char number[1001]={0};
int i,sum=0;


while(1){
	sum=0;
	scanf("%s",&number);
	if(number[0]== '0' ) break;
	
	for(i=0;number[i]!='\0';i++){
			sum=sum+(number[i]-'0');
	}
	printf("%d\n",sum);
}
return 0;

}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int expo(int base,int exponent,int mod){
    int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
int n,a[1000006],m,sum[1000006],sqsum[1000006],ans[1000006],res;
void solve(){
    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        a[x]++;
        m=max(m,x);
    }
    rep(i,1,m+1){
        for(int j=i;j<=m;j+=i){
            sum[i]=(sum[i]+a[j]*j)%hell;
            sqsum[i]=(sqsum[i]+a[j]*j*j)%hell;
        }
    }
    for(int i=m;i>=1;i--){
        ans[i]=(sum[i]*sum[i]%hell-sqsum[i]+hell)%hell*(hell+1)/2%hell;
        for(int j=2*i;j<=m;j+=i){
            ans[i]=(ans[i]-ans[j]+hell)%hell;
        }
        res=(res+ans[i]*expo(i,hell-2,hell))%hell;
    }
    cout<<res<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
  int i=0;
  string s,t[7]={"SAT","FRI","THU","WED","TUE","MON","SUN"};
  cin >> s;
  while (s!=t[i]) i++;
  cout << i+1 << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
ans = 0

if S[0] == 'A':
    ans += 1

cnt = 0
for i in range(2, len(S)-1):
    if S[i] == 'C':
        cnt += 1
if cnt == 1:
    ans += 1

cnt = 0
for i in range(len(S)):
    if S[i].isupper():
        cnt += 1
if cnt == 2:
    ans += 1

if ans == 3:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 9040
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;

int main() {
    ll n; cin >> n;
    ll s = ll(sqrt(n));
    if (s*s<n) {
        s++;
    }
    for (ll i = s; i>0; i--) {
        if (n%i==0) {
            ll q = n/i;
            ll ans = 0;
            while (q) {
                q/=10;
                ans++;
            }
            cout << ans << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256