akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [d, t, s] <- getIntList
  if t >= ceiling (((/) `on` fromIntegral) d s) 
    then putStrLn "Yes"
    else putStrLn "No"


-- Input

getInt :: IO Int
getInt = readLn
second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine
 
getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntegerList :: IO [Integer]
getIntegerList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

-- 組み合わせ
powerset :: [a] -> [[a]]  
powerset xs = filterM (\x -> [True, False]) xs


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  
  for(int i = 0;i<M;i++){
    cin >> L.at(i) >> R.at(i);
  }
  
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  
  if(L.at(M-1) > R.at(0)){
    cout << "0" << endl;
  }
  
  else if(L.at(M-1) <= R.at(0)){
    cout << R.at(0) - L.at(M-1) + 1 <<endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define     FasterIO        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define     Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define     watch(a)        cout<<fixed<<setprecision(a)
#define     lp(i,a,b)       for(int i=a;i<b;i++)
#define     Endl            "\n";
#define     tab             "\t"
#define     reset(a,b)      memset(a,b,sizeof(a));
#define     sfl(a)          scanf(" %lld", &a);
#define     sf(a)           scanf(" %d", &a);
#define     srt(a)          sort(a.begin(),a.end());
#define     pi              2*acos(0.0)
const int sz=1e5+9;
const ll inf=1e18L+9;
ll dp[sz];


void solve(){
    reset(dp,inf);
    int n,w;
    sf(n);
    sf(w);
    vector<pair<ll,int>>v(n);
    dp[0]=0;
    int pnt=0;
    lp(i,0,n){
       sfl(v[i].first);
       sf(v[i].second);
       pnt+=v[i].second;
    }
    //bug(pnt, 1);
   // sort(v.begin(),v.end(),com);
    for(int i=0;i<n;i++){

        for(int j=pnt-v[i].second;j>=0;j--){
            dp[j+v[i].second]=min( dp[j+v[i].second],dp[j]+v[i].first);
        }

    }
   // bug("140 dp",dp[140]);
    for(int i=pnt;i>=0;i--){
        if(dp[i]<=w){
            printf("%d\n",i);
            return;
        }
    }
}

int main(){
    //FasterIO;
    #ifndef ONLINE_JUDGE
    //    freopen("1.txt","r",stdin);
    #endif
    //int t;
//cin>>t;
   // while(t--)
        solve();
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

ll gcd(ll x, ll y) {
    if(y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    --a;

    ll ac = a / c, ad = a / d, bc = b / c, bd = b / d;

    ll lcm = (c / gcd(c, d)) * (d / gcd(c, d)) * gcd(c, d);

    ll ans = (b - bc - bd + b / lcm) - (a - ac - ad + a / lcm);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Monad

main :: IO()
main = do
  _ <- getLine
  as <- fmap (map read . words) getLine :: IO [Int]
  _ <- getLine
  ms <- fmap (map read . words) getLine :: IO [Int]
  solve as ms

solve :: [Int] -> [Int] -> IO()
solve _ [] = return ()
solve as (m:ms) = do
  putStrLn $ if innerSolve as m then "yes" else "no"
  solve as ms
    where
      innerSolve :: [Int] -> Int -> Bool
      innerSolve _ 0 = True
      innerSolve [] m = False
      innerSolve (a:as) m = innerSolve as m || innerSolve as (m - a)



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

#define rep(i,n) for(int i=0; i<(n); i++)
#define lep(j,n) for(int j=0; j<(n); j++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define leps(j,n) for(int j=1; j<(n); j++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

#define return(Z) re:(Z)

long long h[10000010],x[10000010],z[10000010];

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin>>s;
    int a=0;
    rep(i,3) {
        if(s[i]=='1') a++;
    }
    cout<<a<<'\n';
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define INF 1LL << 60
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 100005;
vector<int> nd[N];
int st[N];
int n,m;

inline int fdist(int x,int y){
	if(y >= x)return y - x;
	else return m - x + y - 1 + 1;
}

int main(){
	fast_io();
	cin >> n >> m;
	int a[n];
	cu(i,0,n)cin >> a[i];	
	ll tot = 0;
	ll ans = 0;
	int cnt = 0;
	cu(i,1,n){
		int x = a[i-1],y = a[i];
		tot += min(fdist(x,y),fdist(1,y) + 1);
		if(x > y){
			++cnt;
			++st[(x==m?1:x+1)];	
			nd[y].pb(x);
		}
		else{
			++st[(x==m?1:x+1)];	
			nd[y].pb(x);
		}
	}
	ans = tot;
	cnt -= nd[1].size();	
	for(int x: nd[1]){
		tot += fdist(x,1) - 1;
	}
	fu(i,2,m){
		tot-=cnt;
		gmin(ans, tot);
		cnt += st[i];
		cnt -= nd[i].size();	
		for(int x: nd[i]){
			tot += fdist(x,i) - 1;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5760
from bisect import bisect
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    ans = max(ans, i + bisect(b, tmp) - 1)
print(ans)

Measured memory_bytes: 47352
package main

import (
	"fmt"
)

func main() {
	var n int
	var s, t string
	var ans string
	fmt.Scan(&n, &s, &t)
	for i := 0; i < n; i++ {
		ans += string(s[i])
		ans += string(t[i])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(),a = sc.nextInt(),b = sc.nextInt();
		System.out.println(Math.abs(x-a) < Math.abs(b-x) ? "A" : "B");
	}
}


Measured memory_bytes: 21972
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(double &x){
  int k;
  int m=0;
  int p=0;
  double r = 1;
  x = 0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m = 1;
      break;
    }
    if(k=='.'){
      p = 1;
      break;
    }
    if('0'<=k&&k<='9'){
      x = k - '0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k=='.'){
      p = 1;
      continue;
    }
    if(k<'0'||k>'9'){
      break;
    }
    if(p){
      r *= 0.1;
      x += r * (k - '0');
    }
    else{
      x = x * 10 + k - '0';
    }
  }
  if(m){
    x = -x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
int main(){
  double R;
  rd(R);
  wt_L(2*PI*R);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200419-1

// --- original code ---
// {
//   double R;
//   rd(R);
//   wt(2*PI*R);
// }


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

int main(void) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	bool win_tak = true;
	while (true) {
		C -= B;
		if (C <= 0) {
			win_tak = true;
			break;
		}
		A -= D;
		if (A <= 0) {
			win_tak = false;
			break;
		}
	}

	cout << (win_tak ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> PII;
int a,b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a

int main(){
  int n,d,cnt=1;
  cin>>n>>d;
  while(true){
  if((1+2*d)*cnt>=n){break;}
    cnt++;
  }
  cout<<cnt<<endl;
return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();// 1円硬貨の枚数

    System.out.println((N % 500) <= A ? "Yes" : "No");
  }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        boolean[] exists = new boolean[b];
        for (int i = a; i <= a * b; i += a) {
            int num = i % b;
            exists[num] = true;
        }
        
        if (exists[c]) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21844
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, a = 0, b = 0;
	cin >> n >> a >> b;
	if (n == 1)
		cout << (a == b ? "1" : "0");
	else if (a > b)
		cout << "0";
	else
		cout << 1ll * (b - a)*(n - 2) + 1ll;
	cout << endl;
}

Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n){
        cin>>a.at(i);
    }

    int kd = 0;
    int m = 1;
    REP(i,n){
        if(a.at(i) == m){
            m++;
            continue;
        } else {
            kd++;
        }

    }
    if(m==1){
        cout<<-1<<endl;
    } else {
    cout<<kd<<endl;
    }
    // cout << ans << endl;
    return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  int n,c,k; cin >> n >> c >> k;
  vi t(n); rep(i, n) cin >> t[i];
  sort(all(t));
  int ans = 0, time = 0, capa = 0;
  int i = 0;
  while(i < n){
    time = t[i];
    capa = 1;
    int j = i + 1;
    while(j < n){
      if(capa < c and t[j] <= time + k){
	capa++;
	j++;
      }else break;
    }
    ans++;
    i = j;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a[200001];
  cin >> n;
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a, a+n);
  if(a[n/2]==a[n/2-1]) cout << 0 << endl;
  else cout << (a[n/2]-a[n/2-1]) << endl;
  return 0; 
}


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

int func(int a){
    return (a+10-1)/10 *10;
}

void func2(int &a, int &b){
    if(a%10==0 || (b%10!=0 && b%10 < a%10)) swap(a, b);
}        

int main() {
    int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    func2(a, b);
    func2(a, c);
    func2(a, d);
    func2(a, e);
    cout << a + func(b) + func(c) + func(d) + func(e) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    // aとbが等しい
    if (a == b && a != c) {
        cout << "Yes" << endl;
    } else if (a == c && a != b) {
        cout << "Yes" << endl;
    } else if (b == c && b != a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    ll a, b, c;
    cin >> a >> b >> c;
    c = min(c, a + b + 1);
    cout << b + c << "\n";
    return 0;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = gets.split.map(&:to_i)
u = (x2 - x1) + (y2 - y1) * 1i
gets.to_i.times do
  x, y = gets.split.map(&:to_i)
  v = x - x1 + (y - y1) * 1i
  d, c = (u.conj * v).rect
  case
  when c > 0
    puts 'COUNTER_CLOCKWISE'
  when c < 0
    puts 'CLOCKWISE'
  when d < 0
    puts 'ONLINE_BACK'
  when d > (u.conj * u).real
    puts 'ONLINE_FRONT'
  else
    puts 'ON_SEGMENT'
  end
end

Measured memory_bytes: 8896
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int n;
    cin >> n;
    V<ll> cnt(n), a(n);
    rep(i, n) {
        cin >> a[i];
        cnt[--a[i]]++;
    }
    ll sum = 0;
    rep(i, n) sum += (cnt[i] - 1) * cnt[i] / 2;
    rep(i, n) { cout << sum - cnt[a[i]] + 1 << endl; }

    return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<list>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main(){
    int N, T;
    cin >> N;
    cin >> T;
    long A[N] = {};
  	for (int i = 0; i < N; i++){
      cin >> A[i];
    }
  
  	long min = A[0];
  	long maxDiff = 0;
    int maxDiffCount = 0;
  	for (int i = 1; i < N; i++){
      long diff = A[i] - min;
      if (diff > maxDiff){
        maxDiff = diff;
        maxDiffCount = 1;
      }
      else if (diff == maxDiff){
        maxDiffCount++;
      }
      
      if (A[i] < min){
        min = A[i];
      }
    }
  
    cout << maxDiffCount <<endl;
}


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

int main(void)
{
  auto a = std::string{};
  auto b = std::string{};
  auto c = std::string{};
  char next = 'a';
  std::cin >> a >> b >> c;
  while (true) {
    switch (next) {
    case 'a':
      if (!a.length())
        goto exit;
      next = a[0];
      a = a.substr(1);
      break;
    case 'b':
      if (!b.length())
        goto exit;
      next = b[0];
      b = b.substr(1);
      break;
    case 'c':
      if (!c.length())
        goto exit;
      next = c[0];
      c = c.substr(1);
      break;
    }
  }
exit:
  std::cout << std::string{next - 0x20} << std::endl;
}


Measured memory_bytes: 256
n=int(input())
a=[list(map(int, input().split())) for _ in range(2)]

ans=0
s=sum(a[0]+a[1])
for i in range(n):
    tmp_ans=s-(sum(a[1][:i])+sum(a[0][i+1:]))
    ans=max(ans,tmp_ans)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 998244353;

ll rep_power_modM(ll a, ll n, ll M = MOD){
    if(n == 0)return 1;
    if(n%2 == 0){ll tmp = rep_power_modM(a,n/2,M); return tmp*tmp%M;}
    return a*rep_power_modM(a,n-1,M)%M;
}

int main(){
	int N; cin>>N;
	map<int, int> total;
	ll ans = 1;
	rep(i,N){
		int t; cin>>t;
		if(i == 0){if(t != 0)ans = 0;}
		else {if(t == 0)ans = 0;}
		total[t]++;
	}
	int i = 0;
	ll bf = 1;
	for(auto x:  total){
		if(x.first != i)ans = 0;
		ans *= rep_power_modM(bf, x.second, MOD);
		ans %= MOD;
		bf = x.second;
		++i;
	}
	if(ans < 0)ans += MOD;
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;

int main() {
    int R, C, K, r, c, v;
    cin >> R >> C >> K;
    vector<vector<int>> t(R, vector<int>(C, 0));
    rep(i, K) {
        cin >> r >> c >> v;
        t[r - 1][c - 1] = v;
    }
    vector<vector<vector<ll>>> dp(R, vector<vector<ll>>(C, vector<ll>(4, 0)));
    dp[0][0][1] = t[0][0];
    rep(i, R) {
        rep(j, C) {
            rep(k, 4) {
                if (j < C - 1) {
                    dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                    if (k < 3) {
                        dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + t[i][j + 1]);
                    }
                }
                if (i < R - 1) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                    dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + t[i + 1][j]);
                }
            }
        }
    }
    ll ans = 0;
    rep(i, R) {
        rep(j, C) {
            rep(k, 4) {
                ans = max(ans, dp[i][j][k]);
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 670952
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[200005];

// A(Bを数個)A(Bを数個)..A(Bを数個) 
// という列の作り方が何通りあるか、を求める
// ただし列の長さをn、Bを重ねるのは各箇所について0個以上k個以下とする
// また両端がつながっているものとする。
ll func( int n, int k)
{
    if(k>=n) k=n-1;

#ifdef _DEBUG
    printf("%d %d\n", n, k);
#endif
    vector<ll> dp(n+1);   // dp[i]: func(i,k)と同じ。ただし両端がつながっていなくてAから始まるものとする。
    vector<ll> sdp(n+2);  // dpの累積和
    dp[0]=1;
    sdp[0]=0; sdp[1]=1;
    int i;
    for(i=1; i<=n; i++) {
        dp[i]=(sdp[i]-sdp[MAX(0,i-k-1)]+MOD)%MOD;
        sdp[i+1]=(sdp[i]+dp[i])%MOD;
    }
    ll ans = dp[n];

    // dp[n]は、Aから始まるものだけを数えたもの。
    // 両端がつながっている状況で、Bから始まるものを数える
    // Bが最初にp個重なった場合を考えて足し合わせればよい
    int p;
    for(p=1; p<=k; p++) {
        // dp[n-p-1],dp[n-p-2],..という(k-p+1)個を足し合わせればよい
        ans = (ans + sdp[n-p] - sdp[n-k-1] +MOD)%MOD;
    }

    return ans;
}

int main(int argc, char* argv[])
{
    int n, m;
    scanf("%d%d", &n, &m);
    scanf("%s", str);

    char c=str[0];
    int min_odd=INF-1;
    int cnt_first=-1;
    int cnt=0;
    int cnt2=0;
    int i;
    for(i=0; i<m; i++) {
        if(str[i]==c) {
            cnt++;
        }
        else {
            if(cnt>0) {
                if(cnt_first<0) cnt_first=cnt;
                if(cnt%2) min_odd = MIN(min_odd, cnt);
                cnt=0;
            }
            cnt2++;
        }        
    }

    if(cnt2==0) {
        printf("%lld\n", func(n, 1));
    }
    else {
        if(n%2==0) {
            int k = (cnt_first%2==0? cnt_first+1: cnt_first);
            if(min_odd>0) k = MIN(k, min_odd);
            printf("%lld\n", func(n/2, (k-1)/2) *2 %MOD);
        }
        else {
            printf("0\n");
        }
    }

    return 0;
}



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

using namespace std;

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

	int a[100010];
	// don't use a[0]
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int buttonIndex = 1;

	set < int >pushedButton;

	while (a[buttonIndex] != 2 && pushedButton.count(a[buttonIndex]) == 0) {
		pushedButton.insert(a[buttonIndex]);
		buttonIndex = a[buttonIndex];
	}

	if (a[buttonIndex] == 2) {
		cout << pushedButton.size() + 1 << endl;
	} else {
		cout << -1 << endl;
	}

	return 0;
}


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

typedef long long ll;
const int MAXN = 100010;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int n, m;
int a[MAXN], res;
int st[MAXN], to[MAXN<<1];
int nxt[MAXN<<1], e;
inline void Add(int u, int v) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e;
}

ll ans;
bool ban[MAXN], vis[MAXN];
int b[MAXN], cnt;

inline void dfs(int u) {
	int i;
	vis[u] = true;
	if(a[u] < a[res]) res = u;
	for(i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		if(vis[v]) continue;
		dfs(v);
	}
}

int main() {

	int i;
	n = read(), m = read();
	if(m == n-1) {
		printf("0\n");
		return 0;
	}
	if(2*n-2*m-2 > n) {
		printf("Impossible\n");
		return 0;
	}
	generate(a+1, a+n+1, read);
	for(i = 1; i <= m; i++) {
		int u = read()+1, v = read()+1;
		Add(u, v), Add(v, u);
	}
	for(i = 1; i <= n; i++) 
		if(!vis[i]) {
			res = i, dfs(i);
			ban[res] = true, ans += a[res];
		}
	for(i = 1; i <= n; i++) 
		if(!ban[i]) b[++cnt] = a[i];
	sort(b+1, b+cnt+1);
	for(i = 1; i <= n-m-2; i++) ans += b[i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3200
main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine :: IO [Integer]
  let br = b - b `div` c - b `div` d + b `div` lcm c d
  let ar = (a - 1) - (a - 1) `div` c - (a - 1) `div` d + (a - 1) `div` lcm c d
  print $ br - ar

Measured memory_bytes: 508
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval<newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  string S; cin >> S;
  int n = S.size();
  int m = numeric_limits<int>::max();
  rep(i,0,n-2){
    int a = atoi(S.substr(i,3).c_str());
    int d = abs(a-753);
    if(d<m) m=d;
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N, std::vector<long long> A){
    long double ans = 0.0;
    REP(i, N)
        ans += 1.0 / (long double)A[i];
    ans = 1.0 / ans;
    printf("%.5Lf\n", ans);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main(){
    int hnum,wnum;
    
    cin >>hnum>>wnum;
    string data[hnum+2];
    for(int i = 1 ; i <=hnum; i++){
        cin>>data[i];
        data[i] = "#"+data[i]+"#";
    }
    string sharp ="#";
    for (int j = 1; j<=wnum+2; j++){
        cout<<sharp;
    }
    cout<<endl;
    for(int i = 1 ; i <= hnum; i++){
        cout<<data[i]<<endl;
    }
    for (int j = 1; j<=wnum+2; j++){
        cout<<sharp;
    }
    cout<<endl;
   
}

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

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)x.size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define debug(x) cerr << "  - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << "  - " << #x << ": " << x << "\t\t" << #y << ": " << y << endl;
#define debugv(v, n) cerr << #v << " : " << " "; for(int i = 0; i < n; i++) cerr << "\t" << #v << "[" <<  i <<  "]" <<  " : " << v[i] << "\n"; cerr << endl;
#define sep() cerr << "--------------------" << endl;

typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 1234;

int a[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++)
		for(int j = i + 1; j < n; j++) {
			sum += a[i] * a[j];
		}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    char b;
    cin >> b;
    switch (b)
    {
        case 'A':
            cout << 'T';
            break;
        case 'C':
            cout << 'G';
            break;
        case 'G':
            cout << 'C';
            break;
        case 'T':
            cout << 'A';
            break;
    }
    cout << endl;
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	char tmp = s[0];
	int count = 0;
	for(int i = 1; i < s.size(); i++){
		if(s[i] != tmp) {
			count++;
			tmp = s[i];
		}
	}
	cout << count;
	return 0;
}




Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = 998244353;

ll fact[N], a[N], f[N];

ll nCr(int n, int r) {
    return fact[n] / (fact[r] * fact[n - r]);
}

long long power(long long b, long long p, long long MOD = 998244353) {
    long long res = 1;
    b %= MOD;
    for (; p; p >>= 1LL) {
        if (p & 1)res = (res * b) % MOD;
        b = (b * b) % MOD;
    }
    return res % MOD;
}

class BCountingOfTrees {
public:
    void solve(istream &cin, ostream &cout) {
        fact[0] = 1, fact[1] = 1;
        for (ll i = 2; i <= int(1e5) + 2; i++) {
            fact[i] = fact[i - 1] * i;
            fact[i] %= MOD;
        }
        int n;
        cin >> n;
        ll mx = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            f[a[i]]++;
            mx = max(mx, a[i]);
        }
        if (f[0] != 1 || a[0] != 0) {
            clr(f, 0);
            clr(fact, 0);
            clr(a, 0);
            return (void) (cout << 0 << el);
        }
        ll ans = 1;
        for (int i = 1; i <= mx; i++) {
            if (f[i] == 0)
                return (void) (cout << 0 << el);
            ans *= power(f[i - 1], f[i]);
            ans %= MOD;
        }
        cout << ans << el;
        clr(f, 0);
        clr(fact, 0);
        clr(a, 0);
    }
};

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    BCountingOfTrees solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> activity(n);
    rep(i, n) {
        cin >> activity[i].second; // 開始時刻
        cin >> activity[i].first; // 終了時刻
    }
    sort(activity.begin(), activity.end()); // 終了時刻の早い順にソート
    stack<pair<int,int>> s; // 参加するアクティビティを追加
    s.push(activity[0]); // 終了時刻が最も早いもの
    for (int i = 1; i < n; i++) {
        pair<int,int> prev = s.top();
        if (activity[i].second > prev.first) { // 前の終了時刻より後で最も終了時刻が早いもの
            s.push(activity[i]);
        }
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 4364
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s;
    string temp;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        s.push_back(temp);
    }
    sort(s.begin(), s.end());

    string sum;
    for (int i = 0; i < n; ++i) sum += s[i];

    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<pair<int,int> ,int>mp;
int color[100005],mx=0;
vector<int>adj[100005];
void dfs(int u,int par)
{
    int cl=1;
    for(int v:adj[u])
    {
        if(v!=par)
        {
            if(cl==color[mp[{par,u}]])
                cl++;
            mx=max(cl,mx);
            color[mp[{u,v}]]=cl;
            dfs(v,u);
            cl++;
        }
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        mp[{u,v}]=i;
        mp[{v,u}]=i;
    }
    dfs(1,0);
    cout<<mx<<endl;
    for(int i=1;i<=n-1;i++)
        cout<<color[i]<<endl;
    return 0;
}


Measured memory_bytes: 18944
n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]

f = True
for i in range(n):
    if i == 0:
        l = x[0][0] - (x[0][1] + x[0][2])
        if l < 0 or l % 2 != 0:
            f = False
            break
    else:
        l = (x[i][0] - x[i-1][0]) - (x[i][1]-x[i-1][1] + x[i][2]-x[i-1][2])
        if l < 0 or l % 2 != 0:
            f = False
            break

print('Yes' if f else 'No')

Measured memory_bytes: 27300
w , h , n=map(int, input().split())
W = [1]*w
H = [1]*h

for i in range(n):
    x,y,a=map(int, input().split())
    if a == 1:
        for i in range(x):
            W[i] = 0
    if a == 2 :
        for i in range(x,w):
            W[i] = 0
    if a == 3:
        for i in range(y):
            H[i] = 0
    if a == 4:
        for i in range(y,h):
            H[i] = 0
print(sum(W)*sum(H))

Measured memory_bytes: 9144
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

alice = 0
bob = 0
A.sort()

for i in range(n):
    if i % 2 == 0:
        alice += A[i]
    else:
        bob += A[i]

print(abs(alice - bob))

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

int f(int i, int j, int k){
    return 10000*i + 5000*j + 1000*k;
}

int main(){
    int n, y;
    cin >> n >> y;
    int a = -1;
    int b = -1;
    int c = -1;
    for(int i = 0; i <= n; i++){
        if(f(i,0,0) > y){
            break;
        }
        for(int j = 0; j <= n; j++){
            if(i+j > n || f(i,j,n-i-j) > y){
                break;
            }
            if(f(i, j, n-i-j) == y){
                a = i;
                b = j;
                c = n - i - j;
                break;
            }
        }
        if(a != -1 && b != -1 && c != -1){
            break;
        }
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  fin((n + 999) / 1000 * 1000 - n);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll N;
  cin>>N;
  vector<LP> P(N);
  rep(i,N){
    ll a,b;
    cin>>a>>b;
    P[i].second=a;
    P[i].first=b;
  }
  
  sort(P.begin(),P.end());
  ll count=0;
  bool ok=true;
  rep(i,N){
    count+=P[i].second;
    if(count>P[i].first) ok=false;
  }
  
  if(ok) Yes();
  else No();
}

  
    

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    if(a == 0) PR(1);
    else if(b == 0) PR(2);
    else if(c == 0) PR(3);
    else if(d == 0) PR(4);
    else if(e == 0) PR(5);

    return 0;
}

/*



*/

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int odd = 0;
	for(int i = 0; i < n; ++i){
		int a;
		cin >> a;
		if(a % 2 == 1){ ++odd; }
	}
	cout << (odd % 2 == 1 ? "NO" : "YES") << endl;
	return 0;
}



Measured memory_bytes: 256
import math
import copy
import bisect








def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input().split())
a=nCast(input().split())

def myKey(a):
    return a[0]


def func():
    base=1<<64
    
    tag=True
    
    number=0

    while base!=0:
        if tag and n[1]&base!=0:
           
            one =0
            zero=0
            for idx in range(0,len(a)):
                if base&a[idx]!=0:
                    one+=1
                else:
                    zero+=1

            if one>=zero:
                tag=False
            else:
                
                number+=base
        elif not tag:
            one =0 
            zero=0
            for idx in range(0,len(a)):
                if base&a[idx]!=0:
                    one+=1
                else:
                    zero+=1
            if one<zero:
                
                number+=base
        base=base>>1
 
    result=0
    
    for idx in range(0,len(a)):
        result+=number^a[idx]
    return result
    
    
    
    
print(func()) 







Measured memory_bytes: 12400
# -*- coding: utf-8 -*-
"""
AtCoder
"""

def main():
    S=list(map(str,input().split()))
    # S=input()
    S=S[0]
    # print(type(S))
    N=len(S)

    s0=0
    s1=0
    for i in range(N):
        if i%2==0:
            if S[i]=="0":
                s1+=1
            else:
                s0+=1
        else:
            if S[i]=="1":
                s1+=1
            else:
                s0+=1
    print(min(s0,s1))

if __name__ == "__main__":
    main()

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        a: u32,
        s: String
    }
    if a >= 3200 {
        println!("{}", s);
    } else {
        println!("red");
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352