akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
//给出两个数a,b 求出[a,b]中各位数字之和能整除原数的数的个数。
public class Main {

    int mod ;
    //
    //int[][] dp = new int[1001][1001];
    void solve(int n, int q, int [] arr, int[][] ops) {
        Map<Integer,Integer> mp = new HashMap<>();
        long cnt = 0;
        for(int i=0;i<n;i++){
            cnt+=arr[i];
            mp.put(arr[i],mp.getOrDefault(arr[i],0)+1);
        }
        for(int i=0;i<q;i++){
            int a1 = ops[i][0];
            int b1 = ops[i][1];
            if(mp.containsKey(a1)){
                int get = mp.get(a1);
                cnt+=(b1-a1)*get;
                mp.put(b1,mp.getOrDefault(b1,0)+get);
                mp.remove(a1);
            }

            System.out.println(cnt);
        }

    }



    public static void main(String[] args)  throws IOException {
        // Use the Scanner class

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[]  s = br.readLine().split(" ");
        Main test = new Main();

        int n = Integer.parseInt(s[0]);
        s = br.readLine().split(" ");
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(s[i]);
        }
        s = br.readLine().split(" ");
        int q = Integer.parseInt(s[0]);
        int[][] ops = new int[q][2];
        for(int i=0;i<q;i++){
            s = br.readLine().split(" ");
            ops[i][0] = Integer.parseInt(s[0]);
            ops[i][1] = Integer.parseInt(s[1]);
        }

        test.solve(n, q, arr, ops);
        //int tot = Integer.parseInt(br.readLine());


//        int i =1;
//        System.out.println();
//        while(tot>0){
//
//            String s = br.readLine();
//            String[] sr = s.split(" ");
//            List<Long> ls = new ArrayList<>();
//            for(String ss:sr){
//                ls.add(Long.parseLong(ss));
//            }
//            Main tt = new Main();
//            tt.sol(ls);
//            // String Buffer to store answer
//            StringBuffer sb = new StringBuffer();
////            Solution obj = new Solution();
////
////            System.out.println("Case #"+i+": "+obj.sol());
//            tot--;
//            i++;
//        }
    }

}


Measured memory_bytes: 68720
#include <bits/stdc++.h>
#define maxn 200005
#define ll long long
#define ld double
#define mod 1000000007
using namespace std;
char s[maxn];
int a[maxn], cnt;
int main()
{
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	for(int i = 1; i <= n; )
	{
		if(s[i] == 'A') a[cnt++] = 2, i++;
		else if(s[i] == 'B' && s[i + 1] == 'C')
			a[cnt++] = 1, i += 2;
		else
			a[cnt++] = 3, i++;
	}
//	cout<<cnt<<endl;
//	for(int i = 0; i < cnt; i++)
//		cout<<a[i]<<" ";
	ll ans = 0;
	for(int i = 0; i < cnt; )
	{
		if(a[i] == 3)
		{
			i++;
			continue;
		}
		int j = i;
		while(j < cnt && a[j] != 3) j++;
		ll s = 0;
		for(int k = i; k < j; k++)
			if(a[k] == 1) s += k;
		sort(a + i, a + j);
		for(int k = i; k < j; k++)
			if(a[k] == 1) s -= k;
		ans += s;
		i = j;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    ll a=lin(),b=lin(),c=lin(),d=lin();
    ll x=c*d/gcd(c,d);
    ll p=b/c-(a-1)/c;
    ll q=b/d-(a-1)/d;
    ll r=b/x-(a-1)/x;
    cout<<b-a+1-p-q+r<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
	string s;
	cin>>s;
	string x=s;
	reverse(s.begin(),s.end());
	int n=s.length();
	for(int i=0;i<n;++i)
	{
		if(s[i]=='b')s[i]='d';
        else if(s[i]=='d')s[i]='b';
        else if(s[i]=='p')s[i]='q';
        else if(s[i]=='q')s[i]='p';
	}
	if(x==s)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
     
    int main(){
      int N,count = 0,i,j;
      int P[N];
      scanf("%d",&N);
      for(i=0;i<N;i++){
        scanf("%d",&P[i]);
      }
      for(j=0;j<N;j++){
        if(P[j]!=j+1){
          count = count +1;
        }
      }
      if(count > 2){
    	printf("NO");
      }else{
        printf("YES");
      }
    }
        

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int A, B; cin >> A >> B;
    if (A+B < 10) cout << A+B << endl;
    else cout << "error" << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,W,H,sum=0,num=0,flag=0;string S,T,O;
   cin >> N >> M;
   Vecpr(P,int,int,M);
   Vec(Q,bool,N,false);Vec(U,bool,N,false);
   rep(i,0,M)cin >> P[i].first >> P[i].second;
   rep(i,0,M){
      if(P[i].first==1)Q[P[i].second-1]=true;
      if(P[i].second==N)U[P[i].first-1]=true;
   }
   rep(i,0,N)if(Q[i]&&U[i])flag=1;
   if(flag)Out("POSSIBLE");
   else Out("IMPOSSIBLE");
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    if(n%2==1){
                    cout << "No" <<endl;
            return 0;
    }
    REP(i,n/2){
        if(s.at(i)!=s.at(i+n/2)){
            cout << "No" <<endl;
            return 0;
        }
    }
    cout << "Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
flg = true
count = 0

while flg do
    c = a.reject { |n| n % 2 == 0 }.size
    if c == 0
        count += 1
        a = a.map { |n| n / 2 }
    else
        flg = false
    end
end

puts count

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

/* define const */
const int Smax = 100000;
/* finish defineing const */

string s;

// check dreamer
bool c_dr(int n)
{
  string dr = "dreamer";
  reverse(dr.begin(), dr.end());
  for (int i = n; i <= n+6; i++) {
    //    cout << s[i] << "1" << dr[i-n] << endl;;
    if (s[i] != dr[i-n] || i == s.length()) return false;

  }
  return true;
}

// check dream
bool c_dm(int n)
{
  string dm = "dream";
  reverse(dm.begin(), dm.end());
  for (int i = n; i <= n+4; i++) {
    if (s[i] != dm[i-n] || i == s.length()) return false;
    //    cout << s[i] << "2" << dm[i-n] << endl;;
  }
  return true;
}

// check eraser
bool c_er(int n)
{
  string er = "eraser";
  reverse(er.begin(), er.end());
  for (int i = n; i <= n+5; i++) {
    if (s[i] != er[i-n] || i == s.length()) return false;
    //    cout << s[i] << "3" << er[i-n] << endl;;
  }
  return true;
}
// check erase
bool c_es(int n)
{
  string es = "erase";
  reverse(es.begin(), es.end());
  for (int i = n; i <= n+4; i++) {
    if (s[i] != es[i-n] || i == s.length()) return false;
    //    cout << s[i] << "4" << es[i-n] << endl;;
  }
  return true;
}

void solve()
{
  bool flag = true;
  for (int i = 0; i < s.length() && flag; ) {
    //check dreamer
    if (c_dr(i)) {
      //      cout << 1 << endl;
      i += 7;
      if (i > s.length()) {
	flag = false;
	break;
      }
      continue;
    }
    //check dream
    if (c_dm(i)) {
      //      cout << 2 << endl;
      i += 5;
      if (i > s.length()) {
	flag = false;
	break;
      }
      continue;
    }
    //check eraser
    if (c_er(i)) {
      //      cout << 3 << s[i+6]<< endl;
      i += 6;
      if (i > s.length()) {
	flag = false;
	break;
      }
      continue;
    }
    //check erase
    if (c_es(i)) {
      //      cout << 4 << endl;
      i += 5;
      if (i > s.length()) {
	flag = false;
	break;
      }
      continue;
    }
    
    flag = false;
  }
  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}

int main()
{
  cin >> s;
  reverse(s.begin(), s.end());
  //  cout << "~" << s << endl;
  solve();
}


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

int main(){
	bool flag[26];
	string s,ans;
	int count=0;

	cin>>s;

	for(int i=0;i<26;i++)
		flag[i]=false;
	for(int i=0;i<s.length();i++)
		flag[s[i]-'a']=true;
	for(int i=25;i>=0;i--){
		if(!flag[i])ans=i+'a';	
		else count++;
	}
	
	if(count!=26)cout<<ans<<endl;
	else cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = N / 11 * 2;
    N -= N / 11 * 11;
    if(N == 0) cout << ans << endl;
    else if(N <= 6) cout << ans + 1 << endl;
    else cout << ans + 2 << 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<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int n;cin>>n;
	int ans=0;
	rep(i,n){
	    int a;cin>>a;
	    if((i+1)%2){
	        if(a%2)ans++;
	    }
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
	int n;
	int a[100];
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];

	for(int i=0; i<n; i++){
		int j;
		int tmp = a[i];
		for(j=0; j<i; j++){
			if(a[i]<a[j]){
				break;
			}
		}
		for(int k=i-1; k>=j; k--){
			a[k+1] = a[k];
		}
		a[j] = tmp;

		for(int k=0; k<n-1; k++){
			cout << a[k] << " ";
		}
		cout << a[n-1] << endl;
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    
    ll n;
    cin >> n;
    V<ll> divisors;
    for(ll i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            divisors.push_back(i);
            divisors.push_back(n/i);
        }
    }

    ll tot = 0;
    for(ll x : divisors) {
        x--;
        if(x == 0) continue;
        if(n%x == n/x) tot += x;
    }
    cout << tot << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) // cerr<<(str)<<endl;
int main() {
  int n;
  cin >> n;
  vector<int> l(n + 1, 0), r(n + 1, 0);
  rep(i, 0, n) { cin >> l[i] >> r[i]; }
  sort(all(l), greater<int>());
  sort(all(r));
  ll ma = 0;
  ll sum = 0;
  rep(i, 0, n / 2 + 1) {
    sum += 2 * (l[i] - r[i]);
    ma = max(ma, sum);
    cerr << sum << " " << ma << endl;
  }
  cout << ma;

  return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        HashMap<Integer, Integer>map = new HashMap<>();
        StringTokenizer st = new StringTokenizer(br.readLine());
        for(int i = 0;i < n;i++){
            int a = Integer.parseInt(st.nextToken());
            if(map.containsKey(a))
                map.put(a, map.get(a) + 1);
            else map.put(a, 1);
        }
        long ans = 0;
        int max1 = 0, max2 = 0;
        for(Integer key : map.keySet()){
            int val = map.get(key);
            //System.out.println(key + " " + val);
            if(val >= 4){
                ans = Math.max(ans, key*1L*key);
            }
            if(val >= 2){
                //System.out.println(max1 + " " + max2);
                if(key > max1){
                    max2 = max1;
                    max1 = key;
                }
                else if(key > max2){
                    max2 = key;
                }
                //System.out.println(max1 + " " + max2);
            }
        }
        //System.out.println(max1 + " " + max2);
        ans = Math.max(ans, max1*1L*max2);
        System.out.println(ans);
    }
}


Measured memory_bytes: 46148
//
//  main.cpp
//  MaximumSum
//
//  Created by XsC on 2018/5/5.
//  Copyright © 2018年 夏思聪. All rights reserved.
//

#include <iostream>
#include "math.h"

int a,b,c,k;

int main(int argc, const char * argv[]) {
    scanf("%d %d %d %d",&a,&b,&c,&k);
    if(a>=b && a>=c){
        while (k--) {
            a*=2;
        }
    }
    else if(b>=a && b>=c){
        while (k--) {
            b*=2;
        }
    }
    else if(c>=b && c>=a){
        int sum=0;
        while (k--) {
            c*=2;
        }
    }
    printf("%d",a+b+c);
    return 0;
}


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;
int mod = 1000000007;

void solve();

int main(void){
    ll S; cin >> S;
    int x1 = 1000000000, y1 = 1, x3 = 0, y3 = 0;
    int x2, y2;
    if(S % x1 > 0) x2 = x1 - (S % x1);
    else x2 = 0;
    y2 = (x2 +S) / x1;
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Point {

    double x;
    double y;

    Point( double x, double y ) {
	this.x = x;
	this.y = y;
    }
}

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( stdin.hasNextDouble() ) {
	    Point[] in = new Point[4];
	    for ( int i = 0; i < 4; i++ ) {
		in[i] = new Point( stdin.nextDouble(), stdin.nextDouble() );
	    }
	    final double deg1 = degree( in[3], in[0], in[1] );
	    final double deg2 = degree( in[3], in[1], in[2] );
	    final double deg3 = degree( in[3], in[2], in[0] );
	    if ( abs( deg1 + deg2 + deg3 - 2 * PI ) < 1.0e-8 ) {
		System.out.println( "YES" );
	    } else {
		System.out.println( "NO" );
	    }
	}	
    }

    static double degree( Point p1, Point p2, Point p3 ) {
	double d12 = distance( p1, p2 );
	double d13 = distance( p1, p3 );
	double d23 = distance( p2, p3 );

	return acos( ( d12 * d12 + d13 * d13 - d23 *d23 ) / ( 2 * d12 * d13 ) );
    }
    
    static double distance( Point p1, Point p2 ) {
	return sqrt( pow( p1.x - p2.x, 2.0 ) + pow( p1.y - p2.y, 2.0 ) );
    }
}

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

int main(){
    
    long long int i, x, y, N, D, count;
    
    cin >> N >> D;
    count = 0;
    
    for (i = 0; i < N; i++){
        
        cin >> x >> y;
        if (x * x + y * y <= D * D) count++;
    }
    
    cout << count << "\n";

    return 0;
}



Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int>a(N), b(N);
	vector<int>c(M), d(M);
	rep(i, N) cin >> a[i] >> b[i];
	rep(i, M) cin >> c[i] >> d[i];
	rep(i, N) 
	{
		int dist_min = 3e8;
		int j_check = 0;
		rep(j, M)
		{
			int  dist = abs(c[j] - a[i]) + abs(d[j] - b[i]);
			if (dist<dist_min)
			{
				j_check = j + 1;
				dist_min = dist;
			}
		}
		co(j_check);
	}
}

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

class plant
{
	public:
	
		double p;
		string name;
		
		plant(string N, double P){ name=N; p=P; }
		bool operator<(const plant &c) const
		{
			if(fabs(p-c.p)<1e-10)
			{
				return name<c.name;
			}
			else
			{
				return p>c.p;
			}
		}
};


int main()
{
	int n;
	while(cin >> n, n)
	{
		vector<plant> v;
		while(n--)
		{
			string L;
			int P,A,B,C,D,E,F,S,M;
		
			cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
			
			int pr = F*M*S - P;
			int tm = (A+B+C)+M*(D+E);
	
			v.push_back(plant(L, (double)pr/tm));
		}
		
		sort(v.begin(), v.end());
		
		for(int i=0; i<v.size(); i++)
		{
			cout << v[i].name << endl;
		}
		cout << "#\n";
	}



}

Measured memory_bytes: 0
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int first[110], n, i, j, mn = 0,last=0,length;
vector<int> ans;
int main()
{
	vector<int> b(110);
	cin >> n;
	length = n;
	for (i = 1; i <= n; i++)
	{
		int a;
		cin >> b[i];
	}
	//printf("size%d\n", b.size());
	for (j = 1; j <= n; j++) {
		last = MAX_INT;
		for (i = 1; i <= n; i++)
		{
			if (b[i] == i) last = i;
		}
		if (last == MAX_INT)
		{
			cout << "-1" << endl;
			return 0;
		}
		b.erase(b.begin() + last);
		//printf("size%d\n", --length);
		ans.push_back(last);
	}
	for (i = ans.size() - 1; i >= 0; i--)
	{
		cout << ans[i] << endl;
	}
}


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

int main() {
  int H, W;
  int h, w;
  cin >> H >> W;
  cin >> h >> w;
  int ans = (H-h) * (W-w);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=[0]*n
if a[0]>x:
    ans[0]=x
else:
    ans[0]=a[0]
for i in range(1,n):
    ans[i]=min(a[i],x-ans[i-1])
print(sum(a)-sum(ans))           

Measured memory_bytes: 20076
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n,k;cin>>n>>k;
    vl h(n);
    rep(i,n)cin>>h[i];
    sort(been(h));
    ll ans =INFL;
    for(int i =0;i+k-1<n;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int n; cin >> n;
    vector<int> a(n), b(n-1);
    rep(i, n-1) cin >> b[i];

    rep(i, n){
        if(i==0) a[i] = b[i];
        else if(i==n-1) a[i] = b[i-1];
        else a[i] = min(b[i], b[i-1]);
    }
    rep(i, n-1) a[i+1] += a[i];
    pr(a[n-1]);
    return 0;}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<ll,ll>
#define mp make_pair
using namespace std;
ll n,m;
int a[200005];
ll pre[200005];
int solve(int mid)
{
    int ok = 0;
    ll sum = 0;

    for(int i=0;i<n;i++)
    {
        int x = a[i];
        int y = mid-x;
        int it = lower_bound(a,a+n,y)-a;
        ll num = n-it;
        sum+=num;
    }
    if(sum >= m)
        return 1;
    return 0;
}
void solve2(int mid)
{
    ll res = 0,sum = 0;
    for(int i=0;i<n;i++)
    {
        int x = a[i];
        int y = mid-x;
        int it = lower_bound(a,a+n,y)-a;
        ll num = n-it;

        res += 1LL * num * a[i];
        sum +=num;
        res += pre[it];
    }
    ll rem = sum-m;
    res = res - (1LL*rem*mid);
    cout<<res<<endl;
    return ;
}
int main()
{
   cin>>n>>m;
   for(int i=0;i<n;i++)
   {
       scanf("%d",&a[i]);
   }
   sort(a,a+n);
   for(int i=n-1;i>=0;i--)
   {
       pre[i]+=a[i];
       if(i!=n-1)
        pre[i]+=pre[i+1];
   }
   ll st = 0 , En = 1e6;
   ll ans = 0;
   while(st <= En)
   {
       ll mid = (st+En)/2;

       if(solve(mid))
       {
           st = mid+1;
           ans = mid;
       }
       else
       {
           En = mid-1;
       }
   }
   solve2(ans);
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

long long  mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    vector<ll>b(n);

    ll s = 0;
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
        s += a[i];
    }
    bool flag = 1;
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])flag=0;
    }
    if(flag){
        cout << 0 << endl;
    }else{
        ll mi=inf;
        rep(i,n){
            if(a[i]>b[i]){
                mi = min(mi,b[i]);
            }
        }
        cout << s-mi << endl;
    }   
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int n,m;
vi adj[100];
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v; cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=1;i<=n;i++) cout<<adj[i].size()<<newl;
}


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

int main(void){
  
  	string N;
  	cin >> N;
  	(N[1]==N[2]&&(N[0]==N[1]||N[2]==N[3])) ? cout << "Yes":cout << "No";

 	return 0;
}

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

int main() {
 int N;
 cin >> N;
 vector<int> d(N);
  for(int i =0; i < N; i++) cin >> d.at(i);
  
  int total = 0;
  for(int i =0; i < N; i++){
   for(int j =0; j < N; j++){
     if(i != j) total += d.at(i) * d.at(j);
   }
  }
  cout << total/2 << endl;
}


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

using namespace std;

int main() {
	int curr = 1;
	int N, K;
	cin >> N;
	cin >> K;
	for (int i = N; i >= 1; i--) {
		if (curr * 2 < curr + K) {
			curr *= 2;
		}
		else {
			curr += K;
		}
	}
	cout << curr << endl;
	return 0;
};

Measured memory_bytes: 256
package main

import "fmt"

const MAX = 1<<31-1
var H, W, xS, xE, yS, yE int
var A []string
var magic [][]int
var visited [][]bool
var added [][]bool
var X = []int{-1,1,0,0}
var Y = []int{0,0,-1,1}
var q dll

func min(a, b int) int {
	if a < b { return a }
	return b
}

type node struct {
	x int
	y int
	prev *node
	next *node
}

type dll struct {
	head *node
	tail *node
}

func (root *dll) isEmpty() bool {
	return root.head.next == root.tail
}

func(root *dll) insertHead(x, y int) {
	tmp := root.head.next
	newNode := &node{x, y, nil, nil}
	root.head.next = newNode
	newNode.prev = root.head
	tmp.prev = newNode
	newNode.next = tmp
}

func (root *dll) insertTail(x, y int) {
	tmp := root.tail.prev
	newNode := &node{x, y, nil, nil}
	root.tail.prev = newNode
	newNode.next = root.tail
	tmp.next = newNode
	newNode.prev = tmp
}

func(root *dll) popFront() *node {
	res := root.head.next
	root.head.next = res.next
	res.next.prev = root.head
	return res
}

func valid(x, y int) bool {
	return x>=0 && x<H && y>=0 && y<W && A[x][y]!='#'
}

func bfs() {

	for !q.isEmpty() {
		cur := q.popFront()
		x, y := cur.x, cur.y
		visited[x][y] = true
		for i:=0; i<4; i++ {
			nx, ny := x + X[i], y+Y[i]
			if valid(nx, ny) && magic[nx][ny] >= magic[x][y] {
				magic[nx][ny] = magic[x][y]
			} else { continue }
			if !visited[nx][ny] {
				q.insertHead(nx, ny)
			}
		}
		for i:=-2; i<=2; i++ {
			for j:=-2; j<=2; j++ {
				nx, ny := x+i, y+j
				if valid(nx, ny) && magic[nx][ny] > magic[x][y] {
					magic[nx][ny] = min(magic[nx][ny], magic[x][y] + 1)

				} else { continue }
				if !visited[nx][ny] {
					q.insertTail(nx, ny)
				}
			}
		}
	}
}

func main() {
	fmt.Scanf("%d%d%", &H, &W)
	fmt.Scanf("%d%d%", &xS, &yS)
	fmt.Scanf("%d%d%", &xE, &yE)
	xS--
	yS--
	xE--
	yE--
	A = make([]string, H)
	for i:=0; i<H; i++ {
		fmt.Scanf("%s", &A[i])
	}
	magic, visited = make([][]int, H), make([][]bool, H)
	for i := range magic {
		magic[i] = make([]int, W)
		visited[i] = make([]bool, W)
		for j := range magic[i] {
			magic[i][j] = MAX
		}
	}
	magic[xS][yS] = 0
	head, tail := &node{}, &node{}
	head.next = tail
	tail.prev = head
	q = dll{head, tail}
	q.insertHead(xS, yS)
	bfs()
	if magic[xE][yE] == MAX {
		fmt.Println(-1)
		return
	}
	fmt.Println(magic[xE][yE])
}


Measured memory_bytes: 28244
import sys

s = sys.stdin.readline().rstrip()

def main():
    l = len(s)
    if l & 1:
        return 'No'
    if s == 'hi' * (l // 2):
        return 'Yes'
    else:
        return 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

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

 
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  int ans = 0;
  rep(i,n)rep(j,n){
    if(i<=j) continue;
    ans += d[i] * d[j];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
<?php
$n = trim(fgets(STDIN));
$s = str_split(trim(fgets(STDIN)));
$a = array_count_values($s);
$ans = 1;
foreach($a as $k => $v){
  $ans*=($v+1);
  $ans%=1000000007;
}
echo $ans-1;

Measured memory_bytes: 10872
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))

q = {0:0, 1:0, 2:0}
for i in p:
    if i <= a:
        q[0] += 1
    elif i >= b + 1:
        q[2] += 1
    else:
        q[1] += 1
print(min(q.values()))

Measured memory_bytes: 9048
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
#define RS(a) string  a; cin >> a;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
bool isPrime(int n)
{   if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
signed main()
{
    fastio;
    string t,s;
    cin>>s>>t;
    int mx=inf;
    int n=s.size(),m=t.size();
        fr(i,0,n-m+1)
    {
        int cnt=0;
        fr(j,i,i+m)
        {
            if(s[j]!=t[j-i])
            {
                cnt+=1;
            }
        }
        mx=min(mx,cnt);
    }
    cout<<mx<<endl;

}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>

int n;
bool ans = true;

int main() {
	std::cin >> n;
	int x;
	char in;
	int cnt1 = 0;
	for (int i = 0; i < n; ++i) {
		std::cin >> in >> x;
		if (in == '(')
			cnt1 += x;
		else {
			cnt1 -= x;
			if (cnt1 < 0) {
				break;
			}
		}
	}
	if (cnt1 == 0)
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;
	return 0;
}

Measured memory_bytes: 1160
N=input()
a=int(N[0])
b=int(N[1])
c=int(N[2])
d=int(N[3])
if a+b+c+d==7:
  print(N[0]+"+"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
  exit()
if a-b+c+d==7:
  print(N[0]+"-"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
  exit()
if a+b-c+d==7:
  print(N[0]+"+"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
  exit()
if a+b+c-d==7:
  print(N[0]+"+"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
  exit()
if a-b-c+d==7:
  print(N[0]+"-"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
  exit()
if a-b+c-d==7:
  print(N[0]+"-"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
  exit()
if a+b-c-d==7:
  print(N[0]+"+"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
  exit()
if a-b-c-d==7:
  print(N[0]+"-"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
  exit()

Measured memory_bytes: 3064
n, m, c = map(int, input().split())
b = list(int(x) for x in input().split())
ans = 0

for j in range(n):
    a = list(int(x) for x in input().split())
    sum = 0
    for i in range(m):
        sum += a[i]*b[i]
    if sum > -c:
        ans += 1

print(ans)

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

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

	ll nsum = 0;
	for (int i = 1; i <= n; i++)
		nsum += count_element[i] * (count_element[i] - 1) / 2;
	for (int i = 0; i < n; i++)
		cout << nsum - count_element[a[i]] + 1 << endl;
	return 0;
}


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

#ifdef LOCAL
  #include "debug.h"
#endif

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(begin(a), end(a));
  cout << a[0] + a[1] << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	long long N, A, B;
	cin >> N >> A >> B;

	if ((B - A) % 2 == 0)
	{
		cout << (B - A) / 2;
	}
	else
	{
		long long left_most = N - B;
		long long right_most = A - 1;
		cout << min(left_most, right_most) + 1 + (B - A - 1) / 2;
	}

	return 0;
}


Measured memory_bytes: 256
/*
  Fuad Ashraful Islam
  University of Asia Pacific,Bangladesh
  Date:10th May 2020
  Category:DP
  ToDo:
 */
#include<bits/stdc++.h>
#define dbg(x) cerr <<__LINE__<<" where "<< #x << " = " << x << endl
#define all(x) (x).begin(),(x).end()

using namespace std;
template <class T> inline void read(T &res)
{
    res = 0; bool bo = 0; char c;
    while (((c = getchar()) < '0' || c > '9') && c != '-');
    if (c == '-') bo = 1; else res = c - 48;
    while ((c = getchar()) >= '0' && c <= '9')
        res = (res << 3) + (res << 1) + (c - 48);
    if (bo) res = ~res + 1;
}
const int N=2e5+5;
typedef long long ll;
int len,_,n,d,k,m,l,c,cs=1;
string s,t;

void HalfDead() 
{
  
  int a,b,c;
  read(a); read(b); read(c); read(k);
  int ans=min(a,k);
  k-=min(a,k);
  k-=min(b,k);
  ans-=min(c,k);
  cout<<ans<<"\n";
}
int main()
{
  HalfDead();
  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll ans = 1e18;
ll a[105000];

ll f() {
    ll nowans = 0;
    ll sum = a[1];
    for(int i = 2; i <= N; i++) {
        ll newsum = sum + a[i];
        if((sum > 0 && newsum < 0) || (sum < 0 && newsum > 0)) {
            sum = newsum;
            continue;
        }
        if(sum > 0) {
            nowans += newsum + 1;
            sum = -1;
            continue;
        } else {
            nowans += 1 - newsum;
            sum = 1;
            continue;
        }
    }
    return nowans;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> a[i];
    if(a[1] != 0) chmin(ans, f());
    ll val = a[1];
    a[1] = 1;
    chmin(ans, f() + abs(val - 1));
    a[1] = -1;
    chmin(ans, f() + abs(val + 1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){
    int a, b, c, count, i;
    count = 0;
    cin >> a >> b >> c;
    for (i=a; (i<=b); i = i+1 ){
        if (c % i == 0){
            count = count + 1;
        } 
    }
    cout << count <<endl;
    return 0;
}


Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

//http://codeforces.com/contest/1095/problem/B
public class Main {

	public static void main(String[] args) throws Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		XeniaAndBitOperations solver = new XeniaAndBitOperations();
		// int test = in.nextInt();
		// while (test-- > 0)
		solver.solve(1, in, out);
		out.close();
	}

	static class XeniaAndBitOperations {

		public void solve(int testNumber, InputReader in, PrintWriter out) throws Exception {

			int n = in.nextInt();
			int k = in.nextInt();
			int h[] = new int[n];
			int dp[] = new int[n];

			for (int i = 0; i < n; i++)
				h[i] = in.nextInt();

//			int ans = mincost(n - 1, h);
//			System.out.println(ans);
			
			dp[1] = Math.abs(h[1]-h[0]);
			for(int i=2; i<n; i++)
			{	
				int min = Integer.MAX_VALUE;
				for(int j=1; j<=k; j++){
					
					if(i-j>=0){
						int temp = dp[i-j] + Math.abs(h[i] - h[i - j]);
						if(min>temp)
							min=temp;
					}
				}
//				int cost1 = dp[i-1] + Math.abs(h[i] - h[i - 1]);
//				int cost2 = dp[i-2] + Math.abs(h[i] - h[i - 2]);
				dp[i]= min;
			}
			System.out.println(dp[n-1]);
		}

		private int mincost(int i, int[] h) {
			
			if (i > 0) {
				int cost1 = mincost(i - 1, h) + (i-1>=0 ? Math.abs(h[i] - h[i - 1]) : Integer.MAX_VALUE);
				int cost2 = mincost(i - 2, h) + (i-2>=0 ? Math.abs(h[i] - h[i - 2]) : Integer.MAX_VALUE);

				return Math.min(cost1, cost2);
			}
			
			return 0;
		}

	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}

Measured memory_bytes: 35636
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
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";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
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;}
const ll INF = 1LL<<60;
//const int dy[4] = {0, 1, 0, -1};
//const int dx[4] = {1, 0, -1, 0};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

ll GCD(ll a, ll b){
    if(a < 0) a = -a;
    if(b < 0) b = -b;
    if(b == 0) return a;
    else return GCD(b, a%b);
}
void solve(){
    ll a, b; cin >> a >> b;
    vector<ll> cd;
    ll gcd = GCD(a, b);
    if(gcd == 1){
        cout << 1 << endl;
        exit(0);
    }
    for(ll i=1; i*i<=gcd; i++){
        if(gcd%i == 0){
            cd.pb(i);
            cd.pb(gcd/i);
        }
    }
    sort(ALL(cd));
    ll res = 1;
    for(ll i=1; i<cd.size(); i++){
        if(cd[i] != -1){
            res++;
            ll div = cd[i];
            for(ll j=i; j<cd.size(); j++){
                if(cd[j]%div == 0) cd[j] = -1;
            }
        }
    }
    cout << res << endl;
}

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

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

void solve() 
{
    ll n;cin>>n;
    ll t=26,s=0,cnt=1;
    while(!(s<n&&n<=s+t))s+=t,t*=26,cnt++;
    n-=s;
    REP(i,cnt-1){
        ll tmp=(n-1)/pow(26,cnt-i-1);
        cout<<(char)('a'+tmp);
        n-=tmp*pow(26,cnt-i-1);
    }
    cout<<(char)('a'+n+(n==0?25:-1))<<endl;
}

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

Measured memory_bytes: 4096
# ABC141
from collections import Counter


def main():
    N, K, Q, *A = map(int, open(0).read().split())
    C = Counter(A)
    ans = []
    for i in range(1, N + 1):
        x = "Yes" if K - Q + C[i] > 0 else "No"
        ans.append(x)
    print("\n".join(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 14324
#include<stdio.h>
int main()
{
	int i,e[4],tmp;
	for(i=0;i<4;i++){
		scanf("%d",&e[i]);
	}
	for(i=0;i<4;i++){
		if(e[i]<e[i+1]){
			tmp=e[i+1];
			e[i+1]=e[i];
			e[i]=tmp;
		}
	}
	
	for(i=0;i<4;i++){
		if(e[i]<e[i+1]){
			tmp=e[i+1];
			e[i+1]=e[i];
			e[i]=tmp;
		}
	}
	if(e[0]==e[1]&&e[2]==e[3])
	puts("yes");
	else
	puts("no");
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int s,ans=1;
    cin >> s;
    
    while(1){
        if(s==4 or s==2 or s==1)break;
        else if(s%2==0)s=s/2;
        else s=3*s+1;
        ans++;
    }
    
    cout << ans+3;

	return 0;
}

Measured memory_bytes: 3616