akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin>>N;
    
    double v[N],Ans=0;
    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    sort(v,v+N);
    Ans=v[0];
    for(int i=1;i<N;i++){
        Ans=(Ans+v[i])/2;
    }
    cout<<Ans<<endl;
}

Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}
func NextInts() (int,int) {
  var a []int = NextIntArray()
  return a[0],a[1]
}

func main() {
  var n,x int = NextInts()
  var a []int = NextIntArray()
  if n == 1 {
    if a[0] > x {
      fmt.Println(a[0]-x)
    } else {
      fmt.Println(0)
    }
    os.Exit(0)
  }
  var m int = 0
  for i:=1;i<n;i++ {
    if a[i-1]+a[i] > x {
      var r int = a[i-1]+a[i]-x
      m += r
      a[i] -= r
      if a[i] < 0 { a[i] = 0 }
    }
  }
  fmt.Println(m)
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int a[N];
    int cnt = 0,cntt = 0,out = 0;
    REP(i,N){
        cin >> a[i];
        if(a[i] % 4 == 0) cnt++;
        if(a[i] % 2 == 0)cntt++;
        if(a[i] % 4 != 0 && a[i] % 2 != 0) out++;
    }
    if(cntt == N || cnt == N/2 || cnt == out) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define sz(x) (x).size()
#define lowbit(x) (x)&(-x)
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))

namespace FastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
	bool IOerror=0;
	inline char nc() {
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if(p1==pend) {
			p1=buf;
			pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if(pend==p1) {
				IOerror=1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch) {
		return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
	}
	template<class T> inline bool read(T &x) {
		bool sign=0;
		char ch=nc();
		x=0;
		for(; blank(ch); ch=nc());
		if(IOerror)return false;
		if(ch=='-')sign=1,ch=nc();
		for(; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if(sign)x=-x;
		return true;
	}
	template<class T,class... U>bool read(T& h,U&... t) {
		return read(h)&&read(t...);
	}
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace std;
using namespace FastIO;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 0x3f3f3f3f;
const int N = 2e5+10;

struct node {
	int l,r,mid,ma;
} tree[N<<2];

int a[N],ans[N];
vector<int>e[N];
int n;

void pp(int x) {
	tree[x].ma=max(tree[ls].ma,tree[rs].ma);
}

void build(int x,int l,int r) {
	tree[x]= {l,r,l+r>>1,0};
	if(l==r) {
		return ;
	}
	int mid=tree[x].mid;
	build(ls,l,mid);
	build(rs,mid+1,r);
}

void modify(int x,int pos,int k) {
	if(tree[x].l==pos && tree[x].r==pos) {
		tree[x].ma=k;
		return ;
	}
	int mid=tree[x].mid;
	if(pos<=mid) modify(ls,pos,k);
	if(pos>mid) modify(rs,pos,k);
	pp(x);
}

int query(int x,int l,int r) {
	if(l<=tree[x].l&&tree[x].r<=r) {
		return tree[x].ma;
	}
	int mid=tree[x].mid;
	int res=0;
	if(l<=mid) res=max(res,query(ls,l,r));
	if(r>mid) res=max(res,query(rs,l,r));
	return res;
}

void dfs(int u,int fa) {
	int now=a[u];
	int sum=query(1,1,now-1)+1;
	int pre=query(1,now,now);
	modify(1,now,max(sum,pre));
	ans[u]=query(1,1,n+5);
	for(auto v:e[u]) {
		if(v==fa) continue;
		dfs(v,u);
	}
	modify(1,now,pre);
}

int main() {

#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	read(n);
	vector<int>b;
	for(int i=1; i<=n; i++) {
		read(a[i]);
		b.pb(a[i]);
	}
	sort(all(b));
	b.erase(unique(all(b)),b.end());
	for(int i=1; i<=n; i++) a[i]=lower_bound(all(b),a[i])-b.begin()+2;
	for(int i=1; i<n; i++) {
		int u,v;
		read(u,v);
		e[u].pb(v);
		e[v].pb(u);
	}
	build(1,1,n+5);
	dfs(1,1);
	for(int i=1; i<=n; i++)	cout<<ans[i]<<"\n";





	return 0;
}



Measured memory_bytes: 36228
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderByDescending(x => x).ToArray();
            var max = l[0];
            var sum = l.Where((x, i) => i > 0).Sum(x => x);
            if(max < sum)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13524
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a.cpp"

int main() {
  ll l, r, d;
  cin >> l >> r >> d;
  ll cnt = 0;
  rep3(i, l, r+1) {
    cnt += i%d == 0;
  }
  cout << cnt << el;
}


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

int main() {
	int n;cin>>n;
	vector<int> v={1,1,0,2,0,0,1,0,1,0};
	if(v[n%10]==0){
		cout<<"hon"<<endl;
	}else if(v[n%10]==1){
		cout<<"pon"<<endl;
	}else{
		cout<<"bon"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3624
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
ans = 0
j = False

for k, v in sorted(d.items(), key = lambda x: -x[0]):
    if v >= 4:
        if ans == 0:
            ans = k*k
            j = True
            break
        else:
            ans *= k
            j = True
            break
    elif v >= 2:
        if ans == 0:
            ans = k
        else:
            ans *= k
            j = True
            break
if j == True:
    print(ans)
else:
    print(0)

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());

    int alice = 0, bob = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }

    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  ll a,b;
  cin>>a>>b;
  if(a>0&&b>0){
    cout<<"Positive"<<endl;
  }
  if(a<=0&&b>=0){
    cout<<"Zero"<<endl;
  }
  if((a<0&&b<0)&&(b-a)%2==0){
    cout<<"Negative"<<endl;               
  }      
  if((a<0&&b<0)&&(b-a)%2==1){
    cout<<"Positive"<<endl;               
  }      
}   

Measured memory_bytes: 3616
import math
  
inp = input().split(" ")
inp = [float(i) for i in inp]

a = inp[0]
b = inp[1]
x = inp[2]

if (x / a) <= (a * b / 2):
  theta = math.atan((a * b * b) / (2 * x))
else:
  theta = math.atan(2 * (a * b - (x / a)) / (a * a))
  
print(theta * 180 / math.pi)

Measured memory_bytes: 3064
a = int(input())
word = []
for i in range(a):
    word.append(input())

for j in range(len(word)):
    if j > 0:
        mae = word[j-1]
        ima = word[j] 
        if mae[-1] != ima[0]:
            print("No")
            exit()
for w in word:
    if word.count(w) > 1:
        print("No")
        exit()
print("Yes")

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

int n, k;
vector<int> v;
int ans;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	v.resize(n);
	for(auto &i:v) cin >> i;
	for(int i=0; i<=n; ++i){
		for(int j=0; i+j<=min(n,k); ++j){
			vector<int> w;
			for(int l=0; l<i; ++l) w.push_back(v[l]);
			for(int l=0; l<j; ++l) w.push_back(v[n-1-l]);
			sort(w.begin(), w.end());
			for(int l=0; l<min<int>(w.size(),k-i-j); ++l)
				if(w[l] < 0)
					w[l] = 0;
			ans = max(ans, accumulate(w.begin(), w.end(), 0));
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    long long n,a[64],i,j,jud,rw=0,h;
    scanf("%lld",&n);
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);rw+=a[i];
    }
    for(i=rw-100000;i<=rw;i++){
        if(i<0){continue;}
        h=0;
        for(j=1;j<=n;j++){
            jud=i+a[j];h+=(jud/(n+1));
            if(jud%(n+1) == n){h++;}
        }
        if(h>i){continue;}
        printf("%lld\n",i);break;
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fl(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define mx 200005
#define inf 2e9
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int arr[mx];
ll dp[101][100001]={0};
int main()
{
	fast;
	ll n,W;
	cin>>n>>W;
	vector<int >w,v;
    w.pb(0);
    v.pb(0);
	for(ll i=1;i<=n;i++)
	{
		ll x,y;
		cin>>x>>y;
		w.pb(x);
		v.pb(y);
	}
	/*for(int i=0;i<=n;i++)
		cout<<w[i]<<" "<<v[i]<<endl;*/
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=W;j++)
		{
			if(i==0||j==0)
				dp[i][j]=0;
			else if(w[i]<=j)
			{
				dp[i][j] = max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
			}
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][W];
	return 0;
}


Measured memory_bytes: 79232
#include "bits/stdc++.h"
using namespace std;
int main(){
    int a[5],k,i,j,ans=1;
    for(i=0;i<5;i++) cin >> a[i];
    cin >> k;
    for(i=0;i<4;i++){
        for(j=i+1;j<5;j++){
            if(a[j]-a[i]>k) ans = 0;
        }
    }
    if(ans) cout<<"Yay!"<<endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int h,a;
cin >> h >> a;
if(h%a==0){
    cout << h/a;

}
else{
    cout << h/a+1<<endl;
}
}





Measured memory_bytes: 256
S = input()

i = 1
flg = 0

for s in S:
  if i % 2 == 1:
    if s != 'R' and s != 'U' and s != 'D':
      flg = 1
      print('No')
      break
      
  if i % 2 == 0:
    if s != 'L' and s != 'U' and s != 'D':
      flg = 1
      print('No')
      break  
      
  i = i + 1
      
if flg == 0:
  print('Yes')
      


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/03  Problem: 014_agc_b / Link: https://agc014.contest.atcoder.jp/tasks/agc014_b?lang=en  ----- */
/* ------問題------

高橋君は木の問題が苦手です。そこで、青木君は高橋君の練習相手になってあげることにしました。
まず、高橋君は N 頂点からなる木を用意し、頂点に 1 から N の番号を付けました。 そして、各辺に 0 と書きました。
次に、青木君は高橋君に M 個のクエリを与えました。i 個目のクエリは以下のような内容です。
頂点 ai と頂点 bi を結ぶパス上の辺すべてに対して、書かれている数を 1 増やす。
全てのクエリを終えた後、高橋君は青木君にどの辺を見ても書かれている数が偶数になったと伝えました。 しかし、青木君は最初に高橋君が用意していた木を確認していなかったので、 高橋君が正しくクエリを処理できたか分かりませんでした。
青木君を助けるために、高橋くんの言う性質を満たす木が存在するかどうかを判定してください。

-----問題ここまで----- */
/* -----解説等-----

適当な根付き木を考えたとき、どのような場合でも登場回数が偶数回ならば辺は偶数の値になる。

----解説ここまで---- */

LL N, M ;

LL ans = 0LL;

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

	cin >> N>>M;
	VI ver(N);
	FOR(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		ver[a]++;
		ver[b]++;
	}

	ans = 1;
	FOR(i, 0, N) {
		if (ver[i] % 2)ans = 0;
	}
	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << "\n";
	}

	return 0;
}


Measured memory_bytes: 640
n=int(input())
ans=n
l=[list(map(int,input().split())) for i in range(n)]

for i in range(n):
    for j in range(n):
        if i==j:continue
        p,q=l[i][0]-l[j][0],l[i][1]-l[j][1]
        ret=0
        pre=sorted(l,reverse=1,key=lambda x:p*x[0]+q*x[1])
        while pre:
            ret+=1
            x,y=pre.pop()
            while  [x+p,y+q] in pre:
                pre.remove([x+p,y+q])
                x,y=[x+p,y+q]
        ans=min(ans,ret)
print(ans)

Measured memory_bytes: 3064
class Dice
	attr_reader :surface
	def initialize arr
		@surface = arr
	end
	def rotate d
		tmp = @surface.clone
		case d
		when 'N'
			tmp[0]=@surface[1];tmp[1]=@surface[5];tmp[5]=@surface[4];tmp[4]=@surface[0]
		when 'S'
			tmp[0]=@surface[4];tmp[1]=@surface[0];tmp[5]=@surface[1];tmp[4]=@surface[5]
		when 'W'
			tmp[3]=@surface[0];tmp[0]=@surface[2];tmp[2]=@surface[5];tmp[5]=@surface[3]
		when 'E'
			tmp[3]=@surface[5];tmp[0]=@surface[3];tmp[2]=@surface[0];tmp[5]=@surface[2]
		end
		@surface = tmp
	end
end
r = Dice.new gets.split
gets.each_char { |ch| r.rotate ch }
puts r.surface[0]

Measured memory_bytes: 8604
#include <bits/stdc++.h>
using namespace std;
 
vector<unsigned long long> next_p_mod(unsigned N, long long mod) { //next_permutation
  vector<unsigned long long> Next_p(N);
  unsigned long long Next_p_buff = 1;
  for (int i = 0; i < N; i++)
  {
    Next_p_buff *= (i + 1) % mod;
    Next_p.at(i) = Next_p_buff % mod;
  }
  return Next_p;
}
unsigned long long modpow(unsigned long long a, unsigned long long n, unsigned long long mod) {
   unsigned long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
void comb(vector<vector <long long int> > &v,unsigned long long mod) {
  //vector<入れたい型> v(配列の個数(x),vector<入れたい型> (配列の個数,初期値));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int k = 1; k < v.size(); k++) {
    for (int j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
    }
  }
}
// a^{-1} mod を計算する
unsigned long long modinv(unsigned long long a, unsigned long long mod) {
    return modpow(a, mod - 2, mod);
}
 
 
int main() {
  string S;
  bool flag=0;
  cin >> S;
  for(int i=0;i<S.size()-1;i++){
    if(S.at(i)==S.at(i+1)){
    cout<<"Bad"<<endl;
      flag=1;
      break;
    }
  }
  if(flag!=1){
    cout<<"Good"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
def resolve():
    n=int(input())
    a=list(map(int,input().split()))
    l=[0]*(10**5+1)
    for i in a:
        l[i]+=1
    ans=sum(a)
    q=int(input())
    for i in range(q):
        b,c=map(int,input().split())
        x=l[b]
        ans+=(c-b)*x
        l[c]+=x
        l[b]=0
        print(ans)

if __name__ == '__main__':
    resolve()

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


int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < n-1; i++) {
        if ((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 1e9

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    REP(i, n)
    {
        cin >> x[i];
    }
    ll res = INF;
    REP(i, n - k + 1)
    {
        ll xl = x[i];
        ll xr = x[i + k - 1];
        ll t1 = abs(xl) + abs(xl - xr);
        ll t2 = abs(xr) + abs(xl - xr);
        ll mint = min(t1, t2);
        res = min(res, mint);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;
ll dp[101][301];

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

  ll n, W;
  cin >> n >> W;
  ll w[n], v[n], ww[n];

  vector<ll> a, b, c, d, sa, sb, sc, sd;

  REP(i, n){
    cin >> w[i] >> v[i];
    if(w[i] == w[0]) a.pb(v[i]);
    else if(w[i] == w[0] + 1) b.pb(v[i]);
    else if(w[i] == w[0] + 2) c.pb(v[i]);
    else d.pb(v[i]);
  }

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  sort(d.rbegin(), d.rend());

  ll ans = 0;

  sa.pb(0);
  sb.pb(0);
  sc.pb(0);
  sd.pb(0);

  REP(i, a.size()) sa.pb(sa[i] + a[i]);
  REP(i, b.size()) sb.pb(sb[i] + b[i]);
  REP(i, c.size()) sc.pb(sc[i] + c[i]);
  REP(i, d.size()) sd.pb(sd[i] + d[i]);

  REP(i, n + 1){
    REP(j, n - i + 1){
      REP(k, n - (i + j) + 1){
        REP(l, n - (i + j + k) + 1){
          if((i + j + k + l) * w[0] + j + 2 * k + 3 * l <= W && i <= a.size() && j <= b.size() && k <= c.size() && l <= d.size()){
            ans = max(sa[i] + sb[j] + sc[k] + sd[l], ans);
          }
        }
      }
    }
  }
  cout << ans << endl;


}


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll big = 10e10 + 11 ;

int  main (  ) {

    FASTIO ;

    int n ;
    cin >> n ;

    set < int > s ;

    for( int i = 0 ; i < n ; i++ ) {
        int x ;
        cin >> x ;
        s.insert( x ) ;
    }

    if( s.size( ) != n ) cout << "NO" ;
    else   cout << "YES" ;


    return  0 ;
}



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

namespace std {
	#define u(x, a, b) for(ll x = a; x < b; x++)
	#define d(x, a, b) for(ll x = a; x > b; x--)
}

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 1000000007

int main(){
	ll n;
	cin >> n;
	
	ll book[100001] = {0};
	ll x;
	ll tot = 0;
	u(one, 0, n){cin >> x; book[x]++; tot+=x;}
	
	ll q;
	cin >> q;
	
	u(one, 0, q){
		ll b, c;
		cin >> b >> c;
		
		ll num = book[b];
		book[b] = 0;
		book[c]+=num;
		tot += (c-b)*num;
		
		cout << tot << endl;
	}
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    int N,M; cin>>N>>M;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) {
      cin>> a[i];

    }
    vector<int> rmod(N+1,0);
    map<int,int> samemod;
    samemod[0]=1;
    for (int j = 0; j < N; ++j) {
        (rmod[j+1]=rmod[j]+a[j])%=M;

        auto iter=samemod.find(rmod[j+1]);
        if(iter!=samemod.end()){
            samemod[rmod[j+1]]++;
        }else{
            samemod[rmod[j+1]]=1;
        }
    }
    ll ans=0ll;
    for(auto iter=samemod.begin();iter!=samemod.end();++iter){
        int cnt=iter->second;
        ans+=(ll)cnt*(cnt-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define fi first
#define se second
#define pb push_back
#define read(type, ...)type __VA_ARGS__; macro_scan(__VA_ARGS__);
#define debug(...)cerr<<"["<<#__VA_ARGS__<<"] : ",deb(__VA_ARGS__);

using namespace std;

template<typename T> void macro_scan(T& t){cin>>t;};
template<typename F, typename ...R>void macro_scan(F& f , R& ...r){
  cin>>f;macro_scan(r...);
}

void deb(){
    cerr<<endl;
}
template<typename T , typename... t>
void deb(T a , t...b){
    cerr<<a<<",";
    deb(b...);
}
template<typename T>
void dev(vector<T>v){
    int c = 0;
    for(auto i : v){
        cerr<<i<<" ";
        c++;
    }
    cerr<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //int t; cin>>t;for(;t--;)done();
    read(int , n , m);
    vector<vector<int> > g(n + 1);
    for(int i = 0 ; i < m; ++i){
        int a , b ; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<bool>mark(n + 1);
    vector<int>dp(n + 1 , INT_MAX) , ans(n + 1);
    queue<int>q;
    q.push(1);
    dp[1] = 0;
    mark[1] = 1;
    while(!q.empty()){
        int u  = q.front(); q.pop();
        for(int v : g[u]){
            if(dp[u] + 1 < dp[v]){
                dp[v] = dp[u] + 1;
                ans[v] = u;
            }
            if(!mark[v]){
                mark[v] = 1;
                q.push(v);
            }
        }
    }
    for(int i = 1 ; i <= n; ++i){
        if(!mark[i]){
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    for(int i = 2 ; i <= n; ++i)cout<<ans[i]<<"\n";


}
//@01928419790ar epic games ar7iq r7e

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

int main(){
  while(true){
    int njudge = 0;
    cin >> njudge;
    if(njudge == 0)return 0;
    int max=0;
    int min=10000;
    int ave=0;
    int sum=0;
    for(int i = 0 ; i<njudge ; i++){
      int input;
      cin >> input;
      if(max < input)max = input;
      if(min > input)min = input;
      sum += input;
    }
    sum -= min;
    sum -= max;
    njudge -= 2;
    ave = sum/njudge;
    cout << ave << endl;
  }
  return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		if(number == 10000) {
			System.out.println(0);
			System.exit(0);
			
		}
		int ans = number/1000;
		
		if(number%1000 == 0) {
			System.out.println(0);
		}
		else {
			ans = 1000-(number - ans*1000);
			System.out.println(ans);
		}
		
	}

}


Measured memory_bytes: 35776
#pragma GCC optimize ("O2")
#include <bits/stdc++.h>
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
inline int read() {
	int f=1,sum=0;
	char x=getchar();
	for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
	for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
	return f*sum;
}

#define M 2000005
int n,K;
int a[M],pos[M];

map <int,ll> st;

inline ll calc_(int x) {
	if(st.count(x)) return st[x];
	ll num=0;
	for1(1,x,i) pos[n-i+1]=1,num+=K+a[n-i+1];
	int head=n;
	FOR2(n-x,1,i) {
		num+=1ll*(a[head]-a[i])*(pos[head]+1)*(pos[head]+1)+K;
		pos[i]=pos[head]+1;
		--head;
	}
	while (head) num+=1ll*a[head]*(pos[head]+1)*(pos[head]+1),--head;
	return st[x]=num+1ll*K*x;
}

signed main () {
	//freopen("a.in","r",stdin);
	n=read(),K=read();
	for1(1,n,i) a[i]=read();
	ll ans=8e18;
	int l=1,r=n,mid,midd;
	while (l+6<r) {
		mid=l+r>>1;
		midd=mid+r>>1;
		ll t[2]={calc_(mid),calc_(midd)};
		if(t[0]<t[1]) ans=min(ans,t[0]),r=midd;
		else ans=min(ans,t[1]),l=mid;
	}
	for1(l,r,i) {
		ll num=calc_(i);
		ans=min(ans,num);
	}
	//cout<<(double)clock()/CLOCKS_PER_SEC<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 5888
#!/usr/bin/env python3

def solve(a: int, b: int, c: int, d: int) -> bool:
    while True:
        c -= b
        if c <= 0:
            return True
        a -= d
        if a <= 0:
            return False

# generated by online-judge-template-generator v4.1.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    A, B, C, D = map(int, input().split())
    ans = solve(A, B, C, D)
    print(ans and 'Yes' or 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define int long long
int findLowerBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{

    auto low = lower_bound(arr.begin(),
                           arr.end(), p);

    return low - arr.begin();
}
int findUpperBound(
    vector<pair<int, int>> &arr,
    pair<int, int> &p)
{
    auto up = upper_bound(arr.begin(),
                          arr.end(), p);

    return up - arr.begin();
}
bool vis[200005];
vector<int> vec[100005];
int child[100005];
void dfs(int node)
{
    vis[node] = 1;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            child[node] += child[vec[node][i]];
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;
    int n;
    cin >> n;
    int m;
    cin >> m;
    int count[n + 1] = {0};
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        count[x]++;
        count[y]++;
    }
    for (int i = 1; i <= n; i++)
        cout << count[i] << "\n";
    return 0;
}


Measured memory_bytes: 5988
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// import here

int main(){
    LL a;
    double b;
    cin >> a >> b;
    LL b2 = (b*100 + 1e-13);
    cout << a * b2 / 100 << endl;
    return 0;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}
 
 
signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      
    
    int n;
    cin>>n;
    int a[n+1];
    multiset<int>s;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    sort(a+1,a+n+1);
    int ans=0;
    int mx=0;

    if(n%2==0)
    {
        int x=a[n/2];
        s.erase(s.find(x));
        while (!s.empty())
        {
            auto j=s.end();
            j--;
            ans+=abs(*j-x);
            x=*j;
            s.erase(j);
            if(!s.empty())
            {
                j=s.begin();
                ans+=abs(*j-x);
                x=*j;
                s.erase(j);
            }
        }    
        mx=max(mx,ans);    
    }
    else
    {
        int x=a[(n+1)/2];
        s.erase(s.find(x));
        while (!s.empty())
        {
            auto j=s.end();
            j--;
            ans+=abs(*j-x);
            x=*j;
            s.erase(j);
            if(!s.empty())
            {
                j=s.begin();
                ans+=abs(*j-x);
                x=*j;
                s.erase(j);
            }
        }
        mx=max(mx,ans);                
    }
    for(int i=1;i<=n;i++)
        s.insert(a[i]);
    ans=0;
    if(n%2==0)
    {
        int x=a[n/2+1];
        s.erase(s.find(x));
        while (!s.empty())
        {
            auto j=s.begin();
            ans+=abs(*j-x);
            x=*j;
            s.erase(j);
            if(!s.empty())
            {
                j=s.end();
                j--;
                ans+=abs(*j-x);
                x=*j;
                s.erase(j);
            }
        }    
        mx=max(mx,ans);    
    }
    else
    {
        int x=a[(n+1)/2];
        s.erase(s.find(x));
        while (!s.empty())
        {
            auto j=s.begin();
            ans+=abs(*j-x);
            x=*j;
            s.erase(j);
            if(!s.empty())
            {
                j=s.end();
                j--;
                ans+=abs(*j-x);
                x=*j;
                s.erase(j);
            }
        }
        mx=max(mx,ans);                
    }

    cout<<mx;    
} 

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
 
using namespace std;
const int MOD=1e9+7;
typedef long long ll;
const int MAXN=1e5+15;
const ll INF=0x3f3f3f3f;
 
typedef pair<ll,ll>PA;
 
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x);x=(x*x);}return res;}
pair<ll,ll>P;
vector<PA> V;
multiset<ll>R,B;
int cmp(PA a,PA b)
{
    return a.first<b.first;
}
int main()
{
    int n;
    ll x,y;
    ll res2,ans;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y;
        V.push_back(make_pair(min(x,y),max(x,y)));
        R.insert(min(x,y));
        B.insert(max(x,y));
    }
    ll maR=-INF,maB=-INF;
    ll miR=INF,miB=INF;
    int col_max=0,col_min=0;
    sort(V.begin(),V.end(),cmp);
    for(int i=0;i<V.size();i++)
    {
        maR=max(V[i].first,maR);
        maB=max(V[i].second,maB);
        miR=min(V[i].first,miR);
        miB=min(V[i].second,miB);
    }
 
    ans=(maR-miR)*(maB-miB);
    for(int i=0;i<V.size();i++)
    {
        R.erase(R.find(V[i].first));
        B.insert(V[i].first);
        B.erase(B.find(V[i].second));
        R.insert(V[i].second);
        ans= min (ans,( *R.rbegin()-*R.begin() )*( *B.rbegin()-*B.begin()) );
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 23020
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  int64_t D;
  cin >> D;

  int result = 0;
  rep(i, N) {
    int64_t X, Y;
    cin >> X >> Y;
    if (X * X + Y * Y <= D * D) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;



int main() {
    string s;
    int q;
    int t;
    int f;
    char c;
    string sentou;
    cin >> s >> q;
    rep(i, q) {
        cin >> t;
        if (t == 1) {
            swap(s, sentou);
        }
        else {
            cin >> f >> c;

            if (f == 1) {
                sentou += c;
            }
            else {
                s += c;
            }
        }
    }
    reverse(sentou.begin(),sentou.end());

    sentou += s;

    cout << sentou << endl;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int maxv = min(a, b);
  // if(a + b >= n){
  //   maxv = n;
  // }
  int minv = n - ((n-a) + (n-b));
  minv = max(0, minv);
  cout << maxv << " " << minv << endl;
}


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

int main()
{
	int n, i, j, k, l;
	int b, f, r, v;
	int ans[4][3][10] = { 0 };

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		if ((b < 0 || b>4) 
			|| (f < 0 || f>3) 
			|| (r < 0 || r>10)
			) continue;
		ans[b - 1][f - 1][r - 1] += v;
	}
	for (l = 0; l < 4; l++) {
		for (k = 0; k < 3; k++) {
			for (j = 0; j < 10; j++) {
				if (ans[l][k][j] > 9)ans[l][k][j] = 9;
				else if (ans[l][k][j] < 0) ans[l][k][j] = 0;

				printf(" %d", ans[l][k][j]);
			}
			printf("\n");
		}
		if(l!=3) printf("####################\n");
	}

	return 0;
}


Measured memory_bytes: 2092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
using namespace std;

int main()
{
    int ans = 0, t_ans = 0, N;
    char S[10];
    cin >> S;
    N = strlen(S);
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G')
        {
            ans++;
            if (i == N - 1 && t_ans < ans)
            {
                t_ans = ans;
            }
        }
        else
        {
            if (t_ans < ans)
            {
                t_ans = ans;
            }
            ans = 0;
        }
    }
    cout << t_ans << endl;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n = gets.to_i
as = gets.split.map(&:to_i).sort!
bs = gets.split.map(&:to_i)
cs = gets.split.map(&:to_i).sort!

ans = 0
bs.each do |b|
  x = as.bsearch_index { |a| a >= b }
  x = n if x.nil?
  y = cs.bsearch_index { |c| b < c }
  y = n if y.nil?
  y = n - y
  ans += x * y
end
puts ans


Measured memory_bytes: 23160
N, M = map(int, input().split())
route = {i: 0 for i in range(N)}
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    route[a] += 1
    route[b] += 1
route = (x[1] for x in sorted(route.items(), key=lambda x: x[0]))
print(*route, sep='\n')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll a[5],n;
int main()
{
	while(scanf("%lld%lld%lld%lld",&a[0],&a[1],&a[2],&a[3])!=EOF)
	{
		scanf("%lld",&n);
		for(int i=1;i<4;i++) a[i]=min(a[i],2*a[i-1]);
		printf("%lld\n",n/2*a[3]+(n&1)*a[2]);
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX)

using namespace std;
typedef long long ll;


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>M(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            char a;
            cin>>a;
            M[i][j]=a;
        }
    }
    vector<vector<int>>dp(h+1,vector<int>(w+1,0));
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(M[i][j]=='#')continue;
            dp[i+1][j]=(dp[i][j]+dp[i+1][j])%int(1e9+7);
            dp[i][j+1]=(dp[i][j]+dp[i][j+1])%int(1e9+7);
        }
    }
    cout<<dp[h-1][w-1];
}
/*
*/

Measured memory_bytes: 8540
using System;
using System.Linq;

namespace AGC015
{
    class A
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long N = input[0];
            long A = input[1];
            long B = input[2];

            if (N == 1)
            {
                if (A == B) { Console.WriteLine(1); return; }
                else { Console.WriteLine(0); return; }
            }
            else
            {
                if (B < A) { Console.WriteLine(0); return; }
                else Console.WriteLine((B - A) * (N - 2) + 1);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};

int main(void) {
    Int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    Int k;
    cin >> k ;
    cout << a[k-1] << endl;

}




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

int main()
{
      ll n;
      cin>>n;
      ll a[n];
      ll i;
      ll mini=1e9+1,c=0,sum=0;
      for(i=0;i<n;i++)
      {
        cin>>a[i];
        if(a[i]<0)
            c++;
        sum+=abs(a[i]);
        mini=min(mini,abs(a[i]));
      }
      if(c%2==0)
      {
        cout<<sum<<endl;
      }
      else
      {
        cout<<sum-2*mini<<endl;
      }

}

Measured memory_bytes: 4296
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
	ll N;
	vector<int> A;
	cin >> N;
	for(int i = 0; i < N; i++){
		ll a;
		cin >> a;
		A.push_back(a);
	}
	
	sort(A.begin(), A.end());
	
	vector<ll> first;
	vector<ll> second;
	
	bool flag = false;
	while(A.size() > 2){
		int a = A.back();
		int a_ = A[A.size()-2];
		if(a > 0 && a_ > 0 && !flag){
			A.pop_back();
			first.push_back(A.front());
			second.push_back(a);
			A.front() -= a;
		}else{
			flag = true;
			int b = A.front();
			A.erase(A.begin(), A.begin()+1);
			first.push_back(A.back());
			second.push_back(b);
			A.back() -= b;
		}
	}
	
	cout << A[1] - A[0] << endl;
	for(int i = 0; i < first.size(); i++){
		cout << first[i] << " " << second[i] << endl;
	}
	cout << A[1] << " " << A[0] << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;

int n, pre[1000005][26];
string T[200002];
ll ans;

struct trie {
    trie *son[26];
    int sum[26];
    trie() {
        for (int i = 0; i < 26; i++) son[i] = NULL, sum[i] = 0;
    }
} * root;

bool cmp(const string &a, const string &b) { return a.size() > b.size(); }

void insert(string &s) {
    for (int j = 0; j < 26; j++) pre[0][j] = 0;
    pre[0][s[0] - 'a'] = 1;
    for (int i = 1; i < s.size(); i++)
        for (int j = 0; j < 26; j++) {
            if (s[i] - 'a' == j)
                pre[i][j] = pre[i - 1][j] | 1;
            else
                pre[i][j] = pre[i - 1][j];
        }
    trie *cur = root;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (cur->son[s[i] - 'a'] == NULL) cur->son[s[i] - 'a'] = new trie;
        if (i == 0) ans += cur->sum[s[0] - 'a'];
        for (int j = 0; j < 26; j++) cur->sum[j] += pre[i][j];
        cur = cur->son[s[i] - 'a'];
    }
    // cout << s << " " << ans << endl;
}

int main() {
    // freopen("1.in", "r", stdin);
    // freopen("1.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    root = new trie;
    for (int i = 1; i <= n; i++) cin >> T[i];
    sort(T + 1, T + n + 1, cmp);
    for (int i = 1; i <= n; i++) insert(T[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 417628
n,m = map(int,input().split())
l,r = 1,n
for i in range(m):
    l_tmp,r_tmp = map(int,input().split())
    if l_tmp > l:
        l = l_tmp
    if r_tmp < r:
        r = r_tmp
if l>r:
    print(0)
else:
    print(r-l+1)

Measured memory_bytes: 3060
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main()
{
  uint64_t N, T;
  cin >> N >> T;

  uint64_t time = 0;
  uint64_t t0, t1;
  cin >> t0;
  for (uint64_t i = 0; i < N - 1; i++) {
    cin >> t1;
    time += min(T, t1 - t0);
    t0 = t1;
  }
  time += T;

  cout << time << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      res.push_back(n/i);
    }
  }
  return res;
}
int main(){
  ll n;cin>>n;
  vector<ll>vec=divisor(n);
  ll MIN=INF;
  for(int i=0;i<vec.size();i+=2){
    string s=to_string(vec[i]);
    string t=to_string(vec[i+1]);
    ll a=s.size();
    ll b=t.size();
    MIN=min(MIN,max(a,b));
  }
  cout<<MIN<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

type store struct {
	price, stock int
}

type stores []store

func (s stores) Len() int {
	return len(s)
}

func (s stores) Less(i, j int) bool {
	return s[i].price < s[j].price
}

func (s stores) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	N := nextInt()
	M := nextInt()
	ss := make([]store, N)
	for i := 0; i < N; i++ {
		ss[i] = store{price: nextInt(), stock: nextInt()}
	}

	sort.Sort(stores(ss))

	var money int
	for _, s := range ss {
		if M >= s.stock {
			money += s.stock * s.price
			M -= s.stock
		} else {
			money += M * s.price
			M -= M
		}

		if M == 0 {
			break
		}
	}

	fmt.Println(money)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextFloat() float64 {
	sc.Scan()
	f64, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}

	return f64
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
#define size 100001

int main()
{
    long long weight,cost,n,capacity,sum;
    cin>>n>>capacity;
    vector<long long>dp(size+1,INT_MAX);
    dp[0]=0,sum=0;
    for(int a=0;a<n;a++)
    {
        cin>>weight>>cost;
        sum+=cost;
        for(int b=size;b>=cost;b--)
        {
            dp[b]=min(dp[b],dp[b-cost]+weight);
        }
    }
    long long res=0;
    for(long long b=1;b<=sum;b++)
    {
        if(dp[b]<=capacity)
            res=max(b,res);
    }
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 1024