akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define INF 1234567891
using namespace std;
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,w;
	cin >> n >> w;
	vector<int> v[4];
	int base = -1;
	for(int i=1,cost,val;i<=n;i++) {
		cin >> cost >> val;
		if(base == -1)	base = cost;
		v[cost - base].emplace_back(val);
	}
	for(int i=0;i<4;i++)	v[i].emplace_back(INF);
	for(int i=0;i<4;i++) {
		sort(v[i].begin(),v[i].end(),greater<int>());
		v[i][0] = 0;
		for(int j=1;j<(int)v[i].size();j++)
			v[i][j] += v[i][j-1];
	}
	int ans = 0;
	for(int i=0;i<(int)v[0].size();i++)
		for(int j=0;j<(int)v[1].size();j++)
			for(int k=0;k<(int)v[2].size();k++)
				for(int x=0;x<(int)v[3].size();x++)
					if(base * i + (base + 1) * j + (base + 2) * k + (base + 3) * x <= w)
						ans = max(ans,v[0][i] + v[1][j] + v[2][k] + v[3][x]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 1000000000
#define M 500000

int merge(int *,int,int,int,int,int);
int mergeSort(int *,int,int);
int main(){
  int n,i,S[M],cnt;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  cnt=mergeSort(S,0,n);
  for(i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n%d\n",S[n-1],cnt);
  return 0;
}

int merge(int *A,int left,int mid,int right,int n1,int n2){
  int L[n1],R[n2];
  int i,j,k;
  int static cnt=0;
  for(i=0;i<n1;i++)
    L[i]=A[left+i];
  for(i=0;i<n2;i++)
    R[i]=A[mid+i];
  L[n1]=N+1;
  R[n2]=N+1;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i+=1;
    }else{
      A[k]=R[j];
      j+=1;
    }
    cnt++;
  }
  return cnt;
}

int mergeSort(int *A,int left,int right){
  int mid,n1,n2;
  if(left+1<right){
    mid=(left+right)/2;
    n1=mid-left;
    n2=right-mid;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    return merge(A,left,mid,right,n1,n2);
  }
}



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

using namespace std;

const int mod = 1e9 + 7;

void add(int &x,int y) {
  x += y;
  if (x >= mod) x -= mod;
}

int mul(int x,int y) {
  return (long long) x * y % mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> f(x + 1);
  f[x] = 1;
  for (int i = n - 1; i >= 0; --i) {
    vector<int> nf(x + 1);
    for (int j = 0; j <= x; ++j) {
      add(nf[j % a[i]], f[j]);
      add(nf[j], mul(i, f[j]));
    }
    f.swap(nf);
  }
  int ans = 0;
  for (int i = 0; i <= x; ++i) {
    add(ans, mul(i, f[i]));
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1048
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    int x[10];
    rep(i,5){
      cin >>  x[i];
    }
    int j;
    rep(i,5){
      if(x[i]==0){
        j=i+1;
        break;
      }
    }
    cout << j << endl;
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 2000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;
typedef pair<int,P> PP;

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

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

ll mod(ll val, ll M) {
    ll res = val % M;
    if(res < 0) {
        res += M;
    }
    return res;
}

template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<char> vec(2 * N);
    for(int i = 0;i < 2 * N;i++) {
        cin >> vec.at(i);
    }
    vector<int> cnt(2 * N);
    int L = 1;
    int R = 0;
    for(int i = 0;i < 2 * N - 1;i++) {
        if(vec.at(i) != vec.at(i + 1)) {
            cnt.at(i + 1) = cnt.at(i);
        }
        else {
            cnt.at(i + 1) = 1 - cnt.at(i);
        }
        if(cnt.at(i + 1) == 0) {
            L++;
        }
        else {
            R++;
        }
    }

    bool cnt2 = true;
    if(vec.at(0) == 'W' || vec.at(2 * N - 1) == 'W' || cnt.at(2 * N - 1) == 0 || L != R) {
        cnt2 = false;
    }

    if(cnt2 == false) {
        cout << 0 << endl;
    }
    else {
        ll ret = 1;
        ll Lcnt = 0;
        for(int i = 0;i < 2 * N;i++) {
            if(cnt.at(i) == 0) {
                Lcnt++;
            }
            else {
                ret *= Lcnt;
                Lcnt--;
                ret %= MOD;
            }
        }
        ll cnt3 = 1;
        for(ll i = 0;i < N;i++) {
            cnt3 *= i + 1;
            cnt3 %= MOD;
        }
        cout << ret * cnt3 % MOD << endl;
    }
}

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

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

    int sum = 0;
   rep(i, n) {
      sum += a.at(i);
   }
   if (sum >= h) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        int[] arr = inputval();
        int a = arr[0];
        int b = arr[1];
        int sum =a+b;
        int result = sum/2;
        if(sum%2 == 1) result++;
        System.out.println(result);
    }













    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    static void array_sout(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    static void array_sout(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

ll gcd(ll a, ll b){ return b ? gcd(b,a%b):a; }

int main(){
  int n;
  cin >> n;
  ll t;
  ll ans; cin>>ans;
  rep(i,n-1){
    cin >> t;
    ans = gcd(t,ans);
  }
   
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
long long ruin(int a, int n, long long  p) {
	if (n == 0) {
		return (1 % p);
	}
	else {
		long long x = ruin(a, (n - (n % 2)) / 2, p);
		if (n % 2 == 0) {
			return (x*x) % p;
		}
		else {
			return (((x*x) % p)*a) % p;

		}

	}

}
long long com(int n, int r, int p) {
	if (r == 0) {
		return (1 % p);
	}
	else {
		long long x = com(n, r - 1, p);
		return (x*(n - r) / r) % p;
	}
}
long long sum(long long n, long long p) {
	if (n == 0) {
		return 0;
	}
	else {
		long long x = (n%p) + sum((n - (n%p)) / p, p);
		return x;
	}
}
int main()
{
	int ans = 1000;
	string s;
	cin >> s;
	int si = s.size();
	vector<int> ss(si);
	for (int i = 0; i < si; i++) {
		int x = s[i]-'0';
		ss[i] = x;
	}
	for (int i = 0; i + 2 < si; i++) {
		int x = ss[i] * 100 + ss[i + 1] * 10 + ss[i + 2] * 1;
		int y = abs(x - 753);
		ans = min(ans, y);
	}
	cout << ans << endl;
}


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  vector<string> list = {"dreamer", "dream", "eraser", "erase"};
  bool ok = true;
  drep(i, s.size()) {
    int idx = -1;
    rep(j, 4) {
      int len = list[j].size();
      if (i - len + 1 < 0 || s.substr(i-len+1, len) != list[j]) continue;
      idx = j;
      i -= len-1;
      break;
    }
    if (idx == -1) {
      ok = false;
      break;
    }
  }
  std::cout << (ok ? "YES" : "NO") << "\n";
}


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


int main(){
   while(1){
   int x,y;
   cin>>x>>y;

   if(x == 0 && y == 0) break;
   if(x > y) swap(x,y);
   cout<<x<<" "<<y<<endl;
  }
 return 0;
}





Measured memory_bytes: 2988
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		string s;
		cin >> s;
		rep(i,0,sz(s)) cout<<'x';
	}
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc088/tasks/abc088_b
package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	n, _ := strconv.Atoi(readLine())
	a := strings.Split(readLine(), " ")
	cards := make([]int, n)
	alice := 0
	bob := 0

	for i := 0; i < n; i++ {
		cards[i], _ = strconv.Atoi(a[i])
	}

	for i := 0; i < n; i++ {
		sort.Sort(sort.Reverse(sort.IntSlice(cards)))
		point := cards[i]
		if i%2 == 0 {
			alice += point
		} else {
			bob += point
		}
	}

	fmt.Fprintf(writer, strconv.Itoa(alice-bob))
	_ = writer.Flush()
}


Measured memory_bytes: 640
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let h: usize = sc.cin();
    let w: usize = sc.cin();
    let mut f = vec![vec![true; w]; h];
    let mut d = vec![vec![0; w]; h];
    for i in 0..h {
        let cs = sc.cin::<String>().chars().collect::<Vec<_>>();
        for j in 0..w {
            if cs[j] == '#' {
                f[i][j] = false;
            }
        }
    }
    for i in 0..h {
        for j in 0..w {
            if i == 0 && j == 0 {
                d[0][0] = 1;
            } else if i == 0 {
                d[i][j] = if f[i][j] {
                    d[i][j-1]
                } else {
                    0
                };
            } else if j == 0 {
                d[i][j] = if f[i][j] {
                    d[i-1][j]
                } else {
                    0
                };
            } else {
                d[i][j] = if f[i][j] {
                    (d[i][j-1] + d[i-1][j]) % M
                } else {
                    0
                };
            }
        }
    }

    put!(d[h-1][w-1] % M);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 12540
#include <iostream>
using namespace std;
int main(void){
    int n,k;
    cin >> n >> k;
    double ans = 0;
    
    for(int i = 1;i <= n;i++){
        
        int temp = i;
        double rate = 1.0 / n;
        while(temp < k){
            temp *= 2;
            rate /= 2;
        }
        ans += rate;
    }
    printf("%.12f\n",ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int n,k,ans;
int qpow(int x,int y)
{
	int tmp=1;
	while(y){
		if(y&1)tmp*=x;
		y>>=1;
		x*=x;
	}return tmp;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		int tmp;cin>>tmp;
		if(tmp>=k)ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def main():
    K, T = map(int, input().split())
    a = list(map(int, input().split()))

    a.sort(reverse=True)
    greatest = a[0]
    others = sum(a[1:])

    if greatest - others <= 1:
        print(0)
        return
    else:
        print(greatest-others-1)
        return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# ABC103c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
ans = 0
f = 0
for j in a:
    f += j-1
#print(f, m)
ans = max(ans, f)
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string u;
	cin>>u;
	deque<char>q;
	for(ll i=0;i<u.size();i++){
		q.push_back(u[i]);
	}
	ll re=0;
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		if(now==1){
			re=abs(re-1);
		}
		else{
			ll ne;
			cin>>ne;
			ne--;
			ne=abs(ne-re);
			char t;
			cin>>t;
			if(ne==0){
				q.push_front(t);
			}
			else{
				q.push_back(t);
			}
		}
	}
	if(re==0){
		for(auto itr=q.begin();itr!=q.end();itr++){
			cout << *itr;
		}
	}
	else{
		for(auto itr=q.end()-1;itr!=q.begin()-1;itr--){
			cout << *itr;
		}		
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 4020
#include <stdio.h>
int main(void) {
	int i, j, x, temp = 1;
	scanf("%d", &x);
	for (i = x; ; i++) {
		for (j = 2; j < i; j++) {
			if (i % j == 0) {
				temp = 0;
				break;
			}
		}
		if (temp == 1) {
			printf("%d", i);
			return 0;
		}
		temp++;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 60)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

struct state {
  ll v, s, d;

public:
  bool operator<(const state &s) const { return d > s.d; }
};

ll N, M, R, T[200];
vector<pll> E[200];

int main(void) {
  cin >> N >> M >> R;
  REP(i, 0, N) T[i] = -1;
  REP(i, 0, R) {
    ll r; cin >> r; r--;
    T[r] = i;
  }
  REP(i, 0, M) {
    ll A, B, C; cin >> A >> B >> C; A--; B--;
    E[A].push_back(pll(B, C));
    E[B].push_back(pll(A, C));
  }

  ll dp[200][256];
  REP(i, 0, N) REP(j, 0, 1 << R) dp[i][j] = INF;
  priority_queue<state> q;
  REP(i, 0, N) q.push((state) { i, 0, 0 });

  while(!q.empty()) {
    ll v = q.top().v, s = q.top().s, d = q.top().d;
    q.pop();

    if(dp[v][s] <= d) continue;
    dp[v][s] = d;

    ll ns = T[v] == -1 ? s : (s | (1 << T[v]));
    if(ns == (1 << R) - 1) {
      cout << d << endl;
      return 0;
    }

    for(auto p : E[v]) {
      ll u = p.first;
      ll dist = p.second;
      if(dp[u][ns] > d + dist) q.push((state) { u, ns, d + dist });
    }
  }
}


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

signed main()
{
    int n; cin >> n;
    vector<int>l(n); for(int i=0;i<n;++i) cin >> l[i];
    sort(l.rbegin(),l.rend());

    int sum = 0;
    for (int i=1;i<n;++i) sum += l[i];
    if (l[0]<sum) puts("Yes"); else puts("No");
    
    return 0;
}


Measured memory_bytes: 256
from collections import deque
def solve():
  ans = ['Possible']
  N, L = map(int, input().split())
  A = list(map(int, input().split()))
  for i in range(N-1):
    if A[i]+A[i+1]>=L:
      ind = i
      break
  else:
    return ['Impossible']
  for i in range(1,ind+1):
    ans.append(i)
  for i in range(N-1,ind+1,-1):
    ans.append(i)
  ans.append(ind+1)
  return ans
print(*solve(),sep='\n')

Measured memory_bytes: 20528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long W = sc.nextLong();
		sc.close();

		if ( H == 1 || W == 1 ) {
			System.out.println(1);
		} else if ( H % 2 == 0 ) {
			System.out.println(W * (H / 2));
		} else {
			System.out.println(W * (H / 2) + (W + 1) / 2);
		}
	}
}


Measured memory_bytes: 23252
i = input()
A,B,C,X,Y = i.split()
A = int(A)
B = int(B)
C = int(C)
X = int(X)
Y = int(Y)

if (A + B) <= (C*2):
    print(A*X + B*Y)
elif X < Y:
    if C*2< B:
        print(C*Y*2)
    else:
        print(C*X*2 + B*(Y-X))
else:
    if C*2< A:
        print(C*X*2)
    else:
        print(C*Y*2 + A*(X-Y))


Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
  int i,count=0;
char s[4];
scanf("%s",s);
  for(i=0;i<4;i++)
  {
  if(s[i]==s[i+1])
    count=1;
  }
if(count==1)
  printf("Bad");
  else
    printf("Good");
return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
    #include<string.h>
    int main()
    {
    	char S[4];
    	scanf("%s",S);
    	if(S[0]==S[1] || S[2]==S[3] || S[1]==S[2])
    	{
    		printf("Bad\n");
    	}
    	else
    		printf("Good\n");
    	return 0;
    }

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int f(int n) {	
	return (n % 2 == 0 ? n / 2 : 3 * n + 1);
}
int main() {
	int s;
	cin >> s;
	vector<int> a(0);
	int i = 1, add;
	while (true) {
		if (i == 1) {
			add = s;
		} else if (i > 1) {
			add = f(a[i-2]);
		}

		for (int j = 0; j < a.size(); j++) {
			if (a[j] == add) {
				cout << i << endl;
				return (0);
			}
		}
		a.push_back(add);
		i++;
	}
}

Measured memory_bytes: 256
from collections import defaultdict

n, w = [int(x) for x in input().split()]
d = []
for _ in range(n):
    ww, nu = [int(x) for x in input().split()]
    d.append((ww, nu))

# dd[idx][ww] represents the maximum value that  we can get if total weight <= ww
# and allowed to use the first idx items.
dd = defaultdict(lambda: defaultdict(int))
for ww in range(w+1):
    dd[0][ww] = 0

for nn in range(n+1):
    dd[nn][0] = 0

for nn in range(1, n+1):
    www, nu = d[nn-1]
    for ww in range(1, w+1):
        # don't use item nn-1
        cur = dd[nn-1][ww]

        # use item nn-1
        if www <= ww:
            rem_ww = ww - www
            cand = dd[nn-1][rem_ww] + nu
            if cand > cur:
                cur = cand

        dd[nn][ww] = cur

print(dd[n][w])

Measured memory_bytes: 808080
R,G,B,N = map(int,input().split())
ans = 0
for i in range(0,N//R+1):
  for j in range(0,(N-i*R)//G+1):
    k = N - i*R -j*G
    if k%B == 0 and k>= 0:
      ans += 1
print(ans)

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

using namespace std;

int main()
{
    long int n,min,max,to;
    cin >> n;

    long int in;
    cin >> in;
    min = in;
    max = in;
    to = in;
    for(int i = 1;i < n;i++)
    {
        cin >> in;
        if(in < min)
        {
            min = in;
        }
        else if(in > max)
        {
            max = in;
        }
        to += in;
    }
    cout << min << " " << max << " " << to << endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;

const ll INF = 1ll<<60;

int main(){
    int n, q;
    cin >> n >> q;
    vector<ll> s(n), t(n), x(n), za;
    
    for(int i = 0; i < n; i++){
        cin >> s[i] >> t[i] >> x[i];
        if(t[i]-x[i] <= 0)  continue;
        za.push_back(max(0ll,s[i]-x[i]));
        za.push_back(t[i]-x[i]);
    }

    vector<int> d(q);
    for(int i = 0; i < q; i++){
        cin >> d[i];
        za.push_back(d[i]);
    }

    sort(za.begin(), za.end());
    za.erase(unique(za.begin(), za.end()), za.end());
    auto f = [&](int val)->int{
        return lower_bound(za.begin(),za.end(),val)-za.begin();
    };

    int siz = za.size();

    vector<pair<ll,int>> st[siz];
    for(int i = 0; i < n; i++){
        if(t[i]-x[i] <= 0)  continue;
        int from = f(max(0ll,s[i]-x[i])), to = f(t[i]-x[i]);
        st[from].push_back({-x[i], to});
    }

    vector<ll> imos(siz, INF);
    // time, to
    priority_queue<pair<ll,int>> pq;


    for(int i = 0; i < siz; i++){
        for(int j = 0; j < st[i].size(); j++){
            pq.push(st[i][j]);
        }
        while(!pq.empty()){
            auto p = pq.top();
            if(i < p.second)    break;
            pq.pop();
        }
        if(!pq.empty()) imos[i] = -(pq.top()).first;
        else            imos[i] = -1;
    }

    for(int i = 0; i < q; i++){
        cout << imos[f(d[i])] << endl;
    }
    
    return 0;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll dp[101][4][4];

int main() {
  int n, m;
  cin >> n >> m;
  int y[100] = {};
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    y[a - 1] = b;
  }

  rep(i, 1, 4) rep(j, 1, 4) {
    int a = y[0] ? y[0] : i, b = y[1] ? y[1] : j;
    dp[1][b][a] = 1;
  }

  rep(i, 2, n) rep(j, 1, 4) rep(k, 1, 4){
    if(y[i]) {
      if(!(y[i] == j && j == k)) dp[i][y[i]][j] += dp[i - 1][j][k];
      dp[i][y[i]][j] %= 10000;
      continue;
    }
    rep(l, 1, 4) if(!(j == k && k == l)) dp[i][j][k] += dp[i - 1][k][l];
    dp[i][j][k] %= 10000;
  }

  ll ans = 0;
  rep(i, 1, 4) rep(j, 1, 4) ans += dp[n - 1][i][j];
  cout << ans % 10000 << endl;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,h,w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(a>=h && b>=w)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N,M = getNM()
dist = [[] for i in range(N)]
for i in range(M):
    a, b, c = getNM()
    dist[a - 1].append((b - 1, c))
    dist[b - 1].append((a - 1, -c))

pos = deque([i for i in range(N)])
point = [float('inf')] * N

while len(pos) > 0:
    now = pos.popleft()
    if point[now] == float('inf'):
        point[now] = 0
    for next, dis in dist[now]:
        if point[next] == float('inf'):
            point[next] = point[now] + dis
            pos.appendleft(next)
            continue
        if point[next] != point[now] + dis:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 122620
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,A;
    scanf("%d%d",&N,&A);
    int L=A;
    int R=N+A-1;
    int eat;
    if(R<=0) eat=R;
    else if(L>=0) eat=L;
    else eat=0;
    int apple_favor=(L+R)*N/2;
    cout<<apple_favor-eat<<endl;
}

Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline()[:-1]

n = int(input())
adj = [[] for _ in range(n)]
for i in range(n-1):
	a, b = map(int, input().split())
	adj[a-1].append((b-1, i))
	adj[b-1].append((a-1, i))
paths = [[0 for _ in range(n)] for _ in range(n)]

def pop_count(b):
	return sum(map(int, list(bin(b)[2:])))

def dfs(x, p, bit):
	for v, j in adj[x]:
		if v == p or paths[p][v] > 0:
			continue
		paths[p][v] = bit + (1<<j)
		dfs(v, p, bit + (1<<j))
	return

for i in range(n):
	dfs(i, i, 0)

#print(*paths, sep="\n")

cons = []
m = int(input())
for _ in range(m):
	u, v = map(int, input().split())
	cons.append(paths[u-1][v-1])

#print(cons)

uses = [0 for _ in range(1<<m)]
ans = 1<<(n-1)
for b in range(1, 1<<m):
	pop = pop_count(b) % 2
	cur = 0
	while not (1<<cur) & b:
		cur += 1
	use = uses[b - (1<<cur)] | cons[cur]
	uses[b] = use
	if pop:
		ans -= 1 << (n-1 - pop_count(use))
	else:
		ans += 1 << (n-1 - pop_count(use))

print(ans)

Measured memory_bytes: 151804
#include <algorithm>
#include <cstring>
#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); }
char mp[10001][10000];

signed main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    memset(mp, ' ', sizeof(mp));
    vector<int> end(n);
    int predot = 0;
    rep(i, n) {
      string s;
      cin >> s;
      int dot = 0;
      for (int j = 0; j < s.size(); j++) {
        while (s[j] == '.') {
          j++;
          dot++;
        }
        mp[i][j] = s[j];
      }
      end[i] = s.size();
      mp[i][dot - 1] = '+';
      if (dot < predot) {
        int tmp = 1;
        while (mp[i - tmp][dot - 1] == ' ' && tmp >= 0) {
          mp[i - tmp][dot - 1] = '|';
          tmp++;
        }
      }
      predot = dot;
    }
    rep(i, n) {
      rep(j, end[i]) { cout << mp[i][j]; }
      cout << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 100796
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n+1,0);
  int a[80], b[80];
  for(int i=0; i<m; i++){
    
    cin >> a[i] >> b[i];
    num[a[i]]++;
    num[b[i]]++;
  }
  for(int i=1; i<=n; i++){
    cout << num[i] << endl;
  }
}

Measured memory_bytes: 256
#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() {
    string s;
    int r = 0;
    cin >> s;
    for (int i = 1; i < (int)s.size(); ++i)
        if (s[i] != s[i - 1]) ++r;
    cout << r;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,K,a[100001],res = -INF_LL,psum[100001],sum[100001];
  cin >> N >> K;
  REP(i,N)cin >> a[i];
  sum[0] = a[0];
  psum[0] = a[0] >= 0 ? a[0] : 0;
  for(int i=1;i<N;i++){
    if(a[i] >= 0){
      psum[i] = psum[i-1] + a[i];
    }else
      psum[i] = psum[i-1];
    sum[i] = sum[i-1] + a[i];
  }
  res = max(res,psum[N-1]-psum[K-1] + sum[K-1]);
  res = max(res,psum[N-1]-psum[K-1]);
  
  for(int i=i;i<N-K+1;i++){
    res = max(res,psum[N-1]-(psum[K-1+i]-psum[i-1]) + (sum[K-1+i]-sum[i-1]));
    res = max(res,psum[N-1]-(psum[K-1+i]-psum[i-1]));
  }
  
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 2560
n=int(input())
l1=list(map(int,input().split()))
l2=sorted(l1)
if l1==l2:
        print("YES")
        exit()
k=0
for i in range(n):
        if l1[i]!=l2[i]:
                k+=1
if k==2:
        print("YES")
else:
        print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define ll long long
#define ldb long double
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)


const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n){
	ll res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}
	
	return res;
}

int main(){
	fast;
	
	ll int n,a,b;
	cin>>n>>a>>b;
	
	if(a+b<n){
		ll int y=n/(a+b);
		ll int p=min(n%(a+b),a);
		
		cout<<y*a+p;
	}
	
	else
	cout<<min(a,n);
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	cin >> H >> W >> K;
	vector<string>s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W - 1; j++) {
			auto w = s;
			swap(w[i][j], w[i][j + 1]);
			for (int loop = 0; loop < H; loop++) {
				for (int k = 0; k < W; k++) {
					for (int l = H - 2; l >= 0; l--) {
						if (w[l][k] <= 'Z'&&w[l][k] >= 'A'&&w[l + 1][k] == '.') {
							swap(w[l][k], w[l + 1][k]);
						}
					}
				}
			}
			bool exit = false;
			while (!exit) {
				exit = true;
				vector<vector<bool>>field(H, vector<bool>(W));
				for (int k = 0; k < H; k++) {
					int lft = 0;
					for (int l = 1; l < W; l++) {
						if (w[k][l] == w[k][l - 1] && w[k][l] != '.') {
							if (l - lft + 1 >= K) {
								for (int m = lft; m <= l; m++) {
									field[k][m] = true;
								}
							}
						}
						else {
							lft = l;
						}
					}
				}
				for (int k = 0; k < W; k++) {
					int up = 0;
					for (int l = 1; l < H; l++) {
						if (w[l][k] == w[l - 1][k] && w[l][k] != '.') {
							if (l - up + 1 >= K) {
								for (int m = up; m <= l; m++) {
									field[m][k] = true;
								}
							}
						}
						else {
							up = l;
						}
					}
				}
				for (int k = 0; k < H; k++) {
					for (int l = 0; l < W; l++) {
						if (field[k][l]) {
							exit = false;
							w[k][l] = '.';
						}
					}
				}
				for (int loop = 0; loop < H; loop++) {
					for (int k = 0; k < W; k++) {
						for (int l = H - 2; l >= 0; l--) {
							if (w[l][k] <= 'Z'&&w[l][k] >= 'A'&&w[l + 1][k] == '.') {
								swap(w[l][k], w[l + 1][k]);
							}
						}
					}
				}
			}
			//cout << i << " " << j << endl;
			//for (auto k : w) {
			//	cout << k << endl;
			//}
			bool ret = true;
			for (auto k : w) {
				for (auto l : k) {
					if (l != '.')ret = false;
				}
			}
			if (ret) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

namespace AtCoder
{
    public static class Program
    {
        static void Main()
        {
            var array = Console.ReadLine().Split(' ');
            Console.WriteLine(Math.Min(int.Parse(array[0]) * int.Parse(array[1]), int.Parse(array[2])));
        }

        public static int ToInt(this string param) => int.Parse(param);
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int a,c,b,d;
    scanf("%d%d%d%d\n",&a,&b,&c,&d);
    int menor1,menor2,maior1,maior2;
    if(a<c){
        menor1 = a;
        menor2 = c;}
    else{
        menor1 = c;
        menor2 = a;}
    if(b>=d){
        maior1 = b;
        maior2 = d;}
    else{
        maior1 = d;
        maior2 = b;}
    if(maior2-menor2>=0)
        printf("%d\n",maior2-menor2);
    else
        printf("%d\n",0);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
	int n,i;
	cin>>n;
	string s;
	cin>>s;
	string head;
	int a=0,b=0;
	loop(i,0,n){
		if(s[i]=='('){
			a++;
		}else{
			b++;
		}
		if(b>a){
			head.push_back('(');
			a++;
		}
	}
	cout<<head<<s;
	loop(i,0,a-b){
		cout<<')';
	}
	cout<<endl;
}

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

int main(){
  string S;
  cin>>S;
  int n=S.size();
  vector<int> a(n);
  int f=0;
  for(int i=0;i<n;i++){
    a.at(i)=S.at(i)-'0';
    f+=a.at(i);
  }
  int X=stoi(S);
  if(X%f==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define P push
#define x1 xx
#define y1 yy
#define x2 xxx
#define y2 yyy
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MOD = 1e8;
const int MAX = 1e5+5;
ll a[111];
ll res=100000000000;


int main()
{
   string s;
   cin>>s;
   ll a=-2,b=-2;
   ll n=s.size();
   for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1])a=i,b=i+1;
   }
   for(int i=0;i<n-2;i++){
    if(s[i]==s[i+2])a=i,b=i+2;
   }
   cout<<a+1<<" "<<b+1;
        return 0;
}



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

using namespace std;
int main(){
  long n;
   cin >> n;
  
  vector<long> a(n);
  for(int i=0;i<n;i++){
   cin >> a[i];
    a[i]-=i+1;
  }
 
  sort(a.begin(),a.end());
  
  long mid;
  
  if(n%2) mid=a[n/2]; 
  else mid=(a[n/2]+a[n/2-1])/2;
  
  long res=0;
  for(int i=0;i<n;i++) res+=abs(a[i]-mid);
  
  cout << res << endl;
  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
#define mp make_pair
#define pb push_back

int main(){
	ll a,b,n;
	cin>>n>>a>>b;
	if (a>b){
		ll t=a;
		a=b;
		b=t;
	}
	ll x=b-a;
	if (x%2==1){
		ll ans=min(x/2+a,x/2+n-b+1);
		cout<<ans<<endl;
	}
	else cout<<x/2<<endl;
	return 0;
}

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

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


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

// std::vector Initialization
template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   string s; cin >> s;
   int n = s.size();

   LL total = 0;
   for (int i = 0; i < n; ++i) {
      // それぞれのs[i]が, どれだけ総和に寄与するかを考える
      for (int k = 0; i+k < n; ++k) {
         // s[i] が 10^k 倍されて加算されるときを考える
         total +=
            (s[i]-'0') *   // 数字
            pow(10,k) *    // 10^k 倍される
            (1<<i) *       // s[i]の前は, 2^i 通り
            (i+k == n-1 ? 1 : 1<<n-1-(i+k)-1);   // s[i]の後は, 長さkで切れている or s の末尾
      }
   }

   cout << total << endl;

   return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N;
ll A[200010];

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N){
        if(i < A[i] || A[i] + 1 < A[i + 1]){
            PRINT("-1");
            return 0;
        }
    }
    ll ans = 0;
    for(int i = N - 1; i > 0; i--){
        if(A[i - 1] < A[i]){
            ans++;
        }else{
            ans += A[i];
        }
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

const int INF = 10;
int dp[100100];

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

    fill(dp, dp + n, INF);
    for(int i = 0; i < n; i++){
        *upper_bound(dp, dp + n, a[i]) = a[i];
    }
    printf("%d\n", lower_bound(dp, dp + n, INF) - dp);

    return 0;
}

Measured memory_bytes: 4268
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int a[3];

int main() {
    rep(i, 3) cin >> a[i];
    sort(a, a+3);
    if (a[0] == a[1] && a[1] != a[2]) cout << "Yes" << endl;
    else if (a[1] == a[2] && a[0] != a[1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			//縦と横のint型の変数
			int intHeight = scan.nextInt();
			int intWidth = scan.nextInt();

			int intHeiblank = intHeight - 2;
			int intWidthblank = intWidth - 2;


			//縦と横の長さがともに０の時ループを抜ける
			if(intHeight == intWidth && intHeight == 0){
				break;
			}
			//上辺
			for(int j = 0;j < intWidth;j++){
				System.out.print("#");
			}

			//改行
			System.out.println("");

			for(int i = 0;i < intHeiblank;i++){

				//上段と下段を除いた横の出力
				System.out.print("#");
				for(int j = 0;j < intWidthblank;j++){
					System.out.print(".");
				}
				System.out.print("#");

				//改行
				System.out.println("");
			}
			if(intHeight >= 2){
				//下辺
				for(int j = 0;j < intWidth;j++){
					System.out.print("#");
				}
			}

			//AOZの制約のための空行
			System.out.println("");
			System.out.println("");
		}
			scan.close();
	}
}



Measured memory_bytes: 34140
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <limits.h>
#include <math.h>

using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<vector<long long>> dp(n+1,vector<long long>(13,0));
	dp[0][0] = 1;
	long long me = 1;
	for (int i = 0;i < n;i++) {
		if (s[n-i-1] == '?') {
			for (int j = 0;j < 13;j++) {
				for (int k = 0;k < 10;k++) {
					dp[i + 1][(j + k * me) % 13] =( dp[i][j] + dp[i + 1][(j + k * me) % 13] )%1000000007;
				}
			}
		}
		else {
			int no = me * (s[n-i-1] - '0') % 13;
			for (int j = 0;j < 13;j++) {
				dp[i + 1][(j + no) % 13] = (dp[i + 1][(j + no) % 13] + dp[i][j])%1000000007;
			}
		}
		me = (me * 10) % 13;
	}
	cout << dp[n][5] << endl;
}

Measured memory_bytes: 13696
#include <iostream>
#include <cmath>
using namespace std;
int X[10][10];
int main(void){
    int N, D;
    cin >> N >> D;
    for (int i = 0; i < N; i++)
        for (int j = 0; j < D; j++)
            cin >> X[i][j];
    
    int ans = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            double d = 0;
            for (int k = 0; k < D; k++)
                d += pow(X[i][k] - X[j][k], 2);
            
            d = pow(d, 0.5);
            if (d == (int)d)
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i, a, n) for (int i = a; i < n; i++)
using namespace std;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,k; cin>>n>>k;
    cout<<min(n%k,abs(n%k-k));

    return 0;
}

Measured memory_bytes: 3628
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val bar = readLine()!!.split(" ").map { it.toLong() }
    val total = bar.sum()
    var subTotal = 0L
    var diff = total
    for(i in (0 until n-1)) {
        subTotal += bar[i]
        diff = Math.min(diff, Math.abs(subTotal*2-total))
    }
    println(diff)
}


Measured memory_bytes: 80960