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

using namespace std;

int main()
{
  double x, h;
  while(cin >> x >> h, x || h){
    printf("%.6f\n", (double)x*x + 2.0 * sqrt(h*h + x*x/4) * x);
  }
  return 0;
}

Measured memory_bytes: 1236
use std::io::{self, Read};
use std::str::FromStr;
use std::cmp;
use std::i64;
pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

pub struct SegmentTree {
    l: usize,
    vals: Vec<i64>,
}
impl SegmentTree {
    pub fn new(vals: Vec<i64>) -> SegmentTree {
        let n = vals.len();
        let mut l = 1;
        while l < n {
            l *= 2;
        }
        let mut st = SegmentTree {
            l: l,
            vals: vec![i64::MAX; 2 * l - 1],
        };
        for i in 0..n {
            st.vals[i + l - 1] = vals[i];
        }
        for i in (0..l - 1).rev() {
            st.vals[i] = cmp::min(st.vals[i * 2 + 1], st.vals[i * 2 + 2]);
        }
        st
    }
    pub fn update(&mut self, i: usize, val: i64) {
        let mut id = i + self.l - 1;
        self.vals[id] = val;
        while id > 0 {
            id = (id - 1) / 2;
            let lid = id * 2 + 1;
            let rid = lid + 1;
            self.vals[id] = cmp::min(self.vals[lid], self.vals[rid]);
        }
    }
    pub fn find(&self, i: usize, j: usize) -> i64 {
        self.query(i, j, 0, 0, self.l)
    }
    fn query(&self, i: usize, j: usize, k: usize, l: usize, r: usize) -> i64 {
        if k >= self.vals.len() || j <= l || r <= i {
            i64::MAX
        } else if i <= l && r <= j {
            self.vals[k]
        } else {
            let vl = self.query(i, j, k * 2 + 1, l, (r + l) / 2);
            let vr = self.query(i, j, k * 2 + 2, (r + l) / 2, r);
            cmp::min(vl, vr)
        }
    }
}

/// Segtree版。O(qlogn)
fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let n: usize = sc.read();
    let q: usize = sc.read();

    let a: Vec<i64> = vec![2i64.pow(31) - 1; n];
    let mut st = SegmentTree::new(a);

    for _ in 0..q { // O(q)
        let com: u32 = sc.read();
        let i: usize = sc.read();

        match com {
            0 => {  // update: O(logn)
                let v: i64 = sc.read();
                st.update(i, v);
            }, 
            1 => {  // find: O(logn)
                let j: usize = sc.read();
                let min = st.find(i,j+1);   // セグ木は[i,j)実装なので、[i,j]→[i,j+1)に変更
                println!("{}", min);
            },
            _ => { panic!("irregular command"); },
        }
    }
}



Measured memory_bytes: 6964
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll w[105],v[105],n,k,dp[105][100100];
ll rec(ll i,ll sum)
{
    if(i==n-1)
        {
            if(sum+w[i]<=k)
                return v[i];
            return 0;
        }
    if(dp[i][sum]!=-1)
        return dp[i][sum];
    ll c1=rec(i+1,sum),c2=0;
    if(sum+w[i]<=k)
        c2=rec(i+1,sum+w[i])+v[i];
    return dp[i][sum]=max(c1,c2);
}
int main()
{
    cin>>n>>k;
    for(ll i=0 ; i <n ; i++)
        cin>>w[i]>>v[i];
    memset(dp,-1,sizeof dp);
    cout<<rec(0,0);
    return 0;
}


Measured memory_bytes: 82432
import sys
readline = sys.stdin.readline

S = readline().rstrip()

right = 0
ans = 0
for left in range(len(S)):
  while right + 1 < len(S) and S[right] in "ACGT":
    right += 1
    
  if right + 1 == len(S):
    if S[right] in "ACGT" and ans < right - left + 1:
      ans = right - left + 1
      break
  
  if ans < right - left:
    ans = right - left
    
  if right == left:
    right += 1
    
print(ans)

Measured memory_bytes: 9068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			int N = vs[0];
			int M = vs[1];

			int[][] shops = new int[N][];
			for (int i = 0; i < N; i++) {
				shops[i] = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			}

			long ans = 0;
			int count = 0;
			foreach (var shop in shops.OrderBy(p => p[0])) {
				int i = Math.Min(M - count, shop[1]);
				ans += (long)shop[0] * i;
				count += i;
				if (count >= M) {
					break;
				}
			}
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 23612
#include<stdio.h>
int main(){
    int dish[5];
    int fin_dish;
    int dish_num;
    int sum=0;
    int tmp=9;
    for(int i=0;i<5;i++){
        scanf("%d",&dish[i]);
        if((dish[i]%10)<=(tmp%10)&&0<(dish[i]%10)){
            tmp=dish[i];
            dish_num=i;
        }
    }
    fin_dish=tmp;
    for(int l=0;l<5;l++){
        if(l==dish_num){
            sum=sum+fin_dish;
        }else{
            if((dish[l]%10)==0){
                sum=sum+dish[l];
            }else{
                sum=sum+(dish[l]-(dish[l]%10)+10);
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
/*inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}*/
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
ll A,B,C,D;
int main() {
	int T = rd();
	while (T--) {
		A=rd(),B=rd(),C=rd(),D=rd();
		if(A<B||D<B) puts("No");
		else if(C>=B-1) puts("Yes");
		else{
			A%=B;
			ll d=__gcd(D,B);
			if(d==B){
				if(A>=C+1) puts("No");
				else puts("Yes");			
			}
			else{
				if(A>=C+1) puts("No");
				else{
					ll c=C-A;
					c=c/d+1;
					if((c*d%B+A)%B>=C+1) puts("No");
					else puts("Yes");
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    vector<ll>s;//訪れた頂点
    vector<ll>ord(n+1,-1);//数字を入れる
    ll c=1;//周期
    ll l=0;//例外部分の長さ
    {
        ll v = 1;
        while(ord[v] == -1){
            ord[v]=s.size();
            s.push_back(v);
            v=a[v-1];
        }
        c=s.size() - ord[v];
        l=ord[v];
    }

    if(k<l) cout << s[k] << endl;
    else {
        k-=l;
        k%=c;
        cout << s[l+k] << endl;
    }
}


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

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

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


Measured memory_bytes: 4840
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<string, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, ans, cnt, sum, a[310000], b[210000];
string str;
bool f;
char c[1100][1100];

int main() {
	cin >> m >> k;
	if ((1LL << m) <= k) {
		cout << -1 << endl;
		return 0;
	}
	if (k == 0) {
		rep(i, 1LL << (m + 1)) {
			if (i)cout << " ";
			cout << i / 2;
		}
		cout << endl;
		return 0;
	}
	rep(i, 1LL << m) {
		if (i != k) {
			a[cnt] = i;
			cnt++;
		}
	}
	a[cnt] = k;
	cnt++;
	rep(i, 1LL << m) {
		if (k != (1LL << m) - i - 1) {
			a[cnt] = (1LL<<m)-i-1;
			cnt++;
		}
	}
	a[cnt] = k;
	cnt++;
	rep(i, 1LL << m) {
		p ^= i;
	}
	if (p != 0) {
		cout << -1 << endl;
		return 0;
	}
	rep(i, cnt) {
		if (i)cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<stack>
#include<limits.h>
using namespace std;

signed main() {
	string a; cin >> a;
	for (int i = 0; i < a.length() - 1; i++) {
		if (a[i] == 'A'&&a[i + 1] == 'C') { puts("Yes"); return 0; }
	}
	puts("No");
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

constexpr int MOD = 1000000007;
ll modpow(ll n, ll r, ll mod) {
    if(r == 0) return 1;
    if(n == 0) return 0;
    if(r % 2 == 0) {
        ll tmp = modpow(n, r / 2, mod);
        return tmp * tmp % mod;
    }
    else {
        return n * modpow(n, r - 1, mod) % mod;
    }
}

int main(){
    int P, Q, R;
    read(P, Q, R);
    int sum = P + Q + R;
    int ans = sum - P;
    ans = min(ans, sum - Q);
    ans = min(ans, sum - R);
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<int> s(n + 1, 0);
    for (int i = 0; i < n; i++) s[i + 1] = s[i] + p[i] + 1;
    int ans = 0;
    for (int i = 0; i + k <= n; i++) {
        ans = max(ans, s[i + k] - s[i]);
    }
    cout << fixed << setprecision(10) << ans / 2.0 << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x_n = new int[n];
		for (int i = 0; i < n; i++) {
			x_n[i] = sc.nextInt();
		}
		sc.close();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int aDistance = Math.abs(0 - x_n[i]) * 2;
			int bDistance = Math.abs(x_n[i] - k) * 2;
			ans += Math.min(aDistance, bDistance);
		}
		System.out.println(ans);
	}

}


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

using namespace std;

#define ll long long int

#define SAY_YES cout << "Yes" << endl
#define SAY_NO cout << "No" << endl
#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)

#define vec vector

int main() {
  int N;
  cin >> N;
  bool ans = true;
  rep(i, N) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 && a % 5) {
        ans = false;
      }
    }
  }
  if (ans) {
    say("APPROVED");
  }else {
    say("DENIED");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int countbits(long long bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];

    LL x = 0;
    REP(i,2,n) x ^= a[i];

    LL l = 0, r = 0;
    dump(x);
    REP(i,0,60) {
        if (x & (1LL<<i)) {
            r += (1LL<< i);
        }
    }
    LL cur = l + r;
    LL rem = a[0] + a[1] - cur;

    if (rem < 0) {
        cout << -1 << endl;
        return;
    }
    RREP(i,0,60) {
        if ((1LL<<i)*2 <= rem) {
            l += (1LL<<i);
            r += (1LL<<i);
            rem -= (1LL<<i)*2;
        }
    }

    RREP(i,0,60) {
        if (l & (1LL<<i)) continue;
        if (r & (1LL<<i)) {
            if (l + (1LL<<i) <= a[0]) {
                l += (1LL<<i);
                r -= (1LL<<i);
            }   
        }        
    }

    if (l + r != a[0] + a[1] || l > a[0] || r < a[1] || l == 0 || (l ^ r) != x) {
        cout << -1 << endl;
        return;
    }
    cout << a[0] - l << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	ll n;
	cin >> n;
	for(ll h = 1;h <= 3500;h++) {
		for(ll w = 1;w <= 3500;w++) {
			if(4*h*w > (n*w + n*h) && (n*h*w)%(4*h*w-(n*w+n*h)) == 0) {
				cout << h << " " << w << " " << (n*h*w)/(4*h*w-(n*w+n*h)) << endl;
				return 0;
			}
		}
	}
}



Measured memory_bytes: 384
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            double[] p = new double[n];
            for (int i = 0; i < n; i++) p[i] = inp.nextDouble();

            // probability of having i heads
            double[] dp = new double[n+1];
            dp[0] = 1;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j > 0; j--) {
                    dp[j] = dp[j] * (1 - p[i]) + dp[j-1] * p[i];
                }
                dp[0] = dp[0] * (1 - p[i]);
            }
            double res = 0;
            for (int i = n / 2 + 1; i <= n; i++) res += dp[i];
            out.print(res);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 25044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int n, q;
int a[100100], m[100100];
set<int> si;

int main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(j, (1 << n)) {
		int s = 0;
		rep(k, n) {
			if (j&(1 << k))s += a[k];
		}
		si.insert(s);
	}
	cin >> q;
	rep(i, q) {
		cin >> m[i];
		if (si.find(m[i]) != si.end())cout << "yes" << endl;
		else cout << "no" << endl;
	}
}

Measured memory_bytes: 3124
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
        int N= scan.nextInt();
        long A[]=new long[N+1];
        long MAX=0;
    for(int i=0;i<=N;i++){A[i]=scan.nextLong();
    MAX=MAX+A[i];}
    long NE=1;
    long P=0;
if(MAX==0){NE=-1;}
    for(int i2=0;i2<=N&&NE>=0;i2++){P=P+NE;
   NE=NE-A[i2];
MAX=MAX-A[i2];
        NE=NE*2;
        if(NE>MAX){NE=MAX;}

    }
    if(NE<0){P=-1;}
    System.out.println(P);
    }
}


Measured memory_bytes: 49756
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int X,Y,Z;
  cin >> X >> Y >> Z;
  swap(X,Y);
  swap(X,Z);
  cout << X << " " << Y << " " << Z << endl;
  return 0;
}

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

#define int long long

using namespace std;

signed main() {
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    vector<int> h(n), dp(n, INT_MAX);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = i - 1; j >= max(i - k, (long long) 0); j--){
            dp[i] = min (dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 4840
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        c += (sum((a-b)**2 for a,b in zip(x[i],x[j]))**0.5).is_integer()

print(c)


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <array>

const int kSize = 20 + 2;

std::array<int, 4> ways = {-1, -kSize, +1, +kSize};

inline int xy2pos(const int x, const int y){
    return x + y * kSize;
}

std::array<bool, kSize*kSize> Bfs(const std::array<bool, kSize*kSize> &tiles, int pos){
    std::array<bool, kSize*kSize> arrived;
    std::queue<int> q;
    q.push(pos);
    std::fill(arrived.begin(), arrived.end(), false);
    while(!q.empty()){
        pos = q.front();
        q.pop();
        arrived[pos] = true;
        for(int way : ways)
            if(tiles.at(pos + way) && !arrived.at(pos + way))
                q.push(pos + way);
    }
    return arrived;
}

int main(){
    int w,h;
    std::array<bool,kSize*kSize> tiles; ///< true if black
    while((std::cin >> w >> h) && w != 0){
        std::fill(tiles.begin(), tiles.end(), false);
        int pos;
        for(int y=1; y<=h; ++y){
            for(int x=1; x<=w; ++x){
                char c;
                std::cin >> c;
                tiles[xy2pos(x,y)] = (c == '.');
                if(c == '@'){
                    pos = xy2pos(x,y);
                    tiles[pos] = true;
                }
            }
        }
        auto arrived = Bfs(tiles, pos);
        int sum = 0;
        for(bool v : arrived)
            sum += (v) ? 1 : 0;
        std::cout << sum << std::endl;
    }
}


Measured memory_bytes: 4628
#include <stdio.h>

int main(void) {
	int x,k, a[10000] = {0};
	int max = -1000001, min = 1000001;
	long sum = 0;
	scanf("%d", &k);
	
	for(x=0;x<k;x++){
		scanf("%d",&a[x]);
		if(a[x]>max) max=a[x];
		if(a[x]<min) min=a[x];
		sum+=a[x];
	}
	
	printf("%d %d %ld\n", min, max, sum);
	
	
	return 0;
}

Measured memory_bytes: 648
#include   <bits/stdc++.h>
#include   <stdlib.h>
#include   <stdio.h>
#define    pb push_back
#define    mp make_pair
#define    ii   int
#define    ll  long long
#define    pii  pair<ii,ii>
#define    pll  pair<ll,ll>
#define    vcii   vector<ii>
#define    vcll   vector<ll>
#define    vcd     vector<double>
#define    vpii   vector<pair>
#define    scll(x)  scanf("%lld",x)
#define    pfll(x) printf("%lld\n",x)
#define    scd(x) scanf("%llf",x)
#define    pfd(x) prinf("%0.5llf\n",x)
#define pie acos(-1)

using namespace std;
ll Bigmod(ll a,ll b,ll m);
vector<ii> sieve(int n);
void divisor(int n);
void coprime(ll n);
ll gcd(ll a,ll b);
int p[10000],m[1000];

int main()
{

    ll n,a,b,m,sum=0,i;
    cin>>n>>m;
    vcll month;
    for(i=0;i<m;i++)
    {
        cin>>a;
        month.pb(a);
        sum+=a;

    }
   if(sum>n)cout<<-1<<endl;
   else
    cout<<(n-sum)<<endl;
    return 0;
}


/*void divisor(int n)
{
      vcii divi[n+1];

      for(int i=1;i<=n;i++)
      {
        for(int j=i;j<=n;j+=i)
        {
          divi[j].pb(i);
        }
      }
    for(int i=1;i<=n;i++)
    {
       for(int j=0;j<divi[i].size();j++)
       {
         cout<<divi[i][j]<<" ";
       }
       cout<<endl;
    }
}
*/

/*vector<ii> sieve(int n)
{
    vci prime;
    map<int,bool>mm;
    int i,j;
    for(i=4; i<=n; i+=2)
        mm[i]=true;
    prime.pb(2);
    for(i=3; i<=n; i+=2)
    {
        if(!mm[i])
        {
            prime.pb(i);

            if(i<=sqrt(n)+2)
            {
                for(j=i*i; j<=n; j+=(i*2))

                {
                    mm[j]=true;

                }
            }
        }
    }
    return prime;
}*/
/*
ll gcd(ll a ,ll b)
{
    if(a==0) return b;

    return gcd(b%a,a);


}
*/
/*

void coprime(ll n)
{
    ll i,j;

    ll p[n+1];
    map<ll,bool>m;
    for(i=1;i<=n;i++)p[i]=i;
    for(i=2;i<=n;i+=2)
    {
        if(i!=2)
        {
            m[i]=1;

        }
        p[i]=p[i]/2;
    }
    p[1]=1;
    m[1]=1;
    for(i=3;i<=n;i+=2)
    {
        if(!m[i])
        {
            p[i]=p[i]-1;
            for(j=i*2;j<=n;j+=i)
            {
                m[j]=1;
                p[j]=p[j]/i*(i-1);
            }

        }
    }

    for(i=1;i<=n;i++)
    {
        cout<<p[i]<<"\n";
    }



}

*/
/*
ll Bigmod(ll a,ll b,ll m)
{
    if(b==0) return 1%m;

    ll x=Bigmod(a,b/2,m);
    x=(x*x)%m;

    if(b%2==1)  x=(x*a)%m;

    return x;
}

*/


Measured memory_bytes: 3732
#include<iostream>
#include<string>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::string S; std::cin >> S;
  if(S == "Sunny") fin("Cloudy");
  if(S == "Cloudy") fin("Rainy");
  if(S == "Rainy") fin("Sunny");
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = input()
    A = A.split(' ')

    for i in A:
        if i == '0':
            print(0)
            return

    X = 1
    for i in A:
        X *= int(i)
        if X > 1000000000000000000:
            print(-1)
            return
    print(X)
main()

Measured memory_bytes: 19356
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		OriginScanner os = new OriginScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int n = os.nextInt();
		String s = os.next();
		
		int count = 0;
		while (s.contains("ABC")) {
			s = s.replaceFirst("ABC", "");
			count++;
		}
		pw.println(count);
		pw.close();
	}
	
	static class OriginScanner {
		private BufferedReader br;
		private StringTokenizer st;
		
		public OriginScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String nextLine() {
			String str = null;
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				System.out.println(e);
			}
			return str;
		}
		String next() {
			if (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int t[101];
int main(){
    int sum,n;cin>>sum>>n;
    for(int i=0;i<n;i++){
        cin>>t[i];
    }
    sort(t,t+n);
    int ans=t[n-1];
    for(int i=n-2;i>=0;i--){
        if(ans>=t[i])ans-=t[i];
        else ans=t[i]-ans;
    }
    if(ans!=0)ans--;
    cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
000010 IDENTIFICATION                   DIVISION.
000020 PROGRAM-ID.                      ABC-147-A.
000030 AUTHOR.                          CUNITAC.
000040 DATE-WRITTEN.                    2019/12/13.
000060*
000070 ENVIRONMENT                      DIVISION.
000075*
000080 DATA                             DIVISION.
000090 WORKING-STORAGE                  SECTION.
000100 01 S   PIC 99 VALUE 0.
000110 01 A   PIC 99.
000120 01 INP PIC X(9).
000125 01 P1  PIC 9 VALUE 1.
000128 01 P2  PIC 9. 
000130*
000140 PROCEDURE                        DIVISION.
000150 MAIN.
000160  ACCEPT INP.
000170  PERFORM 3 TIMES
000180   PERFORM VARYING P2 FROM 1 BY 1
000190       UNTIL INP(P1 + P2:1) = SPACE
000200   END-PERFORM
000210   MOVE INP(P1:P2) TO A
000215   ADD P2+1 TO P1
000220   ADD A TO S
000230  END-PERFORM.
000240  IF S >= 22 THEN
000250   DISPLAY "bust"
000260  ELSE
000270   DISPLAY "win"
000280  END-IF.
000250  STOP RUN.

Measured memory_bytes: 384
#include <stdio.h>
int main(void){
	int a[10],b[10],d[10],e[10],c,i,cnt=0;
	for(i=1;i<=6;i++){
		scanf("%d",&b[i]);
		a[i] = b[i];}
	for(i=1;i<=6;i++){
		scanf("%d",&e[i]);
		d[i] = e[i];}
	for(i=1;i<=5;i++){
		if(a[i]>a[i+1]){
			c = a[i+1];
			a[i+1] = a[i];
			a[i] = c;}
		if(d[i]>d[i+1]){
			c = d[i+1];
			d[i+1] = d[i];
			d[i] = c;}}
	for(i=1;i<=6;i++){
		if(a[i] == d[i])
			cnt++;}
	if((cnt==6) && (a[1]==a[2]) && (a[2]==a[3]) && (a[3]==a[4]) && (a[4]==a[5])){
		printf("Yes\n");
		return 0;}
	for(i=0;i<4;i++){	/*tate idou*/
		if(b[1] == e[1])
			break;
		c = b[1];
		b[1] = b[2];
		b[2] = b[6];
		b[6] = b[5];
		b[5] = c;}
	for(i=0;i<4;i++){	/*tate(1ga yokoniarutoki) idou*/
		if(b[1] == e[1])
			break;
		c = b[1];
		b[1] = b[3];
		b[3] = b[6];
		b[6] = b[4];
		b[4] = c;}
	for(i=0;i<4;i++){	/*yoko idou*/
		if(b[2] == e[2])
			break;
		c = b[2];
		b[2] = b[3];
		b[3] = b[5];
		b[5] = b[4];
		b[4] = c;}
	for(i=2;i<=6;i++){
		if(b[i] != e[i]){
			printf("No\n");
			return 0;}}
	printf("Yes\n");	
	return 0;
}			
	

Measured memory_bytes: 580
#include<iostream>
#include<cstdio>
#include<map>
#define ll long long int
using namespace std;
ll a,b;
string aa[110],bb;
map<string,int> mp;
int main() {
	int i,j;
	cin>>a;
	for(i=0; i<a; i++) {
		cin>>aa[i];
		mp[aa[i]]++;
	}
	cin>>b;
	for(i=0; i<b; i++) {
		cin>>bb;
		mp[bb]--;
	}
	int m=0;
	for(i=0; i<a; i++) {
		m=max(m,mp[aa[i]]);
	}
	cout<<m;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s; int n=s.size();
	ll k; cin>>k;
	rep(i,n){
		int cost = (26-(s[i]-'a'))%26;
		if(cost<=k) s[i]='a', k-=cost;
	}
	s[n-1] = 'a'+(s[n-1]-'a'+k)%26;
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 592
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		char s[] = sc.next().toCharArray();
		int ans = 0;
		ArrayDeque<Character> st = new ArrayDeque<Character>();
		st.push(s[0]);
		for(int i=1; i<s.length; i++) {
			if(st.isEmpty() || s[i] == st.getFirst()) {
				st.push(s[i]);
			}else {
				st.pop();
				ans++;
			}
		}
		System.out.println(ans*2);
		sc.close();
	}

}


Measured memory_bytes: 29652
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000009;

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

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

	int cnt = 1;
	int now = 1;
	for(int i = 0;i < n-1;i++){
		if(b[i] < b[i+1])now++;
		else{
			cnt = max(cnt,now);
			now = 1;
		}
	}

	cnt = max(now,cnt);

	cout << n - cnt << endl;
}


Measured memory_bytes: 1920
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}



enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N, M, Q;
    scan(N, M, Q);
    auto lr = new int[][](N, N);
    foreach (i ; 0 .. M) {
        int li, ri;
        scan(li, ri);
        li--, ri--;
        lr[li][ri]++;
    }
    auto cu = new int[][](N + 1, N + 1);
    foreach (i ; 1 .. N + 1) {
        foreach (j ; 1 .. N + 1) {
            cu[i][j] += cu[i-1][j] + cu[i][j-1] - cu[i-1][j-1] + lr[i-1][j-1];
        }
    }

    foreach (_ ; 0 .. Q) {
        int pi, qi;
        scan(pi, qi);
        auto ans = cu[N][qi] - cu[pi - 1][qi];
        writeln(ans);
    }
}


Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const int INF = INT_MAX;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

int used[200010];

int main(){
	ll N, K; cin >> N >> K;
	int A[N];
	rep(i, N){
		cin >> A[i];
		A[i]--;
	}
	rep(i, N) used[i] = -1;
	int cnt = 0, now = 0, p;
	used[0] = 0;
	vector<int> his;
	his.pb(0);
	while(1){
		cnt++;
		if(used[A[now]] == -1){
			used[A[now]] = cnt;
			now = A[now];
			his.pb(now);
		}else{
			p = cnt - used[A[now]];
			break;
		}
	}
	if(cnt - p >= K){
		cout << his[K]+1 << endl;
	}else{
		K -= (cnt - p);
		ll pp = K % p, aa = A[cnt-p];
		cout << his[cnt-p+pp]+1 << endl;
	}
	return 0;
}


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

int main(){
   int a,b;
   cin >> a >> b;
   int ans=0;
   int i=0;
   int a2;
   int j;
   int t;
      while (a+i<=b) {
         a2=a+i;
         j=0;
         t=0;
         while (a2){
            t+=pow(10,4-j)*(a2%10);
            a2/=10;
            j++;
         }
         if (a+i==t) ans++;
         i++;
      }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,a,b;
	char s[12];
	scanf("%d%d%s",&a,&b,s);
	if(s[a]!='-'){
		printf("No");
		return 0;
	}
	for(i=0;i<a;i++){
		if(s[i]<'0' || s[i] >'9'){
		printf("No");
		return 0;
		}
	}
	for(i=a+1;i<a+b+1;i++){
		if(s[i]<'0' || s[i] >'9'){
		printf("No");
		return 0;
		}
	}
	printf("Yes");
	return 0;
}	
			

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define debug(x) cout<<#x<<"->"<<x<<endl
#define sz(data) sizeof(data)/sizeof(data[0])

void insertion(int a[],int n){
    for(int i=1;i<n;i++)
    {
        int temp=a[i];
        int j=i-1;
        while(a[j]>temp && j>=0)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=temp;
        for(int i=0;i<n;i++){
                if(i!=n-1) cout<<a[i]<<' ';
                else cout<<a[i]<<endl;;
        }
    }

}

int main()
{
    //freopen("input.txt" ,"r", stdin);

    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
                if(i!=n-1) cout<<a[i]<<' ';
                else cout<<a[i]<<endl;;
        }
    insertion(a,n);

  return 0;
}



Measured memory_bytes: 3092
def nCk(_n,_k):
  return (fact[_n]//(fact[_k]*fact[_n-_k]))%m

fact=[1]*2005
for i in range(1,2004):
  fact[i]=fact[i-1]*i

n,k=map(int,input().split())
r=n-k
m=10**9+7

for i in range(1,k+1):
  if r<i-1: print(0); continue;
  if i==1: print(r+i); continue;
  else:
    ans=nCk(r+1,i)*nCk(k-1,i-1)
    print(ans%m)


Measured memory_bytes: 11580
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N,M;
int32_t Sx[50];
int32_t Sy[50];
int32_t Cx[50];
int32_t Cy[50];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>>M;
	for (size_t i = 0; i < N; i++)
	{
		in >> Sx[i] >> Sy[i];
	}
	for (size_t i = 0; i < M; i++)
	{
		in >> Cx[i] >> Cy[i];
	}
	for (size_t i = 0; i < N; i++)
	{
		int index = 0;
		int min = 1000000000;
		for (size_t j = 0; j < M; j++)
		{
			using std::abs;
			auto dis = abs(Cx[j] - Sx[i]) + abs(Cy[j] - Sy[i]);
			if (dis < min) {
				min = dis;
				index = j;
			}
		}
		out << index + 1 << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 256
#include <cstdio> 
typedef long long ll;
ll n,a,b,ans;
int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a>b){
		puts("0");
		return 0;
	}
	if(n==1){
		if(a==b)puts("1");
			else puts("0");
		return 0;
	}
	if(n==2)return puts("1") && 0;
	ans=(n-1)*b+a-((n-1)*a+b)+1;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	string in="NWSE";
	string s;
	cin>>s;
	bool co[4]={0};
	rep(i,s.size())rep(j,4)if(in[j]==s[i])co[j]=true;
	if((co[0]+co[2])%2==0&&(co[1]+co[3])%2==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
 
 







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

int main(){
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i = 0; i < n; i++) cin >> h[i];
    int count = 0;
    for(int i = 0; i < n; i++){
        if(h[i] >= k) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define M ((int)1e9)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
typedef long long ll;
using namespace std;
int n;

void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int c=0,ma=0;
    for(int i=1;i<n;i++)
    {
        if(a[i]<=a[i-1])
        c++;
        else
        {
            ma=max(c,ma);c=0;
        }
    }
    if(c!=0)
    ma=max(ma,c);
    cout<<ma<<endl;
}



int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    map<int, int> mp;
    REP(i, n){
        if(a[i] % 4 == 0){
            mp[4]++;
        }else if(a[i] % 2 == 0){
            mp[2]++;
        }else{
            mp[1]++;
        }
    }

    n -= mp[2];
    if(mp[2] == 0){
        cout << (mp[4] >= n/2 ? "Yes" : "No") << endl;
    }else{
        cout << (mp[4] >= n/2 + n%2 ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

#define ll long long int
#define ull unsigned long long int

#define INF 100000000000L

using namespace std;

int main(){
    ll N,M,C;
    cin >> N >> M >> C;
    vector<ll> B(M);
    vector<vector<ll>> A;
    A = vector<vector<ll>>(N, vector<ll>(M, 0));
    for(int i= 0;i<M;i++){
        cin >> B[i];
    }
    int count = 0;
    for(int i=0;i<N;i++){
        ll sum = 0;
        for(int j=0;j<M;j++){
            ll a;
            cin >> a;
            sum += a*B[j];
        }
        sum += C;
        if(sum > 0){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, m, x, y = nm()
    X = nl()
    Y = nl()
    xx = max(X)
    yy = min(Y)
    for z in range(-100, 101):
        if x < z <= y and xx < z <= yy:
            print('No War')
            return
    print('War')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    ll k, a, b; cin >> k >> a >> b;
    ll cnt = 1;
    if(a + 1 < b) {
        k -= a - 1;
        cnt += a - 1;
        if(k % 2 != 0) {
            cnt++;
            k--;
        }
        cnt += (b - a) * (k / 2);
    } else {
        cnt += k;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i > 0; i--)

int main() {
    string S;
    cin >> S;
    if(S[0]=='S')
        cout << "Cloudy" << endl;
    if (S[0] == 'C')
        cout << "Rainy" << endl;
    if (S[0] == 'R')
        cout << "Sunny" << endl;

    return 0;
}

Measured memory_bytes: 256
#import<cstdio>
int main(){int n,h,m;scanf("%d",&n);for(;n--;){scanf("%d:%d",&h,&m);double s=h*30+m/2.,l=m*6,t,d;l<s?t=l,l=s,s=t:0;d=s-l+360;l-s<d?d=l-s:0;d<30?puts("alert"):d<90?puts("warning"):puts("safe");}}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main(){
  
  int N , M;
  cin >> N;
  long T[N];
 
  for(int i = 0 ; i < N ; i++){
    cin >> T[i];
    //cout << "T[i]:" << T[i] << endl;
  }

  
  


  cin >> M;
  
  int P[M];
  long X[M];


  for(int i = 0 ; i < M ; i++){
    cin >> P[i] >> X[i];
    //cout << "X[i]:" << X[i] << endl
  }
  
  

  for(int i = 0 ; i < M ; i++){
    int sum = 0;
    for(int j = 0 ; j < N ; j++){
      //cout << "j:" << j << " P[i]:" << P[i] << endl;
      if(j+1 == P[i]){
        sum += X[i];  
        //cout << "X[j]:" << X[j] <<endl;
      }
      else{
        sum += T[j];
        //cout << "T[i]:" << T[i] <<endl;
      }
      //cout << "sum:" << sum << endl;
    }
    cout << sum << endl;
  }
    

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>Set;
typedef tree<int,int,less<int>,rb_tree_tag,tree_order_statistics_node_update> Map;

#define ipow(a,b)+0.5 (int)pow(a,b)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fi first
#define se second
#define pll pair<ll,ll>
#define ook order_of_key
#define findby find_by_order
#define pii pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,a,b) for(int i=a;i<=b;i++)

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }

const ld EPS = ld(1e-9);
const ld PI = ld(3.141592653589);

int n;
ll a[300005];

class Task
{
public:
    void solve(istream& in,ostream& out)
    {
          in>>n;
          for(int i=1;i<=3*n;i++)
          {
               in>>a[i];
          }

          sort(a+1,a+3*n+1,greater<int>());

          ll res=0;

          for(int i=2;i<=2*n;i+=2)
          {
               res+=a[i];
          }

          out<<res<<endl;
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}





Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.Arrays;

class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        
        int[] x = new int[10];
        for (int i = 0; i < 10; i++) {
            x[i] = input.nextInt();
        }
        Arrays.sort(x);
        for (int i = 9; 6 < i; i--) {
            System.out.println(x[i]);
        }
    }
}

Measured memory_bytes: 26204