akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y){
	int r;
	while((r = x % y) != 0){
        x = y;
        y = r;
    }
	return y;
}
int main(void){
	int n, x;
	cin >> n >> x;
	int d[n];
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		d[i] = abs(a - x);
	}
	sort(d, d + n);
	if(n == 1) cout << d[0] << endl;
	else if(n == 2) cout << gcd(d[0], d[1]) << endl;
	else {
		int ans = gcd(d[0], d[1]);
		for(int i = 2; i < n; i++){
			ans = gcd(d[i], ans);
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  ll ans=0;
  for(int i=1;i<=N;i++){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long int

struct knapsack{
    int wt, val;
};

int32_t main() {
    int N, W; cin>>N>>W;
    knapsack arr[N+1];
    for(int i=1; i<=N; i++) {
        cin>>arr[i].wt;
        cin>>arr[i].val;
    }

    int dp[N+1][W+1];
    for(int i=0; i<=W; i++) dp[1][i] = 0;

    dp[1][arr[1].wt] = arr[1].val;

    for(int i=2; i<=N; i++) {
        for(int j=0; j<=W; j++) {
            dp[i][j] = dp[i-1][j];
            if(arr[i].wt > j) continue;
            dp[i][j] = max(dp[i][j], arr[i].val + dp[i-1][j - arr[i].wt]);
        }
    }

    cout<< *max_element(dp[N], dp[N] + W + 1)<<endl;
    return 0;
}


Measured memory_bytes: 81720
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

vector<int> par,r;

void init(int n){
  par.resize(n);
  r.resize(n);
  for(int i = 0; i < n; i++)
  {
    par[i] = i;
    r[i] = 0;
  }
}

int find(int x){
  if (par[x] == x){
    return x;
  }else{
    return find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);

  if(x == y){
    return;
  }else if(r[x] < r[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(r[x] == r[y]) r[x]++;
  }
}

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



int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> p(n),x(m),y(m);
  for(int i = 0; i < n; i++) cin >> p[i];
  for(int i = 0; i < m; i++) cin >> x[i] >> y[i];

  init(n);

  for(int i = 0; i < m; i++){
    unite(x[i],y[i]);
  }

  int sol = 0;
  for(int i = 0; i < n; i++){
    if(same(i+1,p[i])) sol++;
  }

  cout << sol << endl;


  return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
  int A,B;
  scanf("%d %d",&A,&B);
  int ad=A+B;
  int su=A-B;
  int time=A*B;
  if(ad>=su&&ad>=time)
    printf("%d",ad);
  else if(su>=ad&&su>=time)
    printf("%d",su);
  else
    printf("%d",time);
  return 0;
}


Measured memory_bytes: 128
from functools import reduce

# 入力
N = int(input())
S = input()

# 閉じられていない '(' の個数だけ S の末尾に ')' を、
# 閉じられていない ')' の個数だけ S の先頭に '(' を付与した文字列が解である
a, b = reduce(
    lambda acc, s:
        (
            (
                acc[0] + 1 if s == '(' else
                max(0, acc[0] - 1)
            ),
            (
                acc[1] + 1 if s == ')' and acc[0] == 0 else
                acc[1]
            )
        ),
    S,
    (0, 0)
)
ans = b * '(' + S + a * ')'

# 出力
print(ans)


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  int i;
  for(i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int count=1;
  for(i=0;i<n-1;i++){
	if(vec.at(i+1)-vec.at(i)>0){
      count++;
    }
  }
  cout << count;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
unsigned long long k;//要求第k位的lunlun数 
unsigned long long q[5000001],f=1,e=0;
int main()
{
	cin>>k;
	for(int i=1;i<=9;i++)q[++e]=i;//进队列 
	for(long long i=1;i<=k+1;i++)
	{
		long long m=q[f]%10;
		if(m<0||m>9)break;
		if(m-1>=0)//末尾可以添加数字 
			q[++e]=10*q[f]+m-1;
		q[++e]=10*q[f]+m;
		if(m+1<=9)//末尾可以添加数字 
			q[++e]=10*q[f]+m+1;
		f++;
	}
	/*
	for(int i=1;i<=k;i++)cout<<q[i]<<' ';
	cout<<endl;
	*/
	cout<<q[k]<<endl;
	return 0;
}

Measured memory_bytes: 5728
n, m = map(int, input().split())

accums = [0]
for i in range(n - 1):
    accums.append(accums[-1] + int(input()))

result = 0
k = 0
for i in range(m):
    a = int(input())
    result = (result + abs(accums[k + a] - accums[k])) % 100000
    k += a

print(result)

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

const int N = 1e3 + 5;

int main()
{
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) for (int j = 0; j <= m; j++)
		if (i * m + j * n - 2 * i * j == k) return puts("Yes") * 0;
	puts("No");
	return 0;
}

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

int main() {
 LL X,K,D; cin>>X>>K>>D;

 K = min(K,abs(X)/D/2*2+10+K%2);

 LL l,r; l=-K; r=K;
 while(l+1<r){
  LL m=(l+r)/2;
  if(X+D*m < 0) l=m; else r=m;
 }

 if(abs(r)%2 == K%2) l=r;

 LL ans = abs(X+D*l);
 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 3632
s = input()
if "N" in s:
    if "S" not in s:
        print("No")
        exit()
if "S" in s:
    if "N" not in s:
        print("No")
        exit()
if "W" in s:
    if "E" not in s:
        print("No")
        exit()
if "E" in s:
    if "W" not in s:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
int main()
{
	char s[55], t[55];
	scanf("%s%s", s, t);
	int n, m;
	n = strlen(s);
	m = strlen(t);
	int i, j;
	int v, c;
	v = 0;
	for (i = n - m; i >= 0; i--)
	{
		c = 0;
		for (j = 0; j < m; j++)
			if (s[i + j] != t[j] && s[i + j] != '?')
				c++;
		if (c == 0)
		{
			v = 1;
			for (j = 0; j < m; j++)
				if (s[i + j] == '?')
					s[i + j] = t[j];
			break;
		}
	}
	if (v == 0)
	{
		printf("UNRESTORABLE\n");
		return 0;
	}
	for (i = 0; i < n; i++)
		if (s[i] == '?')
			s[i] = 'a';
	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 128
import numpy as np
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)
mod = 10**9 + 7
ans = 0
for i in range(60):
  # a要素のi番目のデータが1であるデータの数 iビット右シフト &:論理積 
  b = np.count_nonzero(a >> i & 1)
  #print(a>>i&1)
  # 2進数から10進数 b*(N-b)は(1の個数)*(0の個数)
  ans += 2 ** i * b*(n-b)
  ans %= mod
print(ans)

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

int main() {
    string s,t;
    cin>>s>>t;
    int ans = 0;
    rep(i,3) {
        if (s[i]==t[i]) {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  int s[n], sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }
  if (sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  sort(s, s + n);
  for (int i = 0; i < n; i++) {
    if (s[i] % 10 != 0) {
      sum -= s[i];
      cout << sum << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

void output(vector<int> ans){
	for(int i = 0;i < ans.size();i++) cout << (i ? " " : "") << ans[i];
	cout << endl;
}

signed main(){
	int n,k,s;
	cin >> n >> k >> s;
	vector<int> ans(n);
	if(k == n){
		for(int i = 0;i < n;i++) ans[i] = s;
		output(ans);
		return 0;
	}
	int d = n - k;
	for(int i = 0;i < n;i++){
		if(s - d <= 0){
			ans[i] = 1000000000;
			d--;
		}
		else if(i % (d + 1) == 0) ans[i] = s - d;
		else ans[i] = 1;
	}
	output(ans);
}

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

bool f(string a){
  string t = a;
  reverse(a.begin(),a.end());
  return t == a;
}

int main(){
   string s,a="",b="";
   cin >> s;
   int n=s.size();
   a = s.substr(0,n/2);
   if(f(s) && f(a)){
     cout << "Yes" << endl;
   }else{
     cout << "No" << 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;

ll choose(int n, int k){
    ll x=1;
    ll y=1;
    rep(i, k){
        x*=(n-i);
        y*=i+1;
    }
    return x/y;
}
int main(void){
    string s;
    int k;
    cin>>s;
    cin>>k;
    int digit=s.size();
    ll ans;
    if(digit-1<k) ans=0;
    else ans=choose(digit-1, k)*pow(9, k);
    //cout<<ans<<endl;
    vector<vector<int> > dp1(digit+1, vector<int>(10));
    vector<vector<int> > dp2(digit+1, vector<int>(10));
    dp1[0][0]=0;
    dp1[0][1]=(s[0]-'0')-1;
    dp2[0][1]=1;
    int dp2now=1;
    for(int i=1;i<=digit-1;i++){
        rep(j, 4){
            if(j==0){
                dp1[i][j]=dp1[i-1][j]+dp2[i-1][j]*min((s[i]-'0'), 1);
            }
            else dp1[i][j]=dp1[i-1][j-1]*9+dp1[i-1][j]+dp2[i-1][j-1]*max((s[i]-'0'-1), 0)+dp2[i-1][j]*min((s[i]-'0'), 1);
        }
        if(s[i]=='0'){
            if(dp2now>=4) continue;
            dp2[i][dp2now]=1;
        }
        else {
            if(dp2now+1>=4) {
                dp2now=10;
                continue;
            }
            dp2now++;
            dp2[i][dp2now]=1;

        }
    }
    ans+=dp1[digit-1][k]+dp2[digit-1][k];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#define PI 3.14159265

int main(void)
{
	double a, b, c, s, l, h;

	scanf("%lf%lf%lf%lf", &a, &b, &c);

	s = a * b*sin(c * PI / 180) / 2;
	l = a + b + sqrt(a * a + b * b - 2 * a * b * cos(c * PI / 180));
	h = s / a * 2;
	printf("%lf\n%lf\n%lf\n", s, l, h);

	return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  rep(i,min(k,100)){
    vector<int> b(n);
    rep(j,n){
      int l=max(j-a[j],0);
      int r=j+a[j];
      b[l]++;
      if(r+1<n) b[r+1]--;
    }
    rep(j,n-1){
      b[j+1]=b[j]+b[j+1];
    }
    a=b;
  }
  rep(i,n) cout<<a[i]<<" ";
  cout<<endl;
}

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

using namespace std;

int main()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   if(abs(a-c)<=d)
    cout<<"Yes"<<endl;

    else if(abs(a-b)<=d&&abs(b-c)<=d)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a, b, c;
    cin >> a >> b >> c;
    string n = a + b + c;
  int ans = 0;
  if (count(n.begin(), n.end(), '5') == 2  && count(n.begin(), n.end(), '7') == 1){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)


n = int(input())
a = list(map(int, input().split()))
a = [0]+a[:]+[0]

l = [0]*len(a)
r = [0]*len(a)

for i in range(len(a)-1):
    m = len(a)-1
    l[i+1] = gcd(l[i], a[i+1])
    r[m-i-1] = gcd(r[m-i], a[m-i-1])

ans = [0]*n

for i in range(n):
    ans[i] = gcd(l[i], r[i+2])

print(max(ans))


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

using namespace std ;

#define ll long long

int n ;
ll a = 1 , b = 1 ;

int main() {
	scanf( "%d" , &n ) ;
	for( int i = 1 ; i <= n ; i ++ ) {
		ll x , y ;
		scanf( "%lld%lld" , &x , &y ) ;
		ll t = max( ( a - 1 ) / x + 1 , ( b - 1 ) / y + 1 ) ;
		a = x * t ; b = y * t ;
 	}
	printf( "%lld\n" , 1ll * ( a + b ) ) ;
	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;
using P = pair<int,int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  rep(i,m) cin >> x[i];
  if(n>=m) {
    cout << 0 << endl;
    return 0;
  }
  sort(x.begin(),x.end());
  vector<int> d(m-1);
  rep(i,m-1) d[i] = x[i+1]-x[i];
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  int ans = x.at(m-1)-x.at(0);
  rep(i,n-1) ans -= d[i];

  cout << ans << endl;
}


Measured memory_bytes: 1024
var
	n,i:Longint;
	s:String;
begin
	setLength(s,100000);
	readln(s);
	n:=length(s);
	i:=1;
	while(i<n)and not((s[i]=s[i+1])or((i+1<n)and(s[i]=s[i+2])))do inc(i);
	if i=n then writeln('-1 -1')else if s[i]=s[i+1] then writeln(i,' ',i+1)else writeln(i,' ',i+2);
end.


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

string a;
int main()
{
	int i;
	cin >> a;
	for (i = 0; i < a.size(); i++) {
		if (a[i] == ',') cout << ' ';
		else cout << a[i];
	}
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <stack>

using namespace std;

int main(){
    int n;
    cin >> n;
    char c;
    stack<char> st;
    for(int i = 0; i < n; i++){
        cin >> c;
        st.push(c);
        vector<int> v, vote;
        while(!st.empty()){
            cin >> c;
            if(c != ']') st.push(c);
            else {
                int keta = 1;
                int num = 0;
                while(st.top() != '['){
                    num += keta * ((0 - '0') + st.top());
                    keta = keta * 10;
                    st.pop();
                }
                if(num != 0) {
                    v.push_back(num);
                    vote.push_back(num/2 + 1);
                }
                else {
                    v.push_back(num);
                    vote.push_back(num);
                }
                st.pop();
            }
        }
        vector<int> v_sort;
        vector<int> v_num;
        deque<int> q_num;
        for(int j = 0; j < v.size(); j++){
            if(vote[j] != 0){
                v_sort.push_back(vote[j]);
            }
            else {
                sort(v_sort.begin(), v_sort.end());
                int x = 0;
                for(int k = 0; k < v_sort.size() / 2 + v_sort.size()%2; k++){
                    x += v_sort[k];
                }
                v_num.push_back(x);
                sort(v_num.begin(), v_num.end());
                for(int l = 0; l < v_num.size(); l++){
                        q_num.push_back(v_num[l]);
                }

                v_sort.clear();
                v_num.clear();
            }
        }
        vector<int> vec;
        deque<int> q2;
        int b = -1;
        while(q_num.size() != 1 && q_num.front() != 0){
            while(!q_num.empty()){
                int n = q_num.front();
                q_num.pop_front();
                if(n != 0) vec.push_back(n);
                if(b != 0 && n == 0){
                    sort(vec.begin(), vec.end());
                    int m = 0;
                    for(int l = 0; l < vec.size() / 2 + 1; l++){
                        m += vec[l];
                    }
                    vec.clear();
                    q2.push_back(m);
                }
                if(b == 0 && n == 0) q2.push_back(0);
                b = n;
            }
            q_num = q2;
            q2.clear();
        }
        cout << q_num.front();
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    long long n;
    cin>>n;

    string s;

    while(n>0){

        int x = n%26;

        if(x==0)
            s+='z';
        else s+=(char)(96+x);

        n = (n-1)/26;
    }

    reverse(s.begin(),s.end());

    cout<<s<<endl;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    vector<int> v( 3 );
    for( auto &x : v )
    {
        cin >> x;
    }
    sort( ALL( v ) );
    cout << abs( v[ 1 ] - v[ 0 ] ) + abs( v[ 2 ] - v[ 1 ] ) << endl;
    return 0;
}

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

int top, A[1000];

void push(int x){
  top++;
  A[top] = x;
}

int pop(){
  top--;
  return A[top+1];
}

int main(){
  int b, c;
  top = 0;
  char a[100];

  while(1){
    if(scanf("%s",a)==EOF){
     break;
    }
    if(a[0]=='+'){
      b = pop();
      c = pop();
      push(b+c);
    }else if(a[0]=='-'){
      c = pop();
      b = pop();
      push(b-c);
    }else if(a[0]=='*'){
      b = pop();
      c = pop();
      push(b*c);
    }else{
      push(atoi(a));
    }
  }
  printf("%d\n", pop());
  return 0;
 }


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

using namespace std;

#define INF 210000000
#define int long long

signed main() {
		int n;
		cin >> n;
		string s;
		cin >> s;
		string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		string ans = "";
		for(auto& A : s){
				int tmp = a.find(A);
				tmp += n;
				if (tmp >= a.length()) tmp -= 26;
				ans += a[tmp];
		}
		cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
cnt = Counter()
for x in map(int, input().split()):
    cnt[x] += 1

xs = sorted(cnt.items(), key=lambda x: x[0])

def find_pair():
    while xs:
        x = xs.pop()
        if x[1] >= 2:
            xs.append((x[0], x[1] - 2))
            return x[0]
        else:
            continue
    return 0

a = find_pair()
b = find_pair()
print(a*b)



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i; i < N; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  
  int ans = 1;
  for (int i; i < N-1; i++) {
    if (vec[i] != vec[i+1]) ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <complex>
#include <cassert>
#include <vector>
#include <iomanip>

using namespace std;

typedef complex<double> P;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

const double eps = 1e-10;

double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

struct L : public vector<P> {
    L(const P &a, const P &b) {
        push_back(a); push_back(b);
    }
};

P crosspoint(const L &l, const L &m) {
    double A = cross(l[1] - l[0], m[1] - m[0]);
    double B = cross(l[1] - l[0], l[1] - m[0]);
    if (abs(A) < eps && abs(B) < eps) return m[0]; // same line
    if (abs(A) < eps) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
    return m[0] + B / A * (m[1] - m[0]);
}

int main(){
    cout << setprecision(3) << fixed;
    P ps[3];
    int n; cin >> n;
    rep(tt, n){
        rep(i, 3){
            double x, y; cin >> x >> y;
            ps[i] = P(x, y);
        }
        P mid1 = (ps[0] + ps[1]) / 2.0, mid2 = (ps[0] + ps[2]) / 2.0;
        L l1(mid1, mid1 + (ps[0] - ps[1])*P(0, 1)), l2(mid2, mid2 + (ps[0] - ps[2])*P(0, 1));
        P cp = crosspoint(l1, l2);
        cout << cp.real() << " " << cp.imag() << " " << abs(cp - ps[0]) << endl;
    }
}

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

#define  int  long long
#define  endl  '\n'
const int mod = 1e9 + 7;


int32_t main()
{ 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  
 
  int n;
  cin >> n;

  int a[n + 1] = {0};

  for(int i = 1; i <= n; i++)
    cin >> a[i];

  int mx = 0, cnt = 0;

  for(int i = 2; i <= n; i++)
  {
     if(a[i] <= a[i - 1])
      cnt++;
     else
     {
       mx = max(mx, cnt);
       cnt = 0;
     }
  }

  mx = max(mx, cnt);

  cout << mx;
  
  return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

S = input()

if S[2] == S[3] and S[4] == S[5]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int n;
  static char dice[100000000];
  while(cin >> n, n){
    dice['上'] = 1;
    dice['北'] = 2;
    dice['西'] = 3;
    dice['東'] = 4;
    dice['南'] = 5;
    dice['下'] = 6;

    while(n--){
      string s;
      cin >> s;
      if(s == "north"){
        dice['北'] = dice['上'];
        dice['上'] = dice['南'];
        dice['下'] = 7 - dice['上'];
        dice['南'] = 7 - dice['北'];
      }else if(s == "south"){
        dice['南'] = dice['上'];
        dice['上'] = dice['北'];
        dice['北'] = 7 - dice['南'];
        dice['下'] = 7 - dice['上'];
      }else if(s == "east"){
        dice['東'] = dice['上'];
        dice['上'] = dice['西'];
        dice['西'] = 7 - dice['東'];
        dice['下'] = 7 - dice['上'];
      }else{
        dice['西'] = dice['上'];
        dice['上'] = dice['東'];
        dice['東'] = 7 - dice['西'];
        dice['下'] = 7 - dice['上'];
      }
    }
    cout << (int)dice['上'] << endl;
  }
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    long double a,b; cin>>a>>b;
    cout<<(int)(a*b+0.001);
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

// dpを使った場合
// vectorではWAだったがCの配列なら行けた

string options[4] = {"dream", "dreamer", "erase", "eraser"};
bool dp[100010];

int main() {
  string s;
  cin >> s;
  
  dp[0] = 1;
  for (int i = 0; i < s.size(); i++) {
    if (!dp[i]) continue;
    for (string c : options) {
      // sのi番目からc.size要素までがoptionsのどれかと一致したら、
      // その末尾の添字に対応するdpの位置をtrueにする
      if (s.substr(i, c.size()) == c) dp[i + c.size()] = 1;
    }
  }
  
  // dp[s.size()](つまりsの末尾)がtrueということは、sがoptionsで綺麗に分割できたということ
  cout << (dp[s.size()] ? "YES" : "NO") << endl;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const int inf=(1<<30);
    int h,w;
    cin >> h >> w;
    vector<int> a(h+1,0);
    vector<int> b(h+1,0);
    vector<int> one[w+2];
    vector<int> two[w+2];
    //watch out for segments extending all the way to the right
    for(int i=1;i<=h;i++)
    {
        cin >> a[i] >> b[i];
        one[a[i]].push_back(i);
        two[b[i]+1].push_back(i);
    }
    for(int i=1;i<=w+1;i++) reverse(two[i].begin(),two[i].end());
    vector<int> to(h+2,h+1);
    vector<int> st(w+2,h+1);
    set<int> s;
    for(int i=1;i<=w+1;i++)
    {
        for(int y:one[i]) s.insert(y);
        for(int y:two[i])
        {
            s.erase(y);
            auto it=s.lower_bound(y);
            if(it!=s.end()) to[y]=(*it);
        }
        if(!s.empty()) st[i]=(*s.begin());
    }
    vector<array<int,2>> v[h+3];
    vector<int> d(h+2,inf);
    auto add=[&](int l,int r,int dist)
    {
        v[l].push_back({dist-l,1});
        v[r+1].push_back({dist-l,-1});
    };
    for(int i=1;i<=w;i++)
    {
        d[st[i]]=min(d[st[i]],st[i]-1+b[st[i]]+1-i);
        add(1,st[i],0);
    }
    for(int i=1;i<=h;i++)
    {
        d[to[i]]=min(d[to[i]],d[i]+to[i]-i+b[to[i]]+1-(b[i]+1));
        if(b[i]<w) add(i+1,to[i],d[i]+1);
    }
    vector<int> res(h+2,inf);
    multiset<int> m;
    for(int i=1;i<=h+1;i++)
    {
        for(auto [x,t]:v[i])
        {
            if(t==1) m.insert(x);
            else m.erase(m.find(x));
        }
        if(!m.empty()) res[i]=min(res[i],(*m.begin())+i);
    }
    for(int i=1;i<=h+1;i++) if(res[i]==inf) res[i]=-1;
    for(int i=2;i<=h+1;i++) cout << res[i] << "\n";
    return 0;
}


Measured memory_bytes: 54712
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;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; }

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
lli h, w;

int main(void){
    cin >> h >> w;
    vector<string> maze(h);
    vector<vector<lli>> c(h, vector<lli>(w, -1));
    lli way = 0;
    rep(i, h){
        cin >> maze[i];
        rep(j, w) if(maze[i][j] == '.') way++;
    }
    auto bfs = [&](pair<lli, lli> s){
        queue<pair<lli, lli>> q;
        q.push(s);
        c[s.first][s.second] = 0;
        while(!q.empty()){
            lli x = q.front().first;
            lli y = q.front().second;
            q.pop();
            rep(i, 4){
                lli nx = x+dx[i];
                lli ny = y+dy[i];
                if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                if(maze[nx][ny] == '#') continue;
                if(c[nx][ny] != -1) continue;
                c[nx][ny] = c[x][y]+1;
                q.push({nx, ny});
            }
        }
    };
    bfs({0, 0});
    if(c[h-1][w-1] == -1) cout << -1 << endl;
    else cout << way-c[h-1][w-1]-1 << endl;

    return 0;
}


Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int N, A, B;

bool check(int v) {

	char	s[8];
	sprintf(s, "%d", v);

	int total = 0;
	for (int i = 0; s[i] != '\0'; i++) {
		int v = s[i] - '0';
		total += v;
	}

	return (A <= total && total <= B);
}

int main(void) {

	cin >> N >> A >> B;

	int sum = 0;
	for (int i = 1; i <= N; i++) {
		if (check(i)) {
			sum += i;
		}
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	double L;
	cin >> L;
	cout << fixed << setprecision(10) << pow(L/3,3) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a[200001]={0};
	int n,m,x,y,i;
	scanf("%d %d",&n,&m);
	int flag=0;
	for(i=1;i<=m;i++)
	{
		scanf("%d %d",&x,&y);
		if(x==1&&y!=n)
		{
			a[y]++;
		}
		if(y==n&&x!=1)
		{
			a[x]++;
		}
		if(a[x]==2||a[y]==2)
		{
			flag=1;
		}
	}
	if(flag==1) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
} 


Measured memory_bytes: 896
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

#define int ll

int a[maxn];

int32_t main()
{
	int n, x; scanf("%lld %lld", &n, &x);
	for(int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
		a[i] = abs(a[i] - x);
	}
	int res = a[1];
	for(int i = 2; i <= n; i++){
		res = __gcd(res, a[i]);
	}
	printf("%lld\n", res);
	return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n;
  cin >> n;
  int num = (n & 1 ? n / 2 + 1 : n / 2);
  cout << fixed << setprecision(10) << (1. * num) / n << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,t;
    scanf("%d\n",&n);
    char s[n];
    gets(s);
    t=0;
    for(i=0;i<n;i++){
        if(s[i]!=s[i+1]){
            t++;
        }
    }
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
s_a = sorted(a)
cnt = 0

for i in range(N-1):
    if(s_a[i] <= x):
        cnt += 1
        x -= s_a[i]
if(s_a[N-1] - x == 0):
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)
from heapq import heappop, heappush,heapify

icase=0
if icase==0:
    n=int(input())
    xy=[[0]*2 for i in range(n)]
    x=[0]*n
    y=[0]*n
    for i in range(n):
#        xy[i]=list(map(int,input().split()))
        x[i],y[i]=map(int,input().split())
elif icase==1:    
    n=3
#    xy=[[1, 5], [3, 9], [7, 8]]
    x=[1, 3, 7]
    y=[5, 9, 8]
elif icase==2:    
    n=6
#    xy=[[8, 3], [4, 9], [12, 19], [18, 1], [13, 5], [7, 6]]
    x=[8, 4, 12,18,13,7]
    y=[3, 9, 19, 1, 5, 6]

xi=[[0]*2 for i in range(n)]
yi=[[0]*2 for i in range(n)]
for i in range(n):
    xi[i]=[x[i],i]
    yi[i]=[y[i],i]
    
xi.sort()
x=xi
y=yi.sort()
y=yi

pair_lst = [i for i in range(n)]
que=[]
for i in range(n-1):
    wi=x[i+1][0]-x[i][0]
    heappush(que,(wi,x[i][1],x[i+1][1]))
    wi=y[i+1][0]-y[i][0]
    heappush(que,(wi,y[i][1],y[i+1][1]))

def find(x):
    if x == pair_lst[x]:
        return x
    else:
        tmp = find(pair_lst[x])
        pair_lst[x] = tmp
        return tmp

icnt=0
length_sum = 0
while que:
    w, s, t = heappop(que)
#    print(w,s,t)
    root_s = find(s)
    root_t = find(t)
    if root_s != root_t:
        pair_lst[root_s] = root_t
        length_sum += w
        icnt+=1
#        print(icnt)

print(length_sum)   


Measured memory_bytes: 195628
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var values = cin.ReadIntArray(5);
            var A = values[0]; 
            var B = values[1];
            var C = values[2];
            var X = values[3];
            var Y = values[4];
            
            var ans = 0;
            var money = Min(X,Y) == X? B : A;
            
            if( A + B < 2 * C ){
                ans = A * X + B * Y;
            }else{
                
                ans = Min((Max(X ,Y) * 2 )*C, (Min(X,Y) * 2 )*C + Math.Abs(X - Y)*money);
            }
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11348
double p[333][333][333];n;c[4];j,k;main(i){for(;~scanf("%d",n?c:&n);)c[*c]++;for(;i>n?i=0,++j>n?j=0,k++<n:1:1;i++)p[i][j][k]=(i*p[i-!!i][j][k]+j*p[i+1][j-!!j][k]+k*p[i][j+1][k-!!k]+n)/(i+j+k);printf("%.9f",p[c[1]][c[2]][c[3]]);}

Measured memory_bytes: 262144
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
 
int query(vector<int> &x){
    cout<<"?";
    rep(i,x.size()) cout<<" "<<x[i]+1;
    cout<<endl;
 
    string t;
    cin>>t;
    if(t=="Red") return 1;
    else if(t=="Blue") return 2;
    else exit(0);
}
 
int main(){
    int N;
    cin>>N;
 
    vector<int> reds,blues;
    vector<int> v;
    rep(i,N) v.push_back(i);
    int lef=query(v);
    int rig=3-lef;
    int ok=N,ng=0;
    while(abs(ok-ng)>1){
        int mid=(ok+ng)/2;
        vector<int> v;
        rep(i,N) v.push_back(mid+i);
        int c=query(v);
        if(c==rig) ok=mid;
        else ng=mid;
    }
 
    if(lef==1){
        reds.push_back(ng);
        blues.push_back(ng+N);
    }else{
        blues.push_back(ng);
        reds.push_back(ng+N);
    }
 
    v.clear();
    for(int i=0;i<N-1;i++) v.push_back(ok+i);
 
    for(int i=0;i<2*N;i++){
        if(ng<=i&&i<=ng+N) continue;
        v.push_back(i);
        int c=query(v);
        if(c==1) reds.push_back(i);
        else blues.push_back(i);
        v.pop_back();
    }
 
    v.clear();
    for(int i=0;i<N/2;i++){
        v.push_back(reds[i]);
        v.push_back(blues[i]);
    }
    for(int i=ng+1;i<ng+N;i++){
        v.push_back(i);
        int c=query(v);
        if(c==1) reds.push_back(i);
        else blues.push_back(i);
        v.pop_back();
    }
 
    string ans(2*N,'p');
    rep(i,N){
        ans[reds[i]]='R';
        ans[blues[i]]='B';
    }
    cout<<"! "<<ans<<endl;
 
  return 0;
}

Measured memory_bytes: 724
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<string>s(3);
    cin>>s[0];
    cin>>s[1];
    cin>>s[2];
    int turn=0;
    vector<int>index(3,0);
    int winner=-1;
    while(1){
        if(index[turn]==s[turn].size()){
            winner=turn;
            break;
        }
        int temp=turn;
        turn =s[turn][index[turn]]-'a';
        index[temp]++;
    }
    switch(winner){
        case 0:{cout<<"A";break;}
        case 1:{cout<<"B";break;}
        case 2:{cout<<"C";break;}
    }
}

Measured memory_bytes: 3568
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let nk: Vec<i64> = util::gets();

    let c: Vec<i64> = (0..nk[0])
        .map(|_| util::get::<i64>() - nk[1])
        .fold((Vec::new(), 0), |(mut v, acc), a| {
            v.push(acc + a);
            (v, acc + a)
        })
        .0;

    let d: Vec<usize> = {
        let uniq: HashSet<_> = c.iter().cloned().collect();
        let mut uniq_sorted: Vec<_> = uniq.into_iter().collect();
        uniq_sorted.sort();

        c.iter()
            .map(|x| uniq_sorted.binary_search(x).unwrap())
            .collect()
    };

    let n = d.len();
    let mut bit = vec![Vec::new(); n + 1];

    for (i, &x) in (1..).zip(d.iter()) {
        let mut i = i as isize;
        while i as usize <= n {
            bit[i as usize].push(x);
            i += i & -i;
        }
    }

    for mut v in &mut bit {
        v.sort();
    }

    let mut ans = c.iter().filter(|&&x| x >= 0).count();

    for (i, &x) in d.iter().enumerate() {
        let mut i = i as isize;
        while i > 0 {
            ans += binary_search(0, bit[i as usize].len(), x, &bit[i as usize]);
            i -= i & -i;
        }
    }

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

fn binary_search<T: Ord>(low: usize, high: usize, x: T, v: &Vec<T>) -> usize {
    let mid = (low + high) / 2;
    if mid == low {
        return if v[mid] <= x { high } else { low };
    }

    if v[mid] <= x {
        binary_search(mid, high, x, v)
    } else {
        binary_search(low, mid, x, v)
    }
}


Measured memory_bytes: 32968
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <math.h>

using namespace std;

/*lli gcd(lli a,lli b)
{
	if(a==0)return b;
	return gcd(b%a,a);
}*/

int main()
{
    /*ios_base::sync_with_stdio(false);
    cin.tie(NULL);*/
    int a,b,k;
    cin>>k>>a>>b;
    if(b/k!=a/k || a%k==0 || b%k==0)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
B = list(map(int, input().split()))

A = []
A.append(B[0])
for i in range(0, N-2):
  if B[i] < B[i+1]:
    A.append(B[i])
  else:
    A.append(B[i+1])
A.append(B[N-2])
print(sum(A))

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

int main(){
  string S;
  cin>>S;
  vector<string> vec={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  for(int i=0;i<7;i++){
    if(S==vec.at(i)){
      cout<<7-i;
      break;
    }
  }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int cnt = 0;
    int tmp = 0;
    for (int i = 0; i < 3; i++) {
        //cout << s[i] << '\n';
        if (s[i] == 'R') {
            ++tmp;
        } else {
            cnt = max(tmp, cnt);
            tmp = 0;
        }
        cnt = max(tmp, cnt);
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3644
import java.util.*
import kotlin.system.exitProcess

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val K = sc.nextInt()
val D = Array(K) { sc.nextInt() }

fun main(args: Array<String>) {
    for (i in 0..Int.MAX_VALUE) {
        dfs("", i)
    }
}

fun dfs(s: String, m: Int) {
    if (s != "" && s.toInt() >= N) {
        println(s)
        exitProcess(0)
    }
    if (s.length == m) {
        return
    }
    for (i in 0..9) {
        if (i !in D) {
            dfs(i.toString() + s, m)
        }
    }
}


Measured memory_bytes: 36024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>

//#define PI 3.141592653589

using namespace std;



int main()
{
	int n;
	int pm[10000], pe[10000], pj[10000];
	
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		
		for (int i=0; i<n; i++)
		{
			cin >> pm[i] >> pe[i] >> pj[i];
			if (pm[i]==100 || pe[i]==100 || pj[i]==100)
			{
				cout << "A" << endl;
			} else if ((pm[i]+pe[i]) / 2 >= 90) {
				cout << "A" << endl;
			} else if ((pm[i]+pe[i]+pj[i]) / 3 >= 80) {
				cout << "A" << endl;
			} else if ((pm[i]+pe[i]+pj[i]) / 3 >= 70) {
				cout << "B" << endl;
			} else if (((pm[i]+pe[i]+pj[i]) / 3 >= 50) && (pm[i] >= 80 || pe[i] >= 80)) {
				cout << "B" << endl;
			} else {
				cout << "C" << endl;
			}
		}
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;

int main(){
	int r; cin >> r;
	cout << r*r << endl;	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>

#define ll long long
#define nums vector<int>
#define words vector<string>

using namespace std;

int lol(int n) {
    int a = n % 10;
    return a;
}
int main(void) {
    int n;
    cin >> n;
    int b = lol(n);
    if (b == 2 || b == 4 || b == 5 || b == 7 || b == 9) {
        cout << "hon" << endl;
        return 0;
    }
    if (b == 0 || b == 1 || b == 6 || b == 8) {
        cout << "pon" << endl;
        return 0;
    }
    if (b == 3) {
        cout << "bon" << endl;
    }

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* ?????° {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

int hoge(int n, int s, int num)
{
  if (n == 0 && s == 0) return 1;
  if (num > 9 || s < 0) return 0;
  return (hoge(n, s, num + 1) + hoge(n - 1, s - num, num + 1));
}
  
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, s;
  while(cin >> n >> s){
    if (n == 0) break;
    cout << hoge(n, s, 0) << endl;
  }
  return (0);
}

Measured memory_bytes: 1196