akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9+7;
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin>>n;
  if(n%2==0)
    ou(n/2);
  else ou(n/2+1);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n;

	while (cin >> n)
	{	
		if (n == 0) break;
		vector<int> A(n);
		int su = 0, sum = 0;
		
		for (int i = 0; i < n; i++)
		{
			cin >> A[i]; su += A[i];
		}

		int m = su / n;
		for (int i = 0; i < n; i++)
		{
			if (A[i] <= m) sum++;
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
read h w;
s=(`dd`);
dx=(0 1 0 -1 1 1 -1 -1);
dy=(1 0 -1 0 1 -1 1 -1);
for((i=0;i<h;i++))do
	for((j=0;j<w;j++))do
		if [ ${s[$i]:$j:1} = "." ];then
			c=0;
			for((r=0;r<8;r++))do
				tx=$[i+${dx[r]}];
				ty=$[j+${dy[r]}];
				if [ $tx -ge 0 -a $ty -ge 0 -a $tx -lt $h -a $ty -lt $w ];then
					if [ ${s[$tx]:$ty:1} = "#" ];then
						c=$[c+1];
					fi
				fi
			done
			echo -n $c;
		else
			echo -n ${s[$i]:$j:1};
		fi
	done
	echo '';
done

Measured memory_bytes: 540
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int maxi=0;
    int x=0;
    int n;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='I')
            x++;
        else
            x--;
        maxi=max(maxi,x);
    }
    cout<<maxi;
    return 0;
}


Measured memory_bytes: 256
//?????????????????????????¢??????????????????????, ??????????????????????????¨???????????§?????????
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

int n;
double r[500];
double pos[500];	//pos[i] = ???i????????????x??§?¨? (???????£???????????????¢)

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> r[i];
	
	pos[0] = r[0];
	for (i = 1; i < n; i++) {
		pos[i] = r[i];
		for (j = 0; j < i; j++) {
			double sub = max(r[i], r[j]) - min(r[i], r[j]);
			double plus = r[i] + r[j];
			double dist = sqrt(plus * plus - sub * sub);
			pos[i] = max(pos[i], pos[j] + dist);
		}
	}
	
	double ans = 0;
	for (i = 0; i < n; i++) {
		ans = max(r[i] + pos[i], ans);
	}
	
	printf("%.14f\n", ans);
	return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <functional>
using namespace std;

typedef std::pair<std::string,double> sip;

struct str_pair_less {
	bool operator()(const sip& x, const sip& y) const {
        if(x.second==y.second){
            return x.first < y.first;
        }
		return x.second > y.second;
	}
};

int main() {
	int n;
	while (cin >> n, n) {
		vector<sip> vp;
		for (int i = 0; i < n; ++i) {
			string name; cin >> name;
			double p, a, b, c, d, e, f, s, m;
			cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			double eff = 0.0;
			if (m == 1) {
				eff = (s*f - p) / (a + b + c + d + e);
			}
			else {
				eff = (s*f*m - p) / (a + b + c + d + e + (d + e)*(m - 1));
			}
			vp.push_back({ name, eff });
		}
		sort(vp.begin(), vp.end(), str_pair_less());
		
		for (int i = 0; i < vp.size(); ++i) {
			cout << vp[i].first << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}


Measured memory_bytes: 3272
R, G, B, N = map(int, input().split())
ans = 0
mb = N//B+1
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G)/B
        if 0 <= b < mb and int(b) == b:
            ans += 1
print(ans)

Measured memory_bytes: 41068
N=int(input())
P=list(map(int,input().split()))
MIN=10**9#Nの制約よりも十分に大きい数
ans=0
for i in range(N):
    if P[i]<=MIN:
        ans+=1
        MIN=P[i]#累積最小値で左から順に値を更新していく
print(ans)

Measured memory_bytes: 75344
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    Vi vi;

    signed call_of_Cthulhu( signed datum ) {

        int a, b, c;
        read a >> b >> c;
        for ( int i = 1; i <= std::max(a, b); i++ ) {
            if ( a % i == 0 && b % i == 0 ) vi.bash(i);
        }
        echo vi[vi.size()-c] fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main()
{
    int a,b,c,data=0;
    int d[3]={};
    
    cin >> data;
    
    for (int i=0; data>i; i++) {

        cin >> d[0] >> d[1] >> d[2];
        
        sort(d,d+3);
        
        a=d[0];
        b=d[1];
        c=d[2];
        
        if (c*c == a*a+b*b) {
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1168
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B,C,K=get_i
ans=A-B
if K.odd?
    ans*=-1
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s, t;std::cin >> s;std::cin >> t;
  ll n = s.size(), m = t.size();
  bool flag = false;
  for(int i=0;i<=n-m;i++){
    bool k = true;
    for(int j=0;j<m;j++){
      if(s[i+j]!='?'&&s[i+j]!=t[j]){
        k = false;
        break;
      }
    }
    if(k) flag = true;
  }
  string ans = "";
  re(i, n) ans += 'z';
  if(!flag){
    std::cout << "UNRESTORABLE" << '\n';
    return 0;
  }
  for(int i=0;i<=n-m;i++){
    bool k = true;
    string tmp = s;
    for(int j=0;j<m;j++){
      if(s[i+j]!='?'&&s[i+j]!=t[j]){
        k = false;
        break;
      }else tmp[i+j] = t[j];
    }
    if(k){
      re(j, n) if(tmp[j]=='?') tmp[j] = 'a';
      if(tmp<ans) ans = tmp;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1016
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cstdio>
#include <iostream>

using namespace std;
double dp[100000+1];
main(){

  int n;
  while( cin >> n ) {
    if(n == 0)break;
    double ans = 0;
    fill(dp, dp +n+1, 0);
    for(int i=0; i<=n; i++){
      double rate = 1, prate=1, base=1 - dp[i];
      for(int j=i+1; j<=n; j++){
	double nrate = rate * prate;
	if(nrate < 0.0000000001)break;
	dp[j] += (nrate * base);
	prate = nrate;
	rate *= 0.5;
      }
      ans += dp[i];
    }
    printf("%0.8lf\n",ans);
  }
}

Measured memory_bytes: 1972
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int A;
  int B;
  int C;
  int D;
  int E;
  int k;
  cin >>A>>B>>C>>D>>E>>k;
  vector<int>vec(10);
  vec.at(0)=B-A;
  vec.at(1)=C-A;
  vec.at(2)=D-A;
  vec.at(3)=E-A;
  vec.at(4)=C-B;
  vec.at(5)=D-B;
  vec.at(6)=E-B;
  vec.at(7)=D-C;
  vec.at(8)=E-C;
  vec.at(9)=E-D;
  bool answer=true;
  rep(i,10) {
if (vec.at(i)>k) {
  answer=false;
  break;
}
  }
  if(answer) {
cout <<"Yay!" << endl;
  }
else {
cout << ":(" << endl;
}
}
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    
    int ans = 0;
    
    for(int i=1;i<=N;i++){
        if(1<=i && i<=9){
            ans++;
        }
        if(100<=i && i<=999){
            ans++;
        }
        if(10000<=i && i<=99999){
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

// ModInt begin

template <int MOD> class ModInt {
private:
  int x;

  ModInt inverse() const {
    int a = x, b = MOD, u = 1, v = 0;
    while (b) {
      auto t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    return ModInt(u);
  }

public:
  ModInt() = default;
  ModInt(ModInt &&) = default;
  ModInt &operator=(ModInt &&) = default;
  ModInt(const ModInt &) = default;
  ModInt &operator=(const ModInt &) = default;
  ~ModInt() = default;

  template <typename T> ModInt(T x) : x(((x % MOD) + MOD) % MOD) {}

  auto value() const { return x; }

  ModInt &operator+=(const ModInt &mx) {
    x = (x + mx.x) % MOD;
    return *this;
  }
  ModInt &operator-=(const ModInt &mx) {
    x = (x - mx.x + MOD) % MOD;
    return *this;
  }
  ModInt &operator*=(const ModInt &mx) {
    x = (int)((long long)x * mx.x % MOD);
    return *this;
  }
  ModInt &operator/=(const ModInt &mx) {
    x = (ModInt(x) * mx.inverse()).value();
    return *this;
  }
};
template <int MOD>
bool operator==(const ModInt<MOD> &lhs, const ModInt<MOD> &rhs) {
  return lhs.value() == rhs.value();
}
template <int MOD>
ModInt<MOD> operator+(const ModInt<MOD> &lhs, const ModInt<MOD> &rhs) {
  return ModInt<MOD>(lhs) += rhs;
}
template <int MOD>
ModInt<MOD> operator-(const ModInt<MOD> &lhs, const ModInt<MOD> &rhs) {
  return ModInt<MOD>(lhs) -= rhs;
}
template <int MOD>
ModInt<MOD> operator*(const ModInt<MOD> &lhs, const ModInt<MOD> &rhs) {
  return ModInt<MOD>(lhs) *= rhs;
}
template <int MOD>
ModInt<MOD> operator/(const ModInt<MOD> &lhs, const ModInt<MOD> &rhs) {
  return ModInt<MOD>(lhs) /= rhs;
}
template <int MOD> ostream &operator<<(ostream &os, const ModInt<MOD> &mx) {
  return os << mx.value();
}
template <int MOD> istream &operator>>(istream &is, ModInt<MOD> &mx) {
  long long x;
  is >> x;
  mx = ModInt<MOD>(x);
  return is;
}

template <typename T> auto myPow(T x, long long n) {
  return (!n) ? 1 : (myPow((x * x), n >> 1) * ((n & 1) ? x : 1));
}

// ModInt end

using mint = ModInt<998244353>;

int main() {
  int n;
  cin >> n;
  vector<mint> comb(n + 1, 1);
  for (int i = 1; i <= n; ++i) {
    comb[i] = (comb[i - 1] * mint(n - i + 1) / mint(i));
  }
  ll a, b, k;
  cin >> a >> b >> k;
  mint ans = 0;
  for (int i = 0; i <= n; ++i) {
    ll j = k - a * i;
    if (j < 0)
      break;
    if (j % b == 0) {
      j /= b;
      if (j > n)
        continue;
      ans += (comb[i] * comb[j]);
    }
  }
  cout << ans << endl;
}

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

int main(){
    vector<int> data(2);
    while(true){
        cin >> data.at(0) >> data.at(1);
        if(data.at(0) == 0 && data.at(1) == 0){
            break;
        }
        else{
            sort(data.begin(),data.end());
            cout << data.at(0) << " " <<data.at(1) << endl;
        }
    }
}



Measured memory_bytes: 2984
s = gets.chomp

a = s.slice(0..1).to_i
b = s.slice(2..3).to_i

def month?(n)
  n > 0 && n < 13
end

ans = if month?(a)
        if month?(b)
          'AMBIGUOUS'
        else
          'MMYY'
        end
      else
        if month?(b)
          'YYMM'
        else
          'NA'
        end
      end
puts ans


Measured memory_bytes: 3836
import scala.io.StdIn.readInt
import scala.language.postfixOps

object Main {
  implicit class Add(p1:(Double,Double)) {
    def +(p2:(Double,Double)) = (p1._1+p2._1,p1._2+p2._2)
    def /(p2:Double) = (p1._1/p2,p1._2/p2)
    def *(p2:Double) = (p1._1*p2,p1._2*p2)
  }

  val angle = Math.PI/3
  def main(args:Array[String]) = {
    val n = readInt
    var list = Iterator(((0D,0D),(100D,0D)))
    var last = (0D,0D)
    (1 to n).foreach { _=>
      list = for{
        i<-list;
        p1 = i._1*2/3+i._2/3
        p2 = i._1/3+i._2*2/3
        x = (p2._1-p1._1)*Math.cos(angle)-(p2._2-p1._2)*Math.sin(angle)+p1._1
        y = (p2._1-p1._1)*Math.sin(angle)+(p2._2-p1._2)*Math.cos(angle)+p1._2
        p3 = (x,y)
        j<-List((i._1,p1),(p1,p3),(p3,p2),(p2,i._2)) iterator
      } yield j
    }
    for(i<-list) {
      printf("%.8f %.8f\n",i._1._1,i._1._2)
      last = i._2
    }
    printf("%.8f %.8f\n",last._1,last._2)
  }
}

Measured memory_bytes: 66284
#include <cstdio>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int num5 = 0, num7 = 0;

    if (a == 5)
        num5 += 1; // num5 = num5 + 1;
    else if (a == 7)
        num7 += 1;

    if (b == 5)
        num5 += 1; // num5 = num5 + 1;
    else if (b == 7)
        num7 += 1;

    if (c == 5)
        num5 += 1; // num5 = num5 + 1;
    else if (c == 7)
        num7 += 1;


    if (num5 == 2 && num7 == 1)
        printf("YES");
    else
        printf("NO");

    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }
const int dh[4] = {0, 1, 0, -1};
const int dw[4] = {1, 0, -1, 0};

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (S.substr(i, 3) == "ABC") { ans++; }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];

	ll res{INF};
	for (ll i = -100; i <= 100; ++i)
	{
		ll tmp{0};
		for (ll j = 0; j < N; ++j)
			tmp += pow(i-A[j], 2);
		res = min(res, tmp);
	}
	std::cout << res << std::endl;
}


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

using namespace std;

const int MOD = 1e9 + 7;

int main()
{
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  int ans = 0, damage = 0;
  int maxa = *max_element(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());
  for (int i = 0; i < n; i++)
  {
    if (maxa <= b[i])
    {
      ans++;
      damage += b[i];
    }
    else
      break;
    if (h <= damage)
      break;
  }
  if (damage < h)
    ans += (h - damage + maxa - 1) / maxa;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import sys
import math
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

# ===CODE===

a, b, n = map(float, input().split())

left = 1
right = n

ans = 0
num = 0
while abs(left - right) > 10 ** (-2):
    tmp_left = left + (right - left) / 3
    tmp_right = left + 2 * (right - left) / 3

    c_left = math.floor(a * left / b) - a * math.floor(left / b)
    c_right = math.floor(a * right / b) - a * math.floor(right / b)

    f_left = math.floor(a * tmp_left / b) - a * math.floor(tmp_left / b)
    f_right = math.floor(a * tmp_right / b) - a * math.floor(tmp_right / b)

    if c_left <= f_left <= f_right:
        left = tmp_left
        if ans < f_left:
            ans = f_left
            num = tmp_left

    elif f_left >= f_right >= c_right:
        right = tmp_right
        if ans < f_right:
            ans = f_right
            num = tmp_right
    else:
        if c_left > c_right:
            right = tmp_right
            if ans < f_right:
                ans = f_right
                num = tmp_right
        else:
            left = tmp_left
            if ans < f_left:
                ans = f_left
                num = tmp_left

ans1 = math.floor(a * int(num) / b) - a * math.floor(int(num) / b)
ans2 = math.floor(a * int(num + 1) / b) - a * math.floor(int(num + 1) / b)

print(int(max(ans1, ans2)))


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

vector<ll> v;

ll dp[55][55][111];
ll n, k;

ll dfs(ll l, ll r, ll cou){
	if(l > r || cou == k)return 0;
	if(cou > k)return -LLINF;
	if(dp[l][r][cou] != -LLINF)return dp[l][r][cou];

	ll ret = 0;
	ret = max(ret, dfs(l + 1, r, cou + 1) + v[l]);
	ret = max(ret, dfs(l + 1, r, cou + 2));
	ret = max(ret, dfs(l, r - 1, cou + 1) + v[r]);
	ret = max(ret, dfs(l, r - 1, cou + 2));

	return dp[l][r][cou] = ret;
}

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

	REP(i, 55)REP(j, 55)REP(k, 111)dp[i][j][k] = -LLINF;

	cin >> n >> k;
	REP(i, n){
		int tmp;cin >> tmp;
		v.PB(tmp);
	}

	cout << dfs(0, n-1, 0) << endl;

	return 0;
}


Measured memory_bytes: 2944
#include <math.h>
#include <stdio.h>
#include <string.h>
char x[11], y[12];
int idct = 1 ;
int main(void) {
    scanf("%s", x);
    scanf("%s", y);
    for (int i = 0; i < strlen(x); i++) {
        if (x[i] != y[i]) {
            idct = 0;
            break;
        }
    }
    if (idct == 0) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
}

Measured memory_bytes: 1580
#include<bits/stdc++.h>
using namespace std;
string s,t;
int main()
{
    cin>>s>>t;
    int l=s.size();
    for(int i=0;i<l;i++)
    {
        int j=0;
        for(j=0;j<l;j++)
        {
            //cout<<t[(j+i)%l];
            if(t[(j+i)%l]!=s[j])
                break;
        }
        if(j==l)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        //cout<<endl;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n,x,y = map(int,input().split())

d = {}

for i in range(1, n):
	d[i] = d.get(i, 0)

for i in range(1,n):
	for j in range(i+1,n+1):
		if i<=x and j<=y:
			k = min(j-i, (x-i)+1+(y-j))
		elif i<=x and y<=j:
			k = (x-i) + 1 + (j-y)
		elif x<=i and j<=y:
			k = min(j-i, (i-x)+1+(y-j))
		elif x<=i and y<=j:
			k = min(j-i, (i-x)+1+(j-y))
		d[k] = d.get(k, 0) + 1

for v in d.values():
	print(v)



Measured memory_bytes: 46812
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=105;
const ll mod=1e9+7;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

bool chk(int x,int y,int h,int w){
	if(x<0 || x>=h || y<0 || y>=w)
		return false;
	return true;
}
int main(){
	fast;
	int h,w,i,j,k,sx,sy,dex,dey;
	cin>>h>>w>>sx>>sy>>dex>>dey;
	--sx,--sy,--dex,--dey;
	char gr[h][w];
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>gr[i][j];
		}
	}
	vector<vector<int>> d(h,vector<int>(w,1e9));
	deque<pi> q;
	q.push_front({sx,sy});
	d[sx][sy]=0;
	while(!q.empty()){
		pi v=q.front();
		int x=v.ff;
		int y=v.ss;
		q.pop_front();
		for(i=0;i<4;i++){
			if(chk(x+dx[i],y+dy[i],h,w) && gr[x+dx[i]][y+dy[i]]!='#'){
				if(d[x][y]<d[x+dx[i]][y+dy[i]]){
					d[x+dx[i]][y+dy[i]]=d[x][y];
					q.push_front({x+dx[i],y+dy[i]});
				}
			}
		}
		for(int cx=-2;cx<=2;++cx){
			for(int cy=-2;cy<=2;++cy){
				if((cx==-1 && cy==0) || (cx==1 && cy==0) || (cx==0 && cy==1) || (cx==0 && cy==-1))continue;
				if(chk(x+cx,y+cy,h,w) && gr[x+cx][y+cy]!='#'){
					if(d[x][y]+1<d[x+cx][y+cy]){
						d[x+cx][y+cy]=d[x][y]+1;
						q.push_back({x+cx,y+cy});
					}
				}
			}
		}
	}
	if(d[dex][dey]==1e9)
		cout<<-1;
	else
		cout<<d[dex][dey];
	
}

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

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

using namespace std;


const int max_comb = 2100000;
vector<ll> fac(max_comb + 1); //n! (mod M)
vector<ll> ifac(max_comb + 1); //k!^(-1) (mod M)

ll mpow(ll x, ll n) { //x^n(mod M)
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % MOD;
		x = x * x % MOD;
		n = n >> 1;
	}
	return ans;
}

ll minv(ll x) {
	return mpow(x, MOD - 2);
}

ll comb(int a, int b) {     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % MOD;
	return tmp * fac[a] % MOD;
}

ll perm(int a, int b) {     // P(a,b) = a! * (a-b)!^(-1)
	if (b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] % MOD;
	return tmp * fac[a] % MOD;
}

void pre_comb()
{
	fac[0] = 1;
	ifac[0] = 1;
	for (int i = 0; i < max_comb; i++) {
		fac[i + 1] = fac[i] * (i + 1) % MOD; // n!(mod M)
		ifac[i + 1] = ifac[i] * minv(i + 1) % MOD; // k!^(-1) (mod M)
	}
	return;
}


void solve()
{
	int a, b;
	scanf("%d%d", &a, &b);
	ll x = (ll)2 * a - b;
	ll y = (ll)2 * b - a;
	if (x<0 || y<0 || x % 3 || y % 3) {
		printf("0\n"); return;
	}
	x /= 3; y /= 3;
	pre_comb();
	printf("%lld\n", comb(x+y, x));

	return;
}


int main(int argc, char* argv[])
{
#if 1
	solve();
#else
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
#endif
	return 0;
}


Measured memory_bytes: 33024
n = int(input())
people = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    p = people[i]
    pnext = people[i+1]
    if p > pnext:
        a = p-pnext
        ans += a
        people[i+1] += a
print(ans)


Measured memory_bytes: 32348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int X = scanner.nextInt();
		int Y = scanner.nextInt();
		int leg_turtle = 4;
		int leg_crane = 2;

		int turtle = (Y - (leg_crane * X)) / (leg_turtle - leg_crane);
		int crane = X - turtle;

		if ((turtle >= 0 && crane >= 0) && (turtle * 4 ) + (crane * 2) == Y) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

//		System.out.println(turtle);;
//		System.out.println(crane);;

	}

}

Measured memory_bytes: 35800
#include <stdio.h>
#include <math.h>

int s[1002];

#define gc() getchar_unlocked()
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc();
	while (c >= '0');
	return n;
}

int main()
{
	int n, i, is;
	double m, fs, a;
	
	while (n = in()) {
		is = 0; for (i = 0; i < n; i++) is += s[i] = in();
		m = (double)is/n;
		fs = 0; for (i = 0; i < n; i++) {
			a = s[i]-m;
			fs += a*a;
		}
		printf("%.8lf\n", sqrt(fs/n));
	}
	return 0;
}



Measured memory_bytes: 2088
N, M = map(int, input().split())
es = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, used, cnt):
    used[v] = 1
    if all(used):
        cnt.append(1)
    for nv in es[v]:
        if used[nv]:
            continue
        dfs(nv, used, cnt)
    used[v] = 0

used = [0] * N
cnt = []
dfs(0, used, cnt)

print(sum(cnt))

Measured memory_bytes: 43228
# 不足しているカードの発見

# input process
n = int(input())

# initialization
card_list = {}
card_type = ['S', 'H', 'C', 'D']
for c in card_type:
    card_list[c] = [0]*13

# remove process
for i in range(n):
    t, n = input().split()
    n = int(n)
    card_list[t][n-1] = 1

# output process
for c in card_list:
    for i in range(len(card_list[c])):
        if card_list[c][i]==0:
            print("%s %d"%(c, i+1))



Measured memory_bytes: 5596
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] d = new int[N];
		for(int i=0; i<N; i++)
			d[i] = sc.nextInt();
		
		long ans = 0;
		for(int i=0; i<N; i++)
			for(int j=i+1; j<N; j++)
				ans += d[i]*d[j];
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 22996
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <map>
#include <stack>
#include <set>
#include <list>
#include<fstream>
#include<stdio.h>
#include<iomanip>
#include<climits>
#include<list>
#include <functional>
#include <utility>
#include <numeric>
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)(v).size())
#define PI 3.14159265
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int  main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	///////////////////////////////////////////
ll q,h,s,d,n;
cin>>q>>h>>s>>d>>n;
q*=4;
h*=2;
ull mn=min(q,(min(h,s)));
if(n&1)
{
    if(d>=2*mn)
        cout<<n*mn<<endl;
    else cout<<((n-1)/2)*d+mn<<endl;

}
else
{if(d>=2*mn)
        cout<<n*mn<<endl;
    else cout<<((n)/2)*d<<endl;

}
	return 0;
}


Measured memory_bytes: 888
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    k = int(input())
    print(s[k-1])
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5692
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;



int main(){
    
    int n,m;
    cin >> n >> m;
    
    int table[n+10][m+10];
    //初期化
    rep(i,n+10) rep(j,m+10) table[i][j] = 0;
    
    //入力と合計
    rep1(i,n){
        rep1(j,m){
            cin >> table[i][j];
            table[i][m+1] += table[i][j];
            table[n+1][j] += table[i][j];
        }
    }
    
    //全合計
    rep1(i,n) table[n+1][m+1] += table[i][m+1];
    
    //表示
    rep1(i,n+1){
        rep1(j,m) cout << table[i][j] <<" ";
        //cout << endl;
        cout << table[i][m+1] << endl;
    }
    
    
}









Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll a[n],i;
    for(i=0; i<n; i++) cin>>a[i];
    ll mx=a[0];
    ll mn=a[0];
    ll sum=a[0];
    for(i=1; i<n; i++)
    {
        if(mx<a[i]) mx=a[i];
        if(mn>a[i]) mn=a[i];
        sum+=a[i];
    }
    cout<<mn<<" "<<mx<<" "<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
class Dice{
  private:

  vector<int> num;

  public:
  Dice() = default;
  Dice(vector<int> input):num(input){};

  void operate(int cmd){
    vector<int>ret = num;
    if(cmd == 0){ //E方向
      ret[0] = num[3]; 
      ret[2] = num[0]; 
      ret[5] = num[2]; 
      ret[3] = num[5]; 
    }
    if(cmd == 1){ // N方向
      ret[0] = num[1];
      ret[1] = num[5];
      ret[5] = num[4];
      ret[4] = num[0];
    }
    if(cmd == 2){// S方向
      ret[1] = num[0];
      ret[5] = num[1];
      ret[4] = num[5];
      ret[0] = num[4];
    }
    if(cmd == 3){ // W方向
      ret[3] = num[0]; 
      ret[0] = num[2]; 
      ret[2] = num[5]; 
      ret[5] = num[3]; 
    }
    num = ret;
  }
  static int dir(char c){
    if(c == 'E')return 0;
    if(c == 'N')return 1;
    if(c == 'S')return 2;
    if(c == 'W')return 3;
  }
  int top(){
    return num[0];
  }
  void print(){
    for(int i = 0; i < 6; i++){
      cout << num[i] << " ";
    }
    cout << endl;
  }
  vector<int> nums(){
    return num;
  }
  using F = function<bool(vector<int>)>;
  vector<int> search(const F &check){
    int limit = 1;
    for(int i = 0; i < 4; i++)limit *= 4;
    for(int i = 0; i < limit; i++){
      vector<int>cmd_num(4);
      int n = i;
      for(int j = 0; j < 4; j++){
        cmd_num[j] = n % 4;
        n >>= 2;
      }
      Dice copy = *this;
      for(int j = 0; j < 4; j++){
        for(int k = 0; k < cmd_num[j]; k++){
          copy.operate(j);
        }
      }
      if(check(copy.nums()))return copy.nums();
    }
    return vector<int>();
  }
  bool equals(Dice d){
    return !(this->search(
      [&](vector<int>dnum){return dnum == d.nums();})
      ).empty();
  }
};

int main(){
  int n;
  cin >> n;
  vector<Dice>d(n);
  for(int i = 0; i < n; i++){
    vector<int> tmp(6);
    for(int j = 0; j < 6; j++)cin >> tmp[j];
    d[i] = Dice(tmp);
  }
  bool judge = true;
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      if(d[i].equals(d[j]))judge = false;
    }
  }
  if(judge)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3180
#include <iostream>
#include <stdlib.h>
#define max_baggageNum 100000
#define max_weight 10000

using namespace std;
int calc(int* a, int* mid, int* baggage, int* track)
{
    int num = 0;
    int tmp = 0;
    //for (int i = 0; i < *baggage; i++) {
    //	tmp += a[i];
    //	if (tmp > *mid) {
    //	    num++;
    //	    tmp = 0;
    //	}
    //}
    for (int i = 0; i < *track; i++) {
	tmp = 0;
	while (a[num] + tmp <= *mid) {
	    tmp += a[num];
	    num++;
	    if (num == *baggage)
		return num;
	}
    }
    return num;
}
void solve(int* a, int* baggage, int* track)
{
    int left = 0;
    int right = max_baggageNum * max_weight;
    int mid = 0;
    int v = 0;
    while (right - left > 1) {
	mid = left + (right - left) / 2;
	v = calc(a, &mid, baggage, track);
	if (v >= *baggage) {
	    right = mid;
	}
	else {
	    left = mid;
	}
    }
    cout << right << endl;
}

int main()
{
    int baggage = 0;
    int track = 0;
    cin >> baggage;
    cin >> track;
    int a[baggage];
    for (int i = 0; i < baggage; i++) {
	cin >> a[i];
    }
    solve(a, &baggage, &track);
    return 0;
}

Measured memory_bytes: 1552
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    string s; cin>>s;
    int K; cin>>K;

    vector<string> vs;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=K;j++){
            vs.push_back(s.substr(i,j));
        }
    }
    sort(ALL(vs));
    vs.erase(unique(ALL(vs)),vs.end());
    cout<<vs[K-1]<<endl;
}


Measured memory_bytes: 1660
#include <iostream>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=100005, INF=2000000000000000000;
int32_t main()
{
    IOS;
    // pre();
    // fill(isprime,true);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=a*c;
    ans = max(ans,a*c);
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);
    cout<<ans;
}

Measured memory_bytes: 3660
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	sort.Sort(sort.IntSlice(aa))
	exchange := make([]string, n-1)
	e := 0
	i := n - 2
	for ; i > 0 && aa[i] > 0; i-- {
		exchange[e] = fmt.Sprintf("%d %d", aa[0], aa[i])
		aa[0] -= aa[i]
		e++
	}

	for ii := 0; ii <= i; ii++ {
		exchange[e] = fmt.Sprintf("%d %d", aa[n-1], aa[ii])
		aa[n-1] -= aa[ii]
		e++
	}
	fmt.Fprintln(writer, aa[n-1])
	for i := 0; i < n-1; i++ {
		fmt.Fprintln(writer, exchange[i])
	}

	writer.Flush()
}


Measured memory_bytes: 8320
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a,b;
		a=sc.nextInt();
		b=sc.nextInt();
		if(a>b){
			System.out.println("a > b");
		}else if(a<b){
			System.out.println("a < b");
		}else{
			System.out.println("a == b");
		}
		sc.close();
	}
}



Measured memory_bytes: 26208
#include <bits/stdc++.h>
using namespace std;
int main (){
    int n,c,k,ans=0,cut=1;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i=0;i<n;i++){
        cin >> t.at(i);
    }
    sort(t.begin(),t.end());

    for(int i=0;i<n-1;){
        if(t.at(i)+k < t.at(i+1)){
            ans++;//次の人が来るまでに怒るなら乗せる
            i++;//last
        }
        else{int j=i+1;
            while(t.at(i)+k >= t.at(j)){//怒らないなら次の人と一緒にのせて
            cut++;
            if(cut>c){break;}//last
            if(j<n-1){j++;}
            else{ans--;break;}
            }
        ans++; cut=1; i=j;
        }
    }
    ans++;//最後の人補正
    cout << ans << endl;
}

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

int main(){
    ll a[7];
    for(int i=0;i<7;i++){
        cin >> a[i];
    }
    ll ans = a[1];
    if(a[0]>0 && a[3]>0 && a[4]>0 && a[0]%2+a[3]%2+a[4]%2 >= 2){
        ans += 3;
        a[0]--;
        a[3]--;
        a[4]--;
    }
    ans += a[0]/2*2;
    ans += a[3]/2*2;
    ans += a[4]/2*2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from collections import Counter
from bisect import bisect_left

def calc(d, i, dsum, m):
    return comb(d, i) + dsum[i] + dsum[m] - dsum[i+1]

def comb(d, i):
    return d[i][1] * max(0, d[i][1] - 1) // 2

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    d = [[k, v] for k, v in sorted(dict(Counter(v)).items())]
    keys = [q[0] for q in d]
    m = len(d)
    dsum = [0] * (n+1)
    for i in range(1, m+1):
        dsum[i] = dsum[i-1] + comb(d, i-1)
    for i in range(n):
        j = bisect_left(keys, v[i])
        d[j][1] -= 1
        print(calc(d, j, dsum, m))
        d[j][1] += 1

if __name__ == '__main__':
    main()


Measured memory_bytes: 117980
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    string s;
    cin>>s;
    if(s=="RRR") cout<<3;
    else if(s=="RRS" or s=="SRR") cout<<2;
    else if(s=="SSS") cout<<0;
    else cout<<1;
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>

using namespace std;

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    while (n--) {
      int x1, y1, z1, w1, x2, y2, z2, w2;
      cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
      cout << x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2 << " "
	   << x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2 << " "
	   << x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2 << " "
	   << x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
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)*}
    };
}

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

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input! {
        i: i64,
        d: i64,
        points: [(i64, i64); i],
    }

    let threashold = d * d;

    let mut count = 0;
    for point in points {
        if threashold >= point.0 * point.0 + point.1 * point.1 {
            count += 1;
        }
    }

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


Measured memory_bytes: 5172
import sys
import os
import math
import bisect
import collections
import itertools
import heapq

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, D = il()
    X = [il() for _ in range(N)]

    ret = 0
    for x, y in itertools.combinations(X, 2):
        i = 0
        for t in zip(x, y):
            i += abs(t[0] - t[1]) ** 2
        if float.is_integer(math.sqrt(i)):
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n;cin>>n;
    string s = to_string(n);
    int len = s.size();
    for(int i =0;i<len/2;i++){
        if(s[i]!=s[len-i-1]){
            cout<<"No"<<endl;
            return 0;
        }

    }
    cout<<"Yes"<<endl;
    return 0;

}

Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<cassert>
#include<functional>
#include<queue>
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[100006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int mx = inf, id = 0;
	rep(i, n) {
		if (mx > a[i]) {
			mx = a[i];
			id = i;
		}
	}
	cout << id + 1 << endl;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;

bool sex() {
	string str; cin >> str;
	if(str == "Vacant") exit(0);
	return str == "Male";
}

void solve() {
	cin >> N;
	int lv = 0, rv = N, ls, rs;
	cout << 0 << endl;
	ls = rs = sex();
	while(rv - lv > 1) {
		int m = (lv + rv) / 2, ms;
		cout << m << endl;
		ms = sex();
		if(((m - lv + 1) + (ms + ls)) % 2) {
			lv = m; ls = ms;
		}
		else {
			rv = m; rs = ms;
		}
	}
}

int main() {
// #ifndef LOCAL
// 	ios::sync_with_stdio(false);
//     cin.tie(0);
// #endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
// #ifdef LOCAL
// 	//freopen("in.txt", "wt", stdout); //for tester
//     freopen("in.txt", "rt", stdin);
// #endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




Measured memory_bytes: 852
N,L = map(int, input().split())
if L >= 0:
  a = sum([ i for i in range(L+1,L+N)])
elif L+N-1 <= 0:
  a = sum([ i for i in range(L,L+N-1)])
else:
  a = sum([ i for i in range(L,L+N)])
print(a)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N, A, B;
    cin >> N >> A >> B;
    if(A > B){
    	cout << 0 << endl;
    }
    else if(N == 1){
    	if(A == B) cout << 1 << endl;
    	else cout << 0 << endl;
    }
    else{
    	long long ans = (B-A)*(N-2)+1;
    	cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
   int a,b,c,k,sum=0,i;
   scanf("%d%d%d%d",&a,&b,&c,&k);
   for(i=0;i<a;i++){
      if(k>0){
         sum++;
         k--;
      }
   }
    for(i=0;i<b;i++){
      if(k>0){
         k--;
      }
   }
     for(i=0;i<c;i++){
      if(k>0){
         sum--;
         k--;
      }
   }
   printf("%d\n",sum);
   return 0;
}


Measured memory_bytes: 1708