akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	vector<int> z(10,0);
	for (int i = 0; i < 3; i++) {
		int a;
		cin >> a;
		z[a]++;
	}
	for (int i = 1; i <= 9; i++) {
		if (z[i] == 2) {
			cout << "Yes";
			return(0);
		}
	}
	cout << "No";
	return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long a[100005];
int main(){
	int n;
	cin>>n;
	long long mi=2e9,cnt=0;
	long long sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	//	cout<<a[i]<<endl;
		mi=min(mi,abs(a[i]));
		if(a[i]<0) cnt++;
		sum+=abs(a[i]);
	}
//	cout<<cnt<<endl;
	if(cnt%2){
		cout<<sum-2*mi;
	}
	else cout<<sum;
	
}

Measured memory_bytes: 1024
function main(arg) {
    arg  = arg.split("\n")
    var s = arg[0]
    var t = arg[1]

    while (1) {
        if (s === "") {
            break
        } 

        s = s.split(s[0]).join("")
        t = t.split(t[0]).join("")

        if (s.length !== t.length) {
            console.log('No')
            return;
        }
    }
    console.log('Yes')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(void) {
	long long num;
	int	 source,ans = 0;
	cin >> num ;
	for (long long i = sqrt(num); i > 0; i--)
	{
		if (num%i == 0) {
			source = num / i;
			while (source>=1)
			{
				source = source / 10;
				ans++;
			}
			break;
		}
	}

	cout << ans << endl;
	return 0;
}

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

int main() {
  int T;
  cin >> T;
  while(T--) {
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    int dp[n][200];
    memset(dp,0,sizeof(dp));
    dp[0][0]=a[0];
    for(int i=1; i<n; i++) {
      for(int j=0; j<200; j++) {
	dp[i][dp[i-1][j]]=max(dp[i][dp[i-1][j]],a[i]);
	if(dp[i-1][j]) dp[i][dp[i-1][j]-1]=max(dp[i][dp[i-1][j]-1],j+a[i]);
      }
    }
    int ans=0;
    for(int i=0; i<200; i++) ans=max(ans,dp[n-1][i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
D = int(input())
c = [0] + [int(x) for x in input().split()]
s = [[0 for _ in range(26 + 1)]] + \
    [[0] + [int(x) for x in input().split()] for _ in range(D)]
t = [0] + [int(input()) for _ in range(D)]

def calcScore():
    score = [[0] * (26 + 1) for _ in range(D + 1)]
    sinceLast = [[0] * (26 + 1) for _ in range(D + 1)]

    for d in range(1, D + 1):
        id = t[d]  # この日に開催するコンテスト
        sinceLast[d][id] = 0
        score[d][id] = s[d][id]


        for i in range(1, 26 + 1):
            if i == id:  continue
            sinceLast[d][i] = sinceLast[d - 1][i] + 1
            score[d][i] = -c[i] * sinceLast[d][i]

    total = sum(sum(row) for row in score)

    ans = 0
    for d in range(1, D + 1):
        ans += sum(score[d])
        print(ans)

    return ans

calcScore()

Measured memory_bytes: 9868
package main

import (
	"fmt"
	"math"
)

func main()  {
	var n, a, b, c int
	fmt.Scan(&n, &a, &b, &c)
	l := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Scan(&l[i])
	}
	fmt.Println(dfs(n, 0, l, a, b, c, 0, 0, 0))
}

func dfs(n int, depth int, l []int, A int, B int, C int, a int, b int, c int) int {
	if depth == n {
		if a > 0 && b > 0 && c > 0 {
			//fmt.Println( int(math.Abs(float64(A-a)) + math.Abs(float64(B-b)) + math.Abs(float64(C-c))) - 30)
			return int(math.Abs(float64(A-a)) + math.Abs(float64(B-b)) + math.Abs(float64(C-c))) - 30
		}
		return int(10e9)
	}

	min := dfs(n, depth+1, l, A, B, C, a, b, c)
	min = int(math.Min(float64(dfs(n, depth+1, l, A, B, C, a+l[depth], b, c) + 10), float64(min)))
	min = int(math.Min(float64(dfs(n, depth+1, l, A, B, C, a, b+l[depth], c) + 10), float64(min)))
	return int(math.Min(float64(dfs(n, depth+1, l, A, B, C, a, b, c+l[depth]) + 10), float64(min)))


}

Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main(){
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int min_price,max_price,min_number,max_number;
  max_price=2*C;
  min_price=A+B;
  if(A+B>2*C){
    max_price=A+B;
    min_price=2*C;
  }
  max_number=Y;
  min_number=X;
  if(X>Y){
  max_number=X;  
  min_number=Y;
  }
  int res=0;
  res+=min_number*min_price;
  min_number=max_number-min_number;
  if(max_number==X){
  min_price=A;
  } else{
    min_price=B;
        }
  if(min_price>2*C){
    min_price=2*C;
  }
  res+=min_number*min_price;
  cout<<res;
}


Measured memory_bytes: 256
days = int(input())
clast = list(map(int,input().split()))

allpref = [] #allpref[day][contest]
for i in range(days):
    allpref.append(list(map(int,input().split())))
donelist = [0]*26
contestlist = []
for i in range(days):
    max = 0
    result = 0
    contest = False
    for held in range(26):
        tempdonelist = donelist[:]
        tempdonelist[held] = i+1
        zanen = sum([clast[j]*((i+1)-donelist[j]) for j in range(26)])
        result += allpref[i][held] - zanen
        if result >= max:
            max = result;contest = held


    donelist[contest] = i+1
    contestlist.append(contest+1)

for num in contestlist:
    print(num)


Measured memory_bytes: 9516
N,A,B=map(int,input().split())

if(abs(A-B)%2==0):
    print(abs(A-B)//2)
else:
    o=max(abs(1-A),abs(1-B))
    n=max(abs(N-A),abs(N-B))
    t=min(o,n)

    t1=N-((A+B-1)//2)
    t2=((A+B+1)//2)-1
    print(min(t,t1,t2))



Measured memory_bytes: 3060
#include <stdio.h>
#define N 100

int G[N+1][N+1], size[N+1], d[N+1], f[N+1], n, t;

void dfs(int p){
  int i;
  d[p] = t++;
  for(i=1;i<=size[p];i++) if(!d[G[p][i]]) dfs(G[p][i]);
  f[p] = t++;
}

main(){
  int i, j, u, v;
  scanf("%d", &n);
  t = 1;
  for(i=1;i<=n;i++){
    d[i] = f[i] = 0;
    scanf("%d", &u);
    scanf("%d", &size[u]);
    for(j=1;j<=size[u];j++) scanf("%d", &G[u][j]);
  }
  for(i=1;i<=n;i++) if(!d[i]) dfs(i);
  for(i=1;i<=n;i++) printf("%d %d %d\n", i, d[i], f[i]);
  return 0;
}

Measured memory_bytes: 0
program main
  implicit none
  
  double precision ::a,b
  
  read(*,*)a
  read(*,*)b
  if ((a - b) > 0.5) then
    write(*,'(A)')"GREATER"
    stop
  else if ((a - b) < -0.5) then
    write(*,'(A)')"LESS"
    stop
  end if
  write(*,'(A)')"EQUAL"
end program main


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

using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int maxn = 1e6 + 7;
const LL INF = 1e12;
const LL mod = 1e9 + 7;

int main() {
    int h,w,n;
    while(cin >> h >> w >> n) {
        cout << (n + max(h,w) - 1) / max(h,w) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

const int N = 2e5 + 10;

int a[N];
int n;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }

    int num = 0, flg = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] == flg + 1){
            flg = a[i];
            num ++;
        }
    }
    int ans = n - num;
    if(ans == n)    cout << -1 << endl;
    else
    {
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		Arrays.sort(a);

		long s = 0;

		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (s * 2 < a[i]) {
				ans = 0;
			}
			s += a[i];
			ans++;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 44056
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main() {
	int n, a, b; cin >> n >> a >> b;
	int d = b - a - 1;
	if (d % 2) cout << "Alice\n";
	else cout << "Borys\n";
	return 0;
} 

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FOR(i, a, b)    for(int i = a; i <= b; i++)
#define REP(i, a, b)    for(int i = a; i >= b; i--)
#define maxN       300005
#define inf        (int) 1e9
#define mode       (int) 1000000007
#define ll         long long

using namespace std;

int n, k;
int a[maxN], f[maxN];
int it[5 * maxN], dt[5 * maxN];

void update(int r, int k, int l, int u, int v, int delta) {
    if(u > l || v < k) return;
    if(u <= k && l <= v) {dt[r] += delta; return;}
    int g = (k + l)/2;
    dt[2 * r] += dt[r], dt[2 * r + 1] += dt[r], dt[r] = 0;
    update(2 * r, k, g, u, v, delta);
    update(2 * r + 1, g + 1, l, u, v, delta);
    it[r] = max(it[2 * r] + dt[2 * r], it[2 * r + 1] + dt[2 * r + 1]);
}

int get(int r, int k, int l, int u, int v) {
    if(u > l || v < k) return 0;
    if(u <= k && l <= v) return dt[r] + it[r];
    int g = (k + l)/2;
    dt[2 * r] += dt[r], dt[2 * r + 1] += dt[r], dt[r] = 0;
    int tr = get(2 * r, k, g, u, v);
    int tl = get(2 * r + 1, g + 1, l, u, v);
    it[r] = max(it[2 * r] + dt[2 * r], it[2 * r + 1] + dt[2 * r + 1]);
    return max(tr, tl);
}

void solve() {
    cin >> n >> k;
    FOR(i, 1, n) cin >> a[i];
    int x = *max_element(a + 1, a + n + 1);
    FOR(i, 1, n) {
        int u = max(0, a[i] - k);
        int v = min(a[i] + k, x);
        f[a[i]] = max(f[a[i]], get(1, 0, x, u, v) + 1);
        int t = get(1, 0, x, a[i], a[i]);
        if(t < f[a[i]]) {
            update(1, 0, x, a[i], a[i], -t);
            update(1, 0, x, a[i], a[i], f[a[i]]);
        }
    }
    int ans = 0;
    FOR(i, 0, x) ans = max(ans, f[i]);
    cout << ans;
}

int main() {
    //freopen("main.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


Measured memory_bytes: 12164
strToInt :: String -> Int
strToInt s = read s :: Int

main = do
    a <- getLine 
    b <- getLine
    c <- getLine
    d <- getLine
    let train = min (strToInt a) (strToInt b)
        bus = min (strToInt c) (strToInt d)
    putStrLn $ show (train + bus)

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

#define rep(i, k) for (ll i = 0; i < k; i++)
#define pair(x, y) make_pair((x), (y))

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n, m;
    cin >> n >> m;
    string c = "No";
    if (n == m) c = "Yes";
    std::cout << c;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

n = int(input())
uvw = [list(map(int,input().split())) for _ in range(n-1)]

e =[[] for _ in range(n)]
color = [-1]*n
dw = {}

for u,v,w in uvw:
  e[u-1].append(v-1)
  e[v-1].append(u-1)
  dw[(u-1,v-1)] = dw[(v-1,u-1)] = w

def dfs(i,c)  :
  color[i] = c
  for ei in e[i]:
    if color[ei] != -1:
      continue
    dfs(ei, c+dw[(i,ei)])

dfs(0,0)   

for c in color:
  print(c%2)

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

void solve(long long N, string S){
	int now = 0, res = 0;
	for (int i=0; i<N; i++) {
		if (S[i] == '.') now++;
	}
	res = now;
	for (int i=0; i<N; i++) {
		if (S[i] == '.') now--; else now++;
		res = min(res, now);
	}
	cout << res << endl;
}

int main(){	
	long long N;
	string S;
	scanf("%lld",&N);
	cin >> S;
	solve(N, S);
	return 0;
}



Measured memory_bytes: 772
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;
int d;
vector<ll> c(26);
vector<vector<ll>> s;
vector<ll> t;

ll score(){
  ll res = 0;
  vector<ll> last(26);
  rep(i, d){
    int num = t[i];
    res += s[i][num];
    last[num] = i + 1;
    for (int j = 0; j < 26; ++j) {
      res -= c[j] * ((i+1) - last[j]);
    }
    cout << res << endl;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> d;
  rep(i, 26) cin >> c[i];
  s = vector<vector<ll>> (d, vector<ll>(26));
  for (int i = 0; i < d; ++i) {
    for (int j = 0; j < 26; ++j) {
      cin >> s[i][j];
    }
  }
  t = vector<ll> (d);
  rep(i, d) cin >> t[i], t[i]--;

  score();
  // cout << score() << endl;
}


Measured memory_bytes: 3744
#include<stdio.h>
#define N 100

main(){
  int i,j,m[N][N],n,l,b,o;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    for(j=0;j<b;j++){
      m[i][j]=0;
    }
  }

  for(i=0;i<b;i++){
    scanf("%d %d",&n,&l);
    n--;
    for(j=0;j<l;j++){
      scanf("%d",&o);
      o--;
      m[n][o]=1;
    }
  }
  for(i=0;i<b;i++){
    for(j=0;j<b-1;j++){
      printf("%d ",m[i][j]);
    }
    printf("%d",m[i][b-1]);
    printf("\n");
  }
  
  
 return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	char A,B;
	scanf("%c %c",&A,&B);
	if(A>B)
		printf(">\n");
		else if(A<B)
			printf("<\n");
			else
				printf("=\n");
	return 0;
}


Measured memory_bytes: 128
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map int . words
printer = unlines . (:[]) . show 

solver [n,a,b] = min (n*a) b



Measured memory_bytes: 508
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N, M;
    cin >> N >> M;
    vector<int> l(M), r(M);
    REP(i, M) cin >> l[i] >> r[i];
    int ans = *min_element(ALL(r)) - *max_element(ALL(l)) + 1;
    if (ans < 0)
        print(0);
    else
        print(ans);

    return 0;
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl



signed main() {

	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;

	S[K - 1] += 'a' - 'A';

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<ll> ansh(h, 0), answ(w, 0);
  map<pair<ll, ll>, ll> mp;
  for(int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    mp[{x, y}]++;
    ansh[x]++;
    answ[y]++;
  }
  ll ans = 0, maxi = 0;
  for(int i = 0; i < h; i++) {
    maxi = max(maxi, ansh[i]);
  }
  ans += maxi;
  vector<int> idxx, idxy;
  for(int i = 0; i < h; i++) {
    if(ansh[i] == maxi) {
      idxx.push_back(i);
    }
  }
  maxi = 0;
  for(int i = 0; i < w; i++) {
    maxi = max(maxi, answ[i]);
  }
  ans += maxi;
  for(int i = 0; i < w; i++) {
    if(answ[i] == maxi) {
      idxy.push_back(i);
    }
  }
  int cnt = 0;
  for(int i = 0; i < idxx.size(); i++) {
    for(int j = 0; j < idxy.size(); j++) {
      if(mp[{idxx[i], idxy[j]}] == 1) {
        continue;
        cnt++;
      } else {
        cnt = m;
        break;
      }
    }
    if(cnt >= m) {
      break;
    }
  }
  if(cnt < m) {
    cout << ans - 1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 30748
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	string W;
	vector<string> T;

	cin >> W;

	while (true)
	{
		string Ti;
		getline(cin, Ti);

		if (Ti == "END_OF_TEXT")
		{
			break;
		}
		else
		{
			for (auto& c : Ti)
			{
				if ('A' <= c&&c <= 'Z')
				{
					c += ('a' - 'A');
				}
			}
			T.push_back(Ti);
		}
	}

	int counter = 0;
	for (auto& t : T)
	{
		vector<string> tempT;
		string s;
		for (auto& c : t)
		{
			if (c == ' ')
			{
				tempT.push_back(s);
				s.clear();
			}
			else
			{
				if ('A' <= c&&c <= 'Z')
				{
					c += ('a' - 'A');
				}
				s += c;
			}
		}
		tempT.push_back(s);

		for (auto& ts : tempT)
		{
			if (W == ts)
			{
				counter++;
			}
		}
	}

	printf("%d\n", counter);
	return 0;
}

Measured memory_bytes: 3260
/*
 * atcoder/abc121_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

struct D {
  ll price, num;
  bool operator<(const D& a)const{
    return price < a.price;
  }
};
int N, M;
vector<D> ds;

void solve() {
  cin >> N >> M;
  ll price, num;
  loop(n,0,N) {
    cin >> price >> num;
    ds.push_back((D){price, num});
  }
  sort(ds.begin(), ds.end());
  ll total = 0;
  int idx = 0;
  while (M > 0) {
    if (M <= ds[idx].num) {
      total += ds[idx].price * M;
      M = 0;
      break;
    }

    total += ds[idx].price * ds[idx].num;
    M -= ds[idx++].num;
  }
  cout << total << endl;
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


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

int main() {

  int v[128];
  int n;

  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::cin >> v[i];
  }

  for(int i = n-1; i > 0; --i) {
    std::cout << v[i] << " ";
  }
  std::cout << v[0] << std::endl;
  
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
bool chk[30];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string S,T;

    cin>>S;

    n = S.size();

    for(int i=0;i<n;i++)
        chk[S[i]-'a'] = true;

    if(n==26){
        T = S;
        bool judge = next_permutation(S.begin(),S.end());

        if(!judge){
            cout<<"-1\n";
            return 0;
        }

        for(int i=0;i<n;i++){
            cout<<S[i];
            if(T[i]!=S[i])break;
        }

        return 0;
    }

    cout<<S;

    char c;

    for(int i=0;i<26;i++)
        if(!chk[i]){
            c = 'a'+i;
            cout<<c<<"\n";
            break;
        }

    return 0;
}


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

int main() {
  int N;
  long K;
  cin >> N;
  vector<int>L(N);
  for(int i = 0; i < N; ++i){
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());

  int cnt = 0;

  for(int i = 0; i < N-2; ++i){
    int x = L.at(i);
    for(int j = i+1; j < N-1; ++j){
      int y = L.at(j);
      if(x == y) continue;
      int t = x+y;
      for(int k = j+1; k < N; ++k){
        int z = L.at(k);
        if(y == z) continue;

        if(t > z) ++cnt;
      } 
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3632
//  Created by conan1024hao on 2019/11/24.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //------------------------------
    string s;
    cin>>s;
    if(s=="SUN")
        cout<<7<<endl;
    else if(s=="SAT")
            cout<<1<<endl;
           else if(s=="FRI")
           cout<<2<<endl;
    else if(s=="THU")
    cout<<3<<endl;
    else if(s=="WED")
    cout<<4<<endl;
    else if(s=="TUE")
    cout<<5<<endl;
    else if(s=="MON")
    cout<<6<<endl;
            //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
x = gets.to_i

def root(x, n)
  r = 0
  a = 1 << (Math.log(x) / n / Math.log(2))
  while a > 0
    ra = r | a
    d = x - ra ** n
    return ra if d == 0
    r    = ra if d  > 0
    a >>= 1
  end
  return nil
end

b = 0

while true do
  a5 =(x - b ** 5).abs
  a = root(a5, 5)

  if a
    [
      [a,b],
      [-a,b],
      [a,-b],
      [-a,-b],
    ].each do |a1, b1|
      if (a1 ** 5 - b1 **5) == x
        puts "#{a1} #{b1}" 
        exit 0
      end
    end
  end

  b += 1
end


Measured memory_bytes: 14452
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	string ans = "No";
	if(abs(a-c) <= d) ans = "Yes";
	if(abs(a-b) <= d && abs(b-c) <= d) ans = "Yes";
	
	cout << ans << endl;
	return 0;
}

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

vector<int> v[100002];

int rec(int k){
    int l = v[k].size();
    if(l == 0) return 0;
    vector<int> w(l);
    for(int i = 0; i < l; i++){
        w[i] = rec(v[k][i]);
    }
    int res = 1;
    sort(w.begin(), w.end(), greater<int>());
    for(int i = 0; i < l; i++){
        res = max(res, w[i] + i + 1);
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    int a[100002];
    for(int i = 2; i <= n; i++){
        cin >> a[i];
        v[a[i]].push_back(i);
    }
    cout << rec(1) << endl;
}

Measured memory_bytes: 17024
list1 = [int(i) for i in input().split()];

A = list1[0];   #A個口の電源タップ
B = list1[1];   #未使用の差込口を B口以上に拡張したい
#print(list1)
#print(list1[1])
addSupply = 1;
lack   = (B-A); #足りない個数
if lack >0:
    addSupply = 1;
    addSupply += lack / (A-1); #残りの個数 
 
    if lack % (A-1) >0:
        addSupply +=1;
elif B==1 :
    addSupply = 0;

print(int(addSupply));

Measured memory_bytes: 3064
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [_, x] <- fmap read . words <$> getLine :: IO [Int]
    xs <- fmap read . words <$> getLine :: IO [Int]
    let ys = sort (x:xs)
    let d = minimum $ fmap (\(a,b) -> b-a) $ zip ys (tail ys)
    let f d = let r = (head ys) `mod` d
              in all (== r) (fmap (`mod` d) ys)
    let ans = head $ filter f [d, d-1 .. 1]
    print ans

Measured memory_bytes: 39804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> p(r);
    vector<vector<int>> dp(n);
    int ans = INT_MAX;
    
    rep(i, n) {
        dp[i].resize(n, 2e8);
        dp[i][i] = 0;
    }
    
    rep(i, r) {
        cin >> p[i];
        p[i]--;
    }
    
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }
    
    rep(i, n) {
        rep(ii, n) {
            rep(iii, n) {
                dp[ii][iii] = min(dp[ii][iii], dp[ii][i] + dp[i][iii]);
            }
        }
    }
    
    sort(all(p));
    
    do {
        int tmp = 0;
        
        rep(i, sz(p) - 1) {
            tmp += dp[p[i]][p[i + 1]];
        }
        
        ans = min(ans, tmp);
    }
    while(next_permutation(all(p)));
    
    cout << ans << endl;
    return 0;
}


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



int main() {
  int a,c;
  char b;
  cin >> a >> b >> c;
  if(b == '+'){
    
    cout << a + c << endl;
  }
  else{
    cout << a - c << endl;
  }
  
  
}

Measured memory_bytes: 3556
function main(input) {
    input = input.split("\n");
    x = input[1].split(" ").map(x => Number(x));
    var total = 0;
    for (var i = 0; i < x.length; i++) {
        total += x[i];
    }
    var p = Math.round(total/x.length);
    var ans = 0;
    for (var i = 0; i < x.length; i++) {
        ans += Math.abs(Math.pow((x[i] - p), 2));
    }

    console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
 
/*
//functions from gfg
 
long long int power(long long int x,long long int y,long long  int p)
{
    long long int res = 1;     // Initialize result
 
    x = x % p;  // Update x if it is more than or 
                // equal to p
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            {//d=(long double)x/p;
            res = (res*x) % p;
            }
 
        // y must be even now
        y = y>>1; // y = y/2
        x=(x*x)%p;
        
    }
    return res%p;
}
 
long long int gcd(long long int a,long long int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
long long int binomialCoeff(long long int n, ll k) 
{ 
    ll res = 1; 
  
    // Since C(n, k) = C(n, n-k) 
    if (k > n - k) 
        k = n - k; 
  
    // Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1] 
    for (ll i = 0; i < k; ++i) 
    { 
        res *= (n - i); 
        res /= (i + 1); 
    } 
  
    return res; 
} 
 

void sieve(int n, vector<ll> &primes) 
{ 
    vector<int> prime(n,1);
    ll p;
    for ( p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == 1) 
        { 
            
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 0; 
        } 
    } 
  
    for(p=2;p<=n;p++)
    {
        if(prime[p])
        primes.pb(p);
    }
   
} 


void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
    vis[src]=1;
    for(ll i=0;i<adj[src].size();i++)
    {
        if(vis[adj[src][i]]==0)
        dfs(adj,adj[src][i],vis)
    }
}
 
*/

ll calc(ll h)
{
	if(h==1)
      return 1;
  	else return 1 + (2*calc(h/2));
}

int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    
    
    	ll n,i,j,p,x,h,m,ans=0;
        cin>>h;
        
        
        cout<<calc(h)<<endl;
        
        
    
    
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<a[i]<<" ";
    // }
    // cout<<endl;
    
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    std::string S;
    ll K;
    std::cin >> S >> K;
    long double pos = 0.0;
    for(int i = 0; i < K; i++){
        if(S[i] != '1'){
            std::cout << S[i] << std::endl;
            return 0;
        }
    }

    std::cout << S[K - 1] << std::endl;

    return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll steps_slow(ll k, ll x, ll y) {
	ll n = 50;
	vvl dist(n,vl(n,oo));
	queue<pll> q;
	dist[n/2][n/2] = 0;
	q.emplace(n/2,n/2);
	
	while (sz(q)) {
		ll x, y;
		tie(x,y) = q.front();
		q.pop();
		FOR(dx,-k,k+1) {
			ll nx = x+dx;
			ll dy = k-abs(dx);
			for (ll ny: {y-dy,y+dy}) {
				if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
				if (dist[nx][ny] < oo) continue;
				dist[nx][ny] = dist[x][y] + 1;
				q.emplace(nx,ny);
			}
		}
	}
	ll res = dist[n/2+x][n/2+y];
	if (res == oo) res = -1;
	return res;
}

ll steps(ll k, ll x, ll y) {
	ll r = abs(x) + abs(y);

	if (r == 0) return 0;
	if (r == k) return 1;
	if (k%2 == 0 && r%2 == 1) return -1;
	if (k == 1) return r;
	
	ll t = max((r+k-1)/k,2LL);
	if ((t*k)%2 != r%2) t++;
	return t;	
}

pll in_two(ll k, ll x, ll y) {
	assert(steps(k,x,y) == 2);

	if (x < 0) {
		pll p = in_two(k,-x,y);
		return {-p.xx,p.yy};
	}
	if (y < 0) {
		pll p = in_two(k,x,-y);
		return {p.xx,-p.yy};
	}
	if (x < y) {
		pll p = in_two(k,y,x);
		return {p.yy,p.xx};
	}
	assert(0 <= y && y <= x);
	
	ll nx = (x+y)/2;
	ll ny = nx-k;

	assert(abs(nx)+abs(ny) == k);
	assert(abs(x-nx)+abs(y-ny) == k);

	return {nx,ny};
}

vector<pll> res;


void rec(ll k, ll x, ll y) {
	ll r = abs(x)+abs(y);
	if (r == 0) return;
	res.eb(x,y);
	
	FOR(dx,-1,2) FOR(dy,-1,2) if (abs(dx)+abs(dy) == 1) {
		ll nx = x+k*dx, ny = y+k*dy;
		if (steps(k,nx,ny) == steps(k,x,y)-1) {
			return rec(k,nx,ny);
		}
	}
	assert(steps(k,x,y) < 3);

	if (steps(k,x,y) == 1) return;
	
	res.pb(in_two(k,x,y));
}

void solve(ll k, ll x, ll y) {
	if (k%2 == 0 && (x+y)%2 != 0) {
		cout << -1 << endl;
	} else {
		res.clear();
		rec(k,x,y);
		cout << sz(res) << endl;
		reverse(all(res));
		for (pll p: res) cout << p.xx << " " << p.yy << endl;
	}	
}

void test() {
	FOR(k,1,10) FOR(x,-10,10) FOR(y,-10,10) {
		cout << k << " " << x << " " << y << endl;
		assert(steps(k,x,y) == steps_slow(k,x,y));
		solve(k,x,y);
		cout << "----------------------------------" << endl;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	//test();

	ll k, x, y;
	cin >> k >> x >> y;
	solve(k,x,y);

}



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

using namespace std;

int main() {
    long long a, b;
    cin >> a >> b;
    long long k = (a + b) >> 1LL;
    if ((a + b) % 2) cout << "IMPOSSIBLE" << endl;
    else cout << k << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
char c[120000]; int n, r[120000];
bool hantei(int a, int b, int c, char t) {
	if (t == 'o' && b == 0) { if (a == c)return true; return false; }
	if (t == 'o' && b == 1) { if (a != c)return true; return false; }
	if (t == 'x' && b == 0) { if (a != c)return true; return false; }
	if (t == 'x' && b == 1) { if (a == c)return true; return false; }
}
int main() {
	bool OK = false;
	cin >> n; for (int i = 0; i < n; i++)cin >> c[i];
	for (int i = 0; i < 4; i++) {
		r[0] = (i / 2); r[1] = (i % 2);
		for (int j = 2; j < n; j++) {
			if (c[j - 1] == 'o') { r[j] = r[j - 2]; }
			if (c[j - 1] == 'x') { r[j] = 1 - r[j - 2]; }
			if (r[j - 1] == 1)r[j] = 1 - r[j];
		}
		if (hantei(r[n - 2], r[n - 1], r[0], c[n - 1]) == false)continue;
		if (hantei(r[n - 1], r[0], r[1], c[0]) == false)continue;
		for (int j = 0; j < n; j++) { if (r[j] == 0)cout << "S"; else cout << "W"; }cout << endl;
		OK = true; break;
	}
	if (OK == false)cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 768
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        a: [[usize; w]; h],
    }
    let mut a = a;
    let mut result = vec![];
    for i in 0..h {
        for k in 0..w {
            let j = if i % 2 == 0 { k } else { w - 1 - k };
            if a[i][j] % 2 == 1 {
                let i_next = if (i % 2 == 0 && j == w - 1) || (i % 2 == 1 && j == 0) {
                    i + 1
                } else {
                    i
                };
                let j_next = if (i % 2 == 0 && j == w - 1) || (i % 2 == 1 && j == 0) {
                    j
                } else if i % 2 == 0 {
                    j + 1
                } else {
                    j - 1
                };
                if i_next < h {
                    a[i][j] -= 1;
                    a[i_next][j_next] += 1;
                    result.push((i, j, i_next, j_next));
                }
            }
        }
    }
    println!("{}", result.len());
    for (i0, j0, i1, j1) in result {
        println!("{} {} {} {}", i0 + 1, j0 + 1, i1 + 1, j1 + 1);
    }
}


Measured memory_bytes: 13304
#include <iostream>
using namespace std;
int main(void){
    int W,H,x,y,r;
        cin >> W;
        cin >> H;
        cin >> x;
        cin >> y;
        cin >> r;
        if(x < W && x - r >= 0 && x + r <= W && y < H && y - r >= 0 && y + r <= H){
           cout << "Yes";
        }
        else{
            cout << "No";
        }
        cout << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
	int i,a[10001],b[10001];
	for(a[0]=1,b[0]=1,i=1;a[i-1]!=0||b[i-1]!=0;i++) cin>>a[i]>>b[i];
	i--;
	for(int j=1;j<i;j++){
		for(int h=0;h<a[j];h++){
			for(int w=0;w<b[j];w++){
				if(h==0||w==0||h==a[j]-1||w==b[j]-1) cout<<'#';
				else cout<<'.';
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        long ans;

        if((B-A)%2==0){
           ans = (B-A)/2;
        }else{
            long stop=0;
            long turn=0;
            if((N-B)>A-1){
                stop = B-1;
                turn = (((long)(B-A)/2)+1) + (A-1);
            }else{
                stop = N-A;
                turn = (((long)(B-A)/2)+1) + (N-B);
            }
            ans = Math.min(stop, turn);
        }


        System.out.println(ans);

    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
main(){
   string s;
   cin>>s;
   int a,ans=999999,b=s.size();
   int i=0;
   for(int a=0;i<b-1;i++){
       if(s[i]!=s[i+1]){
           if(ans>fmax(b-i-1,i+1)){
               ans=fmax(b-i-1,i+1);
           }
       }
   }
   if(ans>b){
       cout<<b<<endl;
   }
   else{
       cout<<ans<<endl;
   }
}

Measured memory_bytes: 512
import sys
n,m,q=map(int,input().split())


a=[]
b=[]
c=[]
d=[]
for i in range(0,q):
    ay,by1,cy,dy=map(int,input().split())
    a.append(ay)
    b.append(by1)
    c.append(cy)
    d.append(dy)
s=0
smax=-100

sys.setrecursionlimit(3000)



def dfs(h):
    global smax
    if len(h)==n+1:
        s=0
        for j in range(0,q):
            if h[b[j]]-h[a[j]]==c[j]:
                s+=d[j]
        if s>smax:
            smax=s

        return
    
    for i in range(0,m+1-h[len(h)-1]):
        
        h2=h[:]
        h2.append(h[len(h)-1]+i)
        dfs(h2)

sta=[1]
dfs(sta)
print(smax)

Measured memory_bytes: 9172
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;
int gcd(int a,int b){
    if(a < b){
        int c = a;
        a = b;
        b = c;
    }
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	vll a(n);
	rep(i,n)cin >> a[i];

	int cnt = 0;
	int m = 1;
	rep(i,n){
		if(a[i] == m){
			m++;
		}
	}
	m--;
	if(m==0)cout << -1 << endl;
	else cout << n-m << endl;

   
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc148.contest.atcoder.jp/tasks/abc148_b

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main()
{
    long long int a, b, k;
    cin >> a >> b >> k;

    if(k >= a + b)
    	cout << "0 " << "0" << endl;
    else if(k > a)
    	cout << "0 " << b - (k - a) << endl;
    else
    	cout << a - k << " " << b << endl;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int H,W;
  cin >> H >> W;
  vector<vector<ll>> dp(H, vector<ll>(W, 0));

  vector<string> v(H);
  for(int i = 0; i < H; i++){
    cin >> v.at(i);
  }

  dp[0][0] = 1;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(i+1 < H && v.at(i+1).at(j) == '.' ) {
        dp[i+1][j] += dp[i][j];
        dp[i+1][j] %= MOD;
      }
      if(j+1 < W && v.at(i).at(j+1) == '.' ){
        dp[i][j+1] += dp[i][j];
        dp[i][j+1] %= MOD;
      }
    }
  }
  cout << dp[H-1][W-1]%MOD << endl;
}


Measured memory_bytes: 9216
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

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

N,K = inputIL()

l = [0 for _ in range(N)]

for k in range(K):
  n = input()
  l_ = inputIL()
  for item in l_:
    l[item-1] += 1
ans = 0
for item in l:
  if item == 0:
    ans += 1
    
print(ans)

Measured memory_bytes: 73008
open System

let N = stdin.ReadLine()|>int
[<EntryPoint>]
let main argv =
    let rec keta n = if n  < 10 then 1 else (keta (n/10))+1 
    
    [1..N]
    |>Seq.sumBy(fun m ->  if (keta m) % 2 <> 0 then 1 else 0)
    |>stdout.WriteLine
    0
   

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    string s;
    cin>>s;
    char ans[15];
    int j=0,l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='B')
        {
            if(j>0)
                j--;
        }
        else
            ans[j++]=s[i];
    }
    ans[j++]='\0';
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256