akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;

struct node{
    vl alpha;
    ll ans;
}segtree[1048679];
string str;
node util(node a, node b)
{
    node an;
    ll num=0;
    forr(i, 26)
    {
        ll total=a.alpha[i]+b.alpha[i];
        an.alpha.pb(total);
        if(total)
        num++;
    }
    an.ans=num;
    return an;
}
node Query(ll start, ll end, ll r1, ll r2, ll put)
{
    if(start>=r1&&end<=r2)
    return segtree[put];
    node sex;
    forr(i, 26)
    sex.alpha.pb(0);
    sex.ans=0;
    if(start>r2||end<r1)
    return sex;
    ll mid=start+(end-start)/2;
    return util(Query(start, mid, r1, r2, 2*put+1), Query(mid+1, end, r1, r2, 2*put+2));
}
node constructTree(ll start, ll end, ll put)
{
    if(start==end)
    {
        forr(i, 26)
        segtree[put].alpha.pb(0);
        segtree[put].alpha[(int)(str[start]-'a')]++;
        segtree[put].ans=1;
        return segtree[put];
    }
    ll mid=start+(end-start)/2;
    segtree[put]=util(constructTree(start, mid, 2*put+1), constructTree(mid+1, end, 2*put+2));
    return segtree[put];
}
node Update(ll start, ll end, ll index, ll put, char ch)
{
    if(index>end||index<start)
    return segtree[put];
    if(start==end)
    {
        if(start==index)
        {
            ll oldie=str[index]-'a';
            ll newie=ch-'a';
            str[index]=ch;
            segtree[put].alpha[oldie]--;
            segtree[put].alpha[newie]++;
            ll num=0;
            forr(i, 26)
            {
                if(segtree[put].alpha[i])
                num++;
            }
            segtree[put].ans=num;
            return segtree[put];
        }
        else
        return segtree[put];
    }
    ll mid=start+(end-start)/2;
    segtree[put]=util(Update(start, mid, index, 2*put+1, ch), Update(mid+1, end, index, 2*put+2, ch));
    return segtree[put];
}
void solve()
{
    ll n, q;
    cin>>n;
    cin>>str;
    cin>>q;
    ll x=(ll)ceil((log2(n)));
    x=(ll)pow(2, x);
    constructTree(0, n-1, 0);
    while(q--)
    {
        ll type, q1, q2;
        cin>>type;
        if(type==2)
        {
            cin>>q1>>q2;
            //cout<<q1<<" "<<q2<<endl;
            --q1;
            --q2;
            node lala=Query(0, n-1, q1, q2, 0);
            cout<<lala.ans<<endl;
        }
        else
        {
            char ch;
            cin>>q1>>ch;
            //cout<<q1<<" "<<ch<<endl;
            --q1;
            Update(0, n-1, q1, 0, ch);
        }
    }
    
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 302384
nii=lambda:map(int,input().split())
lnii=lambda:list(map(int,input().split()))

a,v=nii()
b,w=nii()
t=int(input())

dist=abs(b-a)

x1=v*t
x2=w*t

print('YES' if v*t>=w*t+dist else 'NO')

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    long long N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int> (C)), c(N, vector<int> (N));
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++) cin >> D[i][j];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) cin >> c[i][j];
    }
    map<long long, long long> m0, m1, m2;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if((i + j) % 3 == 0) m0[c[i][j] - 1]++;
            if((i + j) % 3 == 1) m1[c[i][j] - 1]++;
            if((i + j) % 3 == 2) m2[c[i][j] - 1]++;
        }
    }
    long long ans = 1e18;
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            if(i != j){
                for(int k = 0; k < C; k++){
                    if(j != k && i != k){
                        long long res = 0;
                        for(auto u: m0){
                            res += u.second * D[u.first][i];
                        }
                        for(auto u: m1){
                            res += u.second * D[u.first][j];
                        }
                        for(auto u: m2){
                            res += u.second * D[u.first][k];
                        }
                        ans = min(ans, res);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    std::string a, b, c;
    std::cin >> a >> b >> c;
    std::cout << (a.back()==b.front() && b.back()==c.front() ? "YES" : "NO") << '\n';
}


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

int a, b;

int main(int argc, char* argv[]){
  scanf("%d %d", &a, &b);
  if(a>0) printf("Positive\n");
  else if((a==0||b==0)||(a<0 && b>0)) printf("Zero\n");
  else if((b-a)%2==0) printf("Negative\n");
  else printf("Positive\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    int M1, M2, D1, D2;
    cin >> M1 >> D1 >> M2 >> D2;

    cout << (M1 != M2 ? 1 : 0) << endl;

    return 0;
}


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

int main(){
  long long a,b,k;
  std::cin >> a >> b >> k;
  
  if(a+b <= k){
	a=0;
    b=0;
  }
  else if(a <= k){
    b=b-(k-a);
    a=0;
  }
  else if(k < a){
    a=a-k;
  }
  
  std::cout << a << ' ' <<  b << std::endl;
}
      


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int l, r, d;
  cin>>l>>r>>d;
  int f = l % d == 0 ? l / d : l / d + 1;
  int cnt = 0;
  while(f * d <= r)
  {
    cnt++;
    f++;
  }
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    string S;
    getline(cin,S);
    int N = S.length();
    int zero = 0;
    int one = 0;
    REP(i,N){
        if (S[i] == '0') zero++;
        else one++;
    }
    
    int ans = N - abs(one-zero);

    cout << ans << "\n";

}


Measured memory_bytes: 512
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
4 2
1 3
2 4
---+/
/+---test
10 3
3 6
5 7
6 9
---+/
/+---test
100000 1
1 100000
---+/

void main(string[] args) {
  long N, M;
  readf(" %d %d ", &N, &M);

  long al, ar = long.max;
  foreach (m; 0..M) {
    long l, r;
    readf(" %d %d ", &l, &r);
    --l; --r;
    al.amax(l);
    ar.amin(r);
  }
  (ar < al? 0: ar - al+1).writeln;
}


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

const MOD: usize = 1_000_000_007;

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

    let mut ans = 0;
    let mut sum_a = 0;
    for i in (0..n).rev() {
        ans += sum_a * aa[i];
        ans %= MOD;
        sum_a += aa[i];
        sum_a %= MOD;
    }

    println!("{}", ans);
}


Measured memory_bytes: 5644
use std::io;
use std::cmp::max;
//use std::vec;
// fn sum_of_string(s: &String) -> u32 {
//     s.chars().fold(0, |acc, c| c.to_digit(10).unwrap_or(0) + acc)
//   }

fn main(){

    let mut n:String = String::new();

    io::stdin().read_line(&mut n).expect("Required Input");

    let _n: i128 = n.trim().parse().unwrap();

    let mut stol_height: i128 = 0;
    let mut input: String = String::new();
    let mut prev_height: i128 = 0;

    io::stdin().read_line(&mut input).expect("Input required");

    let values: Vec<i128> = input
            .split_whitespace()
            .map(|x| x.parse::<i128>())
            .collect::<Result<Vec<i128>, _>>()
            .unwrap();

    for i in values.iter(){

        if prev_height <= *i{
            prev_height = max(prev_height, *i);
            continue;
        }

        stol_height += prev_height-*i;

    }
    
    println!("{}", stol_height);

}

Measured memory_bytes: 7360
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
typedef long long ll;
using namespace std;
ll x,y;
int ans;
int main(){
	scanf("%lld%lld",&x,&y);
	ans=1;
	while (x*2<=y){
		x*=2;
		ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<int> p(n);
  int sum = 0;
  rep(i, n) {
    cin >> p[i];
    sum += p[i];
  }

  cout << sum - *max_element(all(p)) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>

using namespace std;

const int N = int(1e6);
int pref[N];
int suf[N];
int a[N];

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

	int n;

	cin >> n;

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

	for(int i = 1 ; i <= n ; i++){
		pref[i] = __gcd(a[i], pref[i - 1]);
	}

	for(int i = n ; i >= 1 ; i--){
		suf[i] = __gcd(a[i], suf[i + 1]);
	}

	int best = 0;

	for(int i = 1 ; i <= n ; i++){
		best = max(best, __gcd(pref[i - 1], suf[i + 1]));
	}

	cout << best << endl;

	return 0;
}


Measured memory_bytes: 8832
n,m = map(int,input().split())
b = [] 
for i in range(n+1):
  if i == 0 or i == 1:
    b.append(1)
  else:
    b.append(b[i-2]+b[i-1])

ans = 1
if m != 0:
  a = list(range(m))
  for i in range(m):
    a[i] = int(input())
    if i == 0:
      ans = ans*b[a[i]-1]%1000000007
    else:
      if a[i] == a[i-1]+1:
        ans = 0
      else:
        ans = ans*b[a[i]-a[i-1]-2]%1000000007
  ans = ans*b[n-a[m-1]-1]%1000000007
  print(ans)
else:
  print(b[n]%1000000007)

Measured memory_bytes: 463988
N=int(input())
S=list(str(input()))
ans=''
az={}
az_dic={}
for i in range(65,65+26):
    az[chr(i)]=i-65
    az_dic[i-65]=chr(i)
    

for p in S:
    c = (az[p]+N) % 26
    ans += az_dic[c]


print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main()
{
        int a,b,c,i = 0,f = 0,sum = 0;
        scanf("%d%d%d",&a,&b,&c);
        for(i= 1;i<=b;i++)
        {
                  sum+=a;
//printf("%d ",sum);
                  if(sum%b==c)
             {  f= 1;
                   break;}
}
if(!f)
printf("NO");
else
printf("YES");

return 0;
}

Measured memory_bytes: 128
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, y] <- getIntList

  let solve a b | a == 0 && b == 0 = if y `div` 1000 == n then (0, 0, n) else (-1, -1, -1)
                | otherwise        =
                  let c = n - a - b
                      b' = if b == 0 then 2000 else b - 1
                      a' = if b == 0 then a - 1 else a
                  in if c >= 0 && 10000*a + 5000*b + 1000*c == y
                     then (a, b, c)
                     else solve a' b'

  putStrLn $ case solve 2000 0 of
    (a, b, c) -> show a ++ " " ++ show b ++ " " ++ show c

Measured memory_bytes: 380
#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 r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

Measured memory_bytes: 256
/*alurquiza*/
//https://matcomgrader.com/problem/9623/dictionary-search/
//Segment Tree + binary search
#include <bits/stdc++.h>

using namespace::std;


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

	// freopen("milkvisits.in","r",stdin);
	// freopen("milkvisits.out","w",stdout);

	int N;
	cin >> N;

	std::vector<int> X(N);

	for(int i = 0;i < N;i++)
		cin >> X[i];

	int sol = INT_MAX;
	for(int i = 1;i <= 100;i++){
		int aux = 0;
		for(int j = 0;j < N;j++)
			aux += (X[j] - i) * (X[j] - i);
		sol = min(aux,sol);
	}

	cout << sol << '\n';

	return 0;
}

//g++ -std=c++11 -Wall DS.cpp -o main

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int w, n, a, b, t, i, temp;
    
    scanf("%d", &w);
    scanf("%d", &n);
    t = n;
    int lots[w];
    for (i = 0; i <= w; i++) {
        lots[i] = i;
    }
    while (--t >= 0) {
        scanf("%d,%d", &a, &b);
        temp = lots[a];
        lots[a] = lots[b];
        lots[b] = temp;
    }
    
    for (i = 1; i <= w; i++) {
        printf("%d\n", lots[i]);
    }
    return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


int main(){
    fIO

    int n;
    cin >> n;

    int ans = 0;
    for(int i = 1; i <= n; i++){
        int t = i;
        int cnt = 0;

        while(t){
            t /= 10;
            cnt++;
        }
        if(cnt & 1) ans++;
    }
    cout << ans;
}










Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s.length() == 2) {
		cout << s << endl;
		return 0;
	}
	else {
		cout << s[2] << s[1] << s[0] << endl;
	}
}


Measured memory_bytes: 768
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    A_arr = [A, (B + C)/2]
    B_arr = [B, (A + C)/2]
    C_arr = [C, (B + A)/2]
    i = 0
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        print 0
        exit()
    if (B + C) % 2 == 1 or (A + C) % 2 == 1 or (B + A) % 2 == 1:
        print 1
        exit()
    if A_arr[0] == A_arr[1] and B_arr[0] == B_arr[1] and C_arr[0] == C_arr[1]:
        print -1
        exit()

    while 1:
        if i >= 2:
            A_arr.append((A_arr[i - 1] + A_arr[i - 2])/2)
            B_arr.append((B_arr[i - 1] + B_arr[i - 2])/2)
            C_arr.append((C_arr[i - 1] + C_arr[i - 2])/2)
        if A_arr[i] % 2 == 1 or B_arr[i] % 2 == 1 or C_arr[i] % 2 == 1:
            break;

        i += 1
    print i
if __name__ == '__main__':
    main()


Measured memory_bytes: 2896
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

int a[51];
int main(void){
	int n=nextint();
	for(int i=1; i<=n; i++){
		a[i]=nextint();
	}
	int am=0, bm=0;
	int ami=1, bmi=1;
	int ai=0, bi=0;
	for(int i=1; i<=n; i++){
		if(a[i]<0){
			bi++;
			if(a[i]<bm){ bm=a[i]; bmi=i; }
		}else{
			ai++;
			if(a[i]>am){ am=a[i]; ami=i; }
		}
	}
	if(am>=-bm){
		printf("%d\n", bi+n-1);
		for(int i=1; i<=n; i++){
			if(a[i]<0){
				printf("%d %d\n", ami, i);
			}
		}
		for(int i=1; i<n; i++){
			printf("%d %d\n", i, i+1);
		}
	}else{
		printf("%d\n", ai+n-1);
		for(int i=1; i<=n; i++){
			if(a[i]>=0){
				printf("%d %d\n", bmi, i);
			}
		}
		for(int i=n-1; i>0; i--){
			printf("%d %d\n", i+1, i);
		}
	}
}


Measured memory_bytes: 1604
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F();
		var m = 0;
		var s = 0;
		for (int i = 0; i < N; i++)
		{
			var I = G();
			if (m < I[0])
			{
				m = I[0];
				s = I[0] + I[1];
			}
		}
		WriteLine(s);
	}
}


Measured memory_bytes: 17448
N =int(input())
A = [0]*N
a = 0
b = 0
for i in range(N):
    x = int(input())
    if x > a:
        b = a
        a = x
    elif x > b:
        b = x
    A[i] = x

for c in A:
    if c == a:
        print(b)
    else:
        print(a)

Measured memory_bytes: 12508
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <algorithm>

using namespace std;
const int NMAX = 10000;

void PrintArray(int* A, int N)
{
   cout << A[0]; 
   for (int k = 1; k < N;k++) {
     cout << " " << A[k] ; 
   }
   cout << endl;
}

void Swap(int& a, int &b) {
  int tmpA, tmpB;
  tmpA = a;
  tmpB = b;
  a = tmpB;
  b = tmpA;
}

int bubbleSort(int* A, int N){
  bool flag = true;
  int count = 0;
  while (flag) {
    flag = false;
    for (int i = 0; i < N -1; i++) {
      if (A[i] > A[i+1]) { 
        Swap(A[i], A[i+1]); 
        count += 1;
        flag = true;
      }
    }
  }
  return count;
} 

int main()
{
  int n;
  cin >> n;
  
  int x;
  int array[NMAX]; 
  for (int i = 0; i < n; i++) {
    cin >> x; 
    array[i] = x; 
  }
  int times;
  times = bubbleSort(array, n);
  PrintArray(array,n); 
  cout << times << endl;
  return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;

	ll n  , r;
	cin>>n>>r;
	if(n>=10){
		cout<<r<<endl;
	}
	else {
		ll ans = r+(100*(10-n));
		cout<<ans<<endl;
	}

	return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        
        static void Solve()
        {
            string s = Console.ReadLine();
            string[] table = { "maerd", "remaerd", "esare", "resare" };
            var worksz = new StringBuilder(s.Length);
            for(int i=0;i<s.Length;++i)
            {
                worksz.Append(s[s.Length - 1 - i]);
            }
            s = worksz.ToString();

            bool success = true;
            int idx = 0;
            while(true)
            {
                if(idx == s.Length)
                {
                    success = true;
                    break;
                }

                string part = s.Substring(idx);
                bool isMatch = false;
                foreach(var key in table)
                {
                    if (part.StartsWith(key))
                    {
                        isMatch = true;
                        idx += key.Length;
                    }
                }
                if( !isMatch)
                {
                    success = false;
                    break;
                }
            }
            string ans = success ? "YES" : "NO";
            Console.WriteLine(ans);
        }
        private static string MatchWord(string s, string key, string[] table)
        {
            foreach(var t in table)
            {
                if(t.StartsWith(key))
                    {
                    return t;
                }
            }
            return null;
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main(){
  std::string str;
  std::cin >> str;
  int p=700;
  if(str[0]=='o'){
    p += 100;
  }
  if(str[1]=='o'){
    p += 100;
  }
  if(str[2]=='o'){
    p += 100;
  }
  std::cout << p << std::endl;
  return 0;
}
  
     


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string K;
  cin >> K;
  int64_t L;
  cin >> L;
  int64_t dp[K.size()+1][L][2]; 
  for(int i=0; i<K.size()+1; i++){
    for(int j=0; j<L; j++){
      for(int k=0; k<2; k++){
        dp[i][j][k] = 0;
      }
    }
  }
  
  
  
  for(int i=0; i<10; i++){
    if(i < K.at(0) - '0'){
      dp[1][i%L][0] += 1;
    }
    if(i == K.at(0) - '0'){
      dp[1][i%L][1] += 1;
    }
  }
  
  
  int64_t MOD = 1e9+7;
  
  for(int i=1; i<K.size(); i++){
    for(int j=0; j<L; j++){
      for(int k=0; k<2; k++){
        for(int l=0; l<10; l++){
          int ni = i+1;
          int nj = (j+l) % L;
          int nk = k;
          if(k == 1 && l > K.at(i) - '0'){
            continue;
          }
          if(k == 1 && l < K.at(i) - '0'){
            nk = 0;
          }
          dp[ni][nj][nk] += dp[i][j][k];
          dp[ni][nj][nk] %= MOD;
        }
      }
    }
  }
  
  int64_t ans = dp[K.size()][0][0] + dp[K.size()][0][1] - 1;
  if(ans < 0){
    ans += MOD;
  }
  
  
  cout << ans << endl;
}



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

int main(){
  int N;
  cin>>N;
  int A[N];
  int maxA=0;
  int cnt=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    maxA=max(maxA,A[i]);
    if(A[i]>=maxA){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3632
import sys
from itertools import accumulate


MOD = 998244353
fin = sys.stdin.readline
N = int(fin())
a_list = [int(fin()) for _ in range(N)]
max_a = max(a_list)
sum_a = sum(a_list)

dp = [[0] * (sum_a + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i, a in enumerate(a_list, start=1):
    for m in range(len(dp[i])):
        dp[i][m] = 2 * dp[i - 1][m] + (dp[i - 1][m - a] if m - a >= 0 else 0)
        dp[i][m] %= MOD
# print(dp)
# print(sum_a)
if sum_a % 2 == 0:
    bound_dp = [[0] * (sum_a // 2 + 1) for _ in range(N + 1)]
    bound_dp[0][0] = 1
    for i, a in enumerate(a_list, start=1):
        for m in range(len(bound_dp[i])):
            bound_dp[i][m] = bound_dp[i - 1][m] + (bound_dp[i - 1][m - a] if m - a >= 0 else 0)
            bound_dp[i][m] %= MOD
    # print(bound_dp)
    print((3 ** N - 3 * sum(dp[N][sum_a // 2:]) + 3 * bound_dp[N][sum_a // 2]) % MOD)
else:
    print((3 ** N - 3 * sum(dp[N][sum_a // 2 + 1:])) % MOD)


Measured memory_bytes: 351752
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Meal struct {
	a, b, c int
}

type Meals []*Meal

func (a Meals) Len() int           { return len(a) }
func (a Meals) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Meals) Less(i, j int) bool { return a[i].c > a[j].c }

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	c := make(Meals, n)
	for i := 0; i < n; i++ {
		a, b := nextInt(), nextInt()
		c[i] = &Meal{a, b, a + b}
	}
	sort.Sort(c)

	taka, aoki := 0, 0
	for i := range c {
		if i%2 == 0 {
			taka += c[i].a
		} else {
			aoki += c[i].b
		}
	}

	puts(taka - aoki)
}


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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int x = sc.nextInt();

		int[] m = new int[n];
		int min = Integer.MAX_VALUE;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			m[i] = sc.nextInt();
			min = Math.min(min, m[i]);
			sum += m[i];
		}

		pr.println(n + (x - sum) / min);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;

int main() {

    string s;
    cin>>s;
    int a=0,b=0,c=0;

    rep(i,s.size()) {
        if(s[i]=='a') {
            a++;
        }
        else if(s[i]=='b') {
            b++;
        }
        else {
            c++;
        }
    }
    if(abs(a-b)<=1&&abs(a-c)<=1&&abs(b-c)<=1) {
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }
  
 return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    boolean flg=false;
    long k;
    for(k=0;k<1000000000;k++){
      if(Math.abs(a-k)==Math.abs(b-k)){
        flg=true;
        break;
      }
    }
    if(flg){
      System.out.println(k);
    }else{
      System.out.println("IMPOSSIBLE");
    }
  }
}

Measured memory_bytes: 22612
#include<cstdio>

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	rep(_,n){
		int y,m,d; scanf("%d%d%d",&y,&m,&d);
		int ans=0;
		for(;y<1000;ans++){
			if(d<(y%3==0||m%2==1?20:19)) d++;
			else if(m<10) d=1, m++;
			else d=1, m=1, y++;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 760
def solve():
    N = int(input())
    A = [[0,0,0]]
    for _ in range(N):
        a = list(map(int, input().split()))
        A.append(a)

    ans = 'Yes'

    for i in range(N):
        t1, x1, y1 = A[i]
        t2, x2, y2 = A[i+1]

        time = t2 - t1
        x = abs(x2 - x1)
        y = abs(y2 - y1)

        if time < x+y or (time+x+y) % 2 != 0:
            ans = 'No'

    return ans

print(solve())


Measured memory_bytes: 63960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;;
#define f(i,a,b) for(int i=a;i<=b;i++)
const int M=1e6;
int main(){
    double n,x,t;
    cin>>n>>x>>t;
    cout<<(int)(ceil(n/x)*t);
}


Measured memory_bytes: 3664
#include <stdio.h>

int main()
{
  	int a,b,c;
  
  	scanf("%d",&a);
    scanf("%d",&b);
  
      	if(a==1)
        {if(b==2)
        {  printf("3");
        }
  			else
            {  printf("2");
            }
        }
       	else if(a==2)
        {
        	if(b==3)
            {  printf("1");
            }
  			else
            { printf("3");
            }
        }
               
       else
       {	if(b==1)
       { printf("2");
       }
  			else
            {   printf("1");
            }
       }
            
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n, ans;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        ll j = n / i;
        ans += i * j * (j + 1) / 2;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
<?php
$table = array(
	48.0 => "light fly",
	51.0 => "fly",
	54.0 => "bantam",
	57.0 => "feather",
	60.0 => "light",
	64.0 => "light welter",
	69.0 => "welter",
	75.0 => "light middle",
	81.0 => "middle",
	91.0 => "light heavy",
	PHP_INT_MAX => "heavy",
);

main();

function main() {
	while ($line = trim(fgets(STDIN))) {
		echo judgeClass($line) . "\n";
	}
}

function judgeClass($w) {
	global $table;
	foreach ($table as $boundary => $name) {
		if ($w <= $boundary) {
			return $name;
		}
	}
	return "heavy";
}

Measured memory_bytes: 6604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,x; cin>>a>>b>>x;
    if(a<=x && x<=a+b){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3568
#include <stdio.h>

constexpr char* S_OUT[31] = {
    "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n",
    "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "20\n",
    "21\n", "22\n", "23\n", "24\n", "25\n", "26\n", "27\n", "28\n", "29\n", "30\n"
};

constexpr unsigned int InputSize = 3e6;
constexpr unsigned int OutputSize = 3e5;
char Input[InputSize];
char* pointer = Input;
char Output[OutputSize];
char* m_buffer = Output;

inline unsigned int getInt(void){
    unsigned int res = 0;
    do{ res = 10 * res + (*(pointer++) - '0'); } while(*pointer >= '0');
    return res;
}

inline void out(int v){
    char* str = S_OUT[v];
    while(*str) *(m_buffer++) = *(str++);
}

unsigned int n;
unsigned int N;
constexpr unsigned int SIZE = (1U << 19) + 1;
unsigned int data[2 * SIZE];

inline void set(void){
    n = getInt(); N = 1U << (31 - __builtin_clz(n)); while(N < n) N <<= 1;
    ++pointer; // \n
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j) data[j] = 1U << (*(pointer++) - 'a');
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1U];
}

inline void query(void){
    pointer += 3;
    if(*(pointer - 2) == '1'){
        unsigned int index = getInt() - 1;
        unsigned char idx = *((++pointer)++) - 'a';
        data[index += N] = 1U << idx;
        while(index >>= 1) data[index] = data[index << 1] | data[(index << 1) | 1U];
    }
    else{
        unsigned int l = getInt() + N - 1; pointer++;
        unsigned int r = getInt() + N;
        unsigned int res = 0;
        while(l < r){
            if(l & 1) res |= data[l++]; l >>= 1;
            if(r & 1) res |= data[--r]; r >>= 1;
        }
        out(__builtin_popcount(res));
    }
}

int main(void){
    fread(Input, sizeof(char), InputSize, stdin);
    set(); ++pointer;
    unsigned int q = getInt();
    while(q--) query();
    setvbuf(stdout, 0, _IONBF, 0);
    fputs(Output, stdout);
    return 0;
}

Measured memory_bytes: 6400
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main() {
  char S[200010];
  char T[200010];
  int a[26] = {};
  int b[26] = {};
  scanf("%s", S);
  scanf("%s", T);
  int i;
  for (i = 0; i < strlen(S); i++) {
    int si = (int)S[i] - 97;
    int ti = (int)T[i] - 97;
    if (a[si] > 0 || b[ti] > 0) {
      if (a[si] != ti || b[ti] != si) {
	printf("No\n");
	return 0;
      }
    } else {
      a[si] = ti;
      b[ti] = si;
    }
  }
  printf("Yes");
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stack>

using namespace std;

void solve()
{
	stack<int> S;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		char p;
		int x;
		cin >> p >> x;
		if (p == '(')
		{
			if (!S.empty())
			{
				x += S.top();
				S.pop();
			}
			S.push(x);
		}
		else
		{
			if (S.empty() || S.top() < x)
			{
				cout << "NO" << endl;
				return;
			}
			else
			{
				x = S.top() - x;
				S.pop();
				if (x > 0)
				{
					S.push(x);
				}
			}
		}
	}
	if (S.empty())
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

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

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N],sum,mark[N];

int main()
{
    fast;
    cin>>n;
    int i=2;
    mark[n]++;
    int q=n;
    while(i++)
    {
        if(q%2==0)
            q=q/2;
        else
            q=q*3+1;
        if(mark[q])
        {
            cout<<i-1;
            return 0;
        }
        mark[q]++;
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<ctype.h>

std::string s;
std::string::iterator it;

int term();
int fact();

// 計算
int expr()
{
 	int p = term();
	
	// + or -
	while( *it == '+' || *it == '-' ){
	 	if( *it == '+' ){
		 	it++;
			int q = term();
			p += q;
		}
		else{
		 	it++;
			int q = term();
			p -= q;
		}
	}
	
	return p;
}

// 項を計算
int term()
{
	int p = fact();
	
	while( *it == '*' || *it == '/' ){
	 	if( *it == '*' ){
		 	it++;
			int q = fact();
			p *= q;
		}
		else{
		 	it++;
			int q = fact();
			p /= q;
		}
	}
	
	return p;
}

// 括弧内 or 数字
int fact()
{
 	if( *it == '(' ){
	 	it++;
		int p = expr();
		it++;
		
		return p;
	}
	else{
	 	int p = 0;
		
		while( isdigit( *it ) ){
			p *= 10;
			p += *it - '0';
			it++;
		}
		
		return p;
	}
}

int main()
{
	int n;
	std::cin >> n;
	
	while( n-- ){
		std::cin >> s;
		s[s.size()-1] = '\0';
		it = s.begin();
		std::cout << expr() << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 *
 * @author 97797
 */
public class Main {
    public static void main(String[] args) throws IOException {

          System.out.println(new Main().run(args, System.in));
    }
    public String run(String[] args, InputStream in) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String[] val = reader.readLine().replaceAll("\\s+", " ").split(" ");

       long N = Long.parseLong(val[0]);
       long A = Long.parseLong(val[1]);
       long B = Long.parseLong(val[2]);        
                        
        String rtn = null;

        if (A == B) {
            rtn = "1";
        } else if (A > B) {
            rtn = "0";
        } else if (N == 1) {
            rtn = "0";
        } else if (N == 2) {
            rtn = "1";
        } else {
            long c = (N-2)*(B-A) + 1;
            rtn = String.valueOf(c);
        }        
 
        return rtn;
    }        

}


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

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

    vector< pair<int64_t, int64_t> > a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }

    sort(a.begin(), a.end());
    
    for(int i = 0; i < n; i++) cout << a[i].second << " ";
    cout << endl;

    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll n; cin >> n;
  vll v(n); V(v);
  Sort(v);
  ld ans = (v[0] + v[1]) / 2.;
  for(ll i = 2;i < n;i++)
  {
    ans = (ans + v[i]) / 2.;
  }
  fin(ans);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 256
/*
lakshaygpt28
Lakshay Gupta
*/

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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

int main() {
    fast_io();
    string s;
    cin >> s;
    sort(all(s));
    if (s[0] == s[1] and s[2] == s[3] and s[2] != s[1]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


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

int main() {
  int a,b,c,d,N;
  cin >> N;
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = N%10;
  if(a == b && b == c){
    cout << "Yes" << endl;
  }
  else if(b == c && c == d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256