akhauriyash/Code-Regression huggingface dataset:
# cook your dish here
import numpy as np
if __name__ == '__main__':
    xy = [int(i) for i in input().split()]
    a1 = np.array([xy[0], xy[1]])
    a2 = np.array([xy[2], xy[3]])
    b = a2 - a1
    r = np.pi / 2
    rot = np.matrix((
        (np.cos(r), np.sin(r)),
        (-np.sin(r), np.cos(r))
    ))
    c = np.dot(b, rot)
    a3 = a2+c
    a4 = a1+c
    print('{} {} {} {}'.format(int(np.round(a3[0,0])), int(np.round(a3[0,1])), int(np.round(a4[0,0])), int(np.round(a4[0,1]))))


Measured memory_bytes: 21300
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a;
  string s;
  cin>>a>>s;
  if(a>=3200){
    cout<<s<<endl;
  }else{
    cout<<"red"<<endl;
  }
}


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

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;

    vector<int> nums;    
    if (S[0] == '0') nums.push_back(0);
    for (int i = 0; i < S.size();) {
        int j = i;
        while (j < S.size() && S[j] == S[i]) ++j;
        nums.push_back(j - i);
        i = j;
    }
    if (S.back() == '0') nums.push_back(0);

    vector<int> sums((int)nums.size() + 1, 0);
    for (int i = 0; i < nums.size(); ++i) sums[i+1] = sums[i] + nums[i];

    int res = 0;
    for (int left = 0; left < sums.size(); left += 2) {
        int right = left + K*2+1;
        if (right >= sums.size()) right = (int)sums.size() - 1;
        res = max(res, sums[right] - sums[left]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1272
//ラブライブ！サンシャイン！！
//AT2274
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double du;
const ll inf=9223372036854775807ll;
struct line {
	ll k,b;//y=kx+b
	line(ll k=0,ll b=0):k(k),b(b) {}
	ll get(ll x) {
		return k*x+b;
	}
} st[300010],u;
int tp;
du its(line a,line b) {
	return(b.b-a.b)/du(a.k-b.k);
}
int t[300010],n;
ll s[300010],f[300010],g[300010];
void dp(ll*f) {
	int i;
	for(i=1; i<=n; i++)s[i]=s[i-1]+t[i];
	tp=1;
	st[1]=line(0,0);
	for(i=1; i<=n; i++) {
		while(tp>1&&st[tp].get(i)<=st[tp-1].get(i))tp--;
		f[i]=max(st[tp].get(i)+((ll)i*i+i)/2-s[i],f[i-1]);
		u=line(-i,f[i]+((ll)i*i-i)/2+s[i]);
		while(tp>1&&its(u,st[tp-1])>=its(st[tp],st[tp-1]))tp--;
		st[++tp]=u;
	}
}
ll h[300010];
void solve(int l,int r) {
	if(l==r) {
		h[l]=1ll-t[l];
		return;
	}
	int mid,i,now;
	ll mx;
	mid=(l+r)>>1;
	solve(l,mid);
	solve(mid+1,r);
	tp=0;
	for(i=l-1; i<mid; i++) {
		u=line(-i,f[i]+((ll)i*i-i)/2+s[i]);
		while(tp>1&&its(u,st[tp-1])>=its(st[tp],st[tp-1]))tp--;
		st[++tp]=u;
	}
	now=1;
	mx=-inf;
	for(i=r; i>mid; i--) {
		while(now<tp&&its(st[now],st[now+1])>=i)now++;
		mx=max(mx,st[now].get(i)+((ll)i*i+i)/2-s[i]+g[i+1]);
		h[i]=max(h[i],mx);
	}
	tp=0;
	for(i=mid+1; i<=r; i++) {
		u=line(-i,g[i+1]+((ll)i*i+i)/2-s[i]);
		while(tp>1&&its(u,st[tp-1])>=its(st[tp],st[tp-1]))tp--;
		st[++tp]=u;
	}
	now=tp;
	mx=-inf;
	for(i=l-1; i<mid; i++) {
		while(now>1&&its(st[now],st[now-1])<=i)now--;
		mx=max(mx,st[now].get(i)+((ll)i*i-i)/2+s[i]+f[i]);
		h[i+1]=max(h[i+1],mx);
	}
}
int main() {
	int i,m,x,y;
	scanf("%d",&n);
	for(i=1; i<=n; i++)scanf("%d",t+i);
	dp(f);
	reverse(t+1,t+n+1);
	dp(g);
	reverse(t+1,t+n+1);
	reverse(g+1,g+n+1);
	for(i=1; i<=n; i++)s[i]=s[i-1]+t[i];
	solve(1,n);
	scanf("%d",&m);
	while(m--) {
		scanf("%d%d",&x,&y);
		printf("%lld\n",max(f[x-1]+g[x+1],h[x]+t[x]-y));
	}
}

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

int main() {
  int N, M, count=0;
  float all=0;
  cin >> N >> M;
  
  vector<int> Ai(N);
  
  rep(i, N){
    cin >> Ai.at(i);
    all += Ai.at(i);
    }
  
  rep(i, N){
    if(Ai.at(i) >= all/(4*M)){
      count++;
      }
    }
  
  if(count >= M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
  long long x;
  long k,d;
  cin >> x >> k >> d;

  if(x<0) x*=-1;

  long shou = x/d;
  long amari = x%d;

  // cout << shou << " " << amari << endl;

  if(k <shou){
    cout << x - k*d << endl;
    return 0;
  }
  
  if(shou%2==k%2){
    cout << amari << endl;
    return 0;
  } else {
    cout << d - amari << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3600
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
if n >= m:
    print(0)
    exit()
l = [0 for _ in range(m-1)]
for i in range(m-1):
    l[i] = x[i+1] - x[i]
l.sort(reverse=True)
print(sum(l[n-1:]))

Measured memory_bytes: 13960
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
int main(){
    int N,A;
    cin >> N >> A;
    N %= 500;
    if(N <= A) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: i64 = input();
    let m: i64 = input();
    println!("{}", (n - 1) * (m - 1));
}


Measured memory_bytes: 4352
n, k = map(int,input().split())
s = str(input())
if 1 < k < 3:
    front = s[0]
elif k == 1:
    front = ''
else:
    front = s[:k-1]
tmp = s[k-1]
rear = s[k:]


print(front+tmp.lower()+rear)

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

int main() {
  int n;
  cin >> n;

  vector<int> x(n);
  int ave = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    ave += x[i];
  }

  ave /= n;

  int suma = 0, sumb = 0;
  for (int i = 0; i < n; i++) {
    suma += (x[i] - ave) * (x[i] - ave);
    sumb += (x[i] - ave - 1) * (x[i] - ave - 1);
  }

  cout << min(suma, sumb) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;
ll s1[N],s2[N];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;i++){
		scanf("%d%d",&x,&y);
		s1[i]=x+y;
		s2[i]=x-y;
	}
	sort(s1+1,s1+1+n);
	sort(s2+1,s2+1+n);
	printf("%lld\n",max(s1[n]-s1[1],s2[n]-s2[1]));
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

struct Edge { ll from; ll to; ll weight; };
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int l; cin >> l;
	vector<Edge> v;
	int n = 20;
	REP(i, n - 1) {
		if (l <= 1) {
			v.push_back({ i + 1,i + 2,0 });
			continue;
		}
		if (l % 2 == 1 && l != 1) {
			v.push_back({ i + 1, n, l / 2 });
		}
		v.push_back({ i + 1,i + 2,0 });
		if ((l + 1) / 2 != 0)v.push_back({ i + 1,i + 2,(l + 1) / 2 });
		l /= 2;
	}
	cout << n << " " << v.size() << endl;
	REP(i, v.size())cout << v[i].from << " " << v[i].to << " " << v[i].weight << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using namespace std;


int main()
{
	int n;
	cin >> n ;
	vector<pair<int, int>> p(n);

	rep(i, n) {
		int a;
		cin >> a;
		p.at(i) = make_pair(a, i + 1);
	}

	sort(p.begin(), p.end());

	rep(i, n) {
		int b,a;
		tie(b, a) = p.at(i);
		cout << a << " ";
	}
	
}

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;



int main(){

    ll k;
    ll m = 100;
    cin >> k;
    ll count = 0;

    while(m < k){
        count++;

        m = m + m / 100;
    }

    cout << count << endl;
    

    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 1111

typedef long long ll;
typedef long double ld;

vector<int> adj[maxn];
int val[maxn];
int dp[maxn];
int cur[maxn][5111];
bool ok;

void DFS(int x){
	vector<int> opt;
	if(adj[x].size() == 0)
		dp[x] = 0;

	for(int v : adj[x]){
		DFS(v);
		opt.pb(v);
	}

	for(int i = 0; i < opt.size() + 2; i++)
		for(int j = 0; j <= val[x]; j++)
			cur[i][j] = 1e9;

	cur[0][0] = 0;
	for(int i = 0; i < opt.size(); i++){
		for(int j = 0; j <= val[x]; j++){
			if(j + dp[opt[i]] <= val[x])
				cur[i + 1][j + dp[opt[i]]] = min(cur[i + 1][j + dp[opt[i]]], cur[i][j] + val[opt[i]]);

			if(j + val[opt[i]] <= val[x])
				cur[i + 1][j + val[opt[i]]] = min(cur[i + 1][j + val[opt[i]]], cur[i][j] + dp[opt[i]]);
		}
	}

	int mini = 1e9 + 1;
	for(int i = 0; i <= val[x]; i++)
		mini = min(mini, cur[opt.size()][i]);

	if(mini == 1e9)
		ok = 0;

	dp[x] = mini;
}



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

	for(int i = 1; i < maxn; i++)
		dp[i] = 1e9;
 
	for(int i = 1; i <= n; i++)
		scanf("%d", val + i);

	DFS(1);	

	if(ok)
		printf("POSSIBLE\n");
	else
		printf("IMPOSSIBLE\n");

	return 0;
}

Measured memory_bytes: 19072
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;

int main(){
    stack<int> S;
    int a,b,x;
    string s;
    
    while(cin >> s){
        if(s[0]=='+'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a+b);
        }else if(s[0]=='-'){
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a-b);
        }else if(s[0]=='*'){
            a = S.top(); S.pop();
            b = S.top(); S.pop();
            S.push(a*b);
        }else{
            S.push(atoi(s.c_str()));
        }
    }
    
    cout << S.top() << endl;
    
    return 0;
}

Measured memory_bytes: 3164
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	
    	double a=sc.nextDouble();
    	double b=2;
    	System.out.println(String.format("%.6f", a*a*Math.PI)+" "+String.format("%.6f", b*Math.PI*a));
    }
}



Measured memory_bytes: 28296
while 1:
	n=input()
	if n==0:break
	dic={}
	for i in range(n):
		k,v=raw_input().split()
		dic[k]=v
	n=input()
	ans=""
	for i in range(n):
		a=raw_input()[0]
		try:ans+=dic[a]
		except:ans+=a
	print ans
			
	

Measured memory_bytes: 7352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  n, mincost;
  cin >> n;
  vector<int> x(n), cost(101);
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  for(int i = 0; i <= 100; i++){
    for(int j = 0; j < n; j++){
      cost[i] += (i - x[j])*(i - x[j]);
    }
  }
  mincost = cost[0];
  
  for(int i = 0; i <= 100; i++){
    if(cost[i] < mincost){
      mincost = cost[i];
    }
  }
  cout << mincost <<endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	long long int a, b, c, d;
	cin >> N >> a >> b >> c >> d;
	N -- ;
	for (int i = 0; i <= N; i++) {
		long long int up_m = c*i;
		long long int up_M = d*i;
		long long int down_m = c*(N - i);
		long long int down_M = d*(N - i);
		if (a + up_M - down_m >= b&&a + up_m-down_M<=b) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
#define int long long

const int MAX_N = 1010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	map<int, bool>tmp,tmp2;
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		if (a == 0)tmp[b] = true;
		if (b == n - 1)tmp2[a] = true;
	}
	bool ok = false;
	rep(i, n) {
		if (i == 0 || i == n - 1)continue;
		if (tmp[i] && tmp2[i]) {
			ok = true;
		}
	}
	if (ok)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 25216
fun main(args : Array<String>) {
    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toLong() }
    val bb = readLine()!!.split(" ").map { it.toLong() }

    val aTime = mutableListOf<Long>()
    aTime.add(aa[0])
    for (i in 1 until aa.size) {
        aTime.add(aTime[i-1] + aa[i])
    }
    aTime.add(0, 0)

    val bTime = mutableListOf<Long>()
    bTime.add(bb[0])
    for (i in 1 until bb.size) {
        bTime.add(bTime[i-1] + bb[i])
    }
    bTime.add(0, 0)

    var cnt = 0
    var lastBIdx = m

    for (i in 0..n) {
        val at = aTime[i]
        if (at > k) break

        val rest = k - at
        var tmpCnt = i

        inner@for (j in lastBIdx downTo 0) {
            if (bTime[j] <= rest) {
                tmpCnt += j
                lastBIdx = j
                break@inner
            }
        }

        cnt = Math.max(cnt, tmpCnt)
    }

    println(cnt)
}

Measured memory_bytes: 91132
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        ArrayList<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {
            mylist.add(strinput);
            strinput = reader.readLine();
        }

        String s = mylist.get(0);
        String t = mylist.get(1);

        // 正規表現パターン指定
        Pattern p1 = Pattern.compile(s + "[a-z]");
        Matcher m1 = p1.matcher(t);
        System.out.println(m1.find() ? "Yes" : "No");

    }

}


Measured memory_bytes: 36856
import java.util.Arrays;
import java.util.Scanner;

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();
        }
        int M = sc.nextInt();
        int[] T = new int[M];
        for (int i = 0; i < M; i++) {
            T[i] = sc.nextInt();
        }
        Arrays.sort(D);
        Arrays.sort(T);
        int index = 0;
        for (int i : D) {
            if (index < T.length && T[index] == i) {
                index++;
            }
        }
        System.out.println(index == T.length ? "YES" : "NO");

    }
}

Measured memory_bytes: 60872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int n;

i64 a[310][310];

bool f[310][310];

int main()
{
	cin >> n;
	rep(i,1,n) rep(j,1,n)
		cin >> a[i][j];
	
	rep(k,1,n) rep(i,1,n) rep(j,1,n)
	{
		if(i == j || i == k || j == k) continue;
		if(a[i][j] > a[i][k] + a[k][j])
		{
			cout << -1 << endl;
			return 0;
		}
		if(a[i][j] == a[i][k] + a[k][j])
		{
			f[i][j] = 1;
		}
	}
	i64 result = 0;

	rep(i,1,n) rep(j,1,i)
	{
		if(!f[i][j]) result += a[i][j];
	}
	cout << result << endl;
	return 0;
}
	



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long a[300100];
int main(){
	int n;
	scanf("%d",&n);
	long long ans=0ll;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
	}
	for(long long i=0;i<60;i++){
		long long c=0ll,b=0ll;
		for(int j=1;j<=n;j++){
			if(a[j] & (1ll<<i))c++;
			else b++;
		}
		ans=(ans+((long long)(c*b)%mod*((1ll<<i)%mod))%mod)%mod;
	}

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

Measured memory_bytes: 2560
/*
g++ --std=c++17 C.cpp
*/

#include <iostream>
#include <iomanip> //! for setprecision(20)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < int(n); ++i)
template<class T> inline bool chmax(T& a, T b) { bool ret = (a < b); if (ret) { a = b; } return ret; }
template<class T> inline bool chmin(T& a, T b) { bool ret = (b < a); if (ret) { a = b; } return ret; }
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int INF = 1000000000;
const int MOD = 1000000007;


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

  LL n;
  cin >> n;

  LL ans = 0;
  for (LL a = 1; a < n; ++a) {
    LL minB = 1;
    LL maxB = (n-1)/a;
    LL cnt = (maxB-minB)+1;
    if (0 < cnt) ans += cnt;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
a,b,c = map(lambda x:int(x),input().split())
reps = 0
while a%2==0 and b%2==0 and c%2==0:
  if (a==b==c):
    reps = -1
    break
  at=a
  bt=b
  ct=c
  a = int(bt/2+ct/2)
  b = int(at/2+ct/2)
  c = int(at/2+bt/2)
  reps += 1
print(reps)

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

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n-1)

char S[11];

int main(void){
	int step=0;
	int A, B;

	scanf("%d%d", &A, &B);

	fflush(stdin);
	scanf("%s", S);

	if(strlen(S)!=A+B+1){
		printf("No\n");
		return 0;
	}

	FOR(i, 0, A+B+1){
		if(('0'>S[i]||S[i]>'9')&&(S[i]!='-')){
			printf("No\n");
			return 0;
		}
		switch(step)
		{
			case 0:
				if('0'<=S[i]&&S[i]<='9'){
					step++;
				}else{
					printf("No\n");
					return 0;
				}
				break;
			case 1:
				if(S[i]=='-'){
					if(i!=A) { printf("No\n"); return 0;}
					step++;
				}
				break;
			case 2:
				if('0'<=S[i]&&S[i]<='9'){
					step++;
				}else if(S[i]=='-'){
					printf("No\n");
					return 0;
				}
				break;
			case 3:
				if('0'>S[i]&&S[i]>'9'){
					printf("No\n");
					return 0;
				}else if(S[i]=='-'){
					printf("No\n");
					return 0;
				}
				break;
		}
	}

	if(step!=3) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
// 昇順配列のうち間違いが2であれば, それをswapすることで元の昇順配列に戻る		

#include<iostream>
using namespace std;
int main()
{
  int n,memo[51],memo_index[51],cnt=0;
  int a[51];
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++)if(i+1 != a[i])cnt++;
  if(cnt==2 || cnt==0)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define eb emplace_back
#define PI 3.14159265
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double ld;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, s = 0;
    cin >> n;
    vector<bool> a(n + 1, false);
    for (ll i = 3; i <= n; i += 3)
    {
        a[i] = true;
    }
    for (ll i = 5; i <= n; i += 5)
    {
        a[i] = true;
    }
    for (ll i = 1; i <= n; i++)
    {
        if (!a[i])
        {
            s += i;
        }
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
long long n, m, a, b, c, ans, A[MAXN];
string str1, str2;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> a >> b;
	cout << a / __gcd(a, b) * b << endl;
	return 0;
}

Measured memory_bytes: 256
class PriorityQueue
  MIN = -(1 << 60)

  attr_reader :size

  def initialize(&block)
    @size = 0
    @heap = Array.new
    @get_key = block || :itself.to_proc
  end

  def empty?
    size == 0
  end

  def pop
    return nil if @size <= 0
    max = @heap[1]
    @heap[1] = @heap[@size]
    @size -= 1
    max_heapify(1)
    max
  end

  def push(x)
    @size += 1
    i = @size
    @heap[i] = x
    while i > 1 && (@get_key.call(@heap[i / 2]) <=> @get_key.call(@heap[i])) == -1
      t = @heap[i / 2]
      @heap[i / 2] = @heap[i]
      @heap[i] = t
      i = i / 2
    end
  end

  def top
    return nil if @size <= 0
    @heap[1]
  end

  def to_a
    return [] if @size == 0
    @heap[1..@size]
  end

  private

  def max_heapify(i)
    l = 2 * i
    r = 2 * i + 1
    largest =
      l <= @size && (@get_key.call(@heap[l]) <=> @get_key.call(@heap[i])) == 1 ? l : i
    largest = r \
      if r <= @size && (@get_key.call(@heap[r]) <=> @get_key.call(@heap[largest])) == 1
    unless largest == i
      t = @heap[i]
      @heap[i] = @heap[largest]
      @heap[largest] = t
      max_heapify(largest)
    end
  end
end


N, M = gets.split.map(&:to_i)
ab_list = N.times.map { gets.split.map(&:to_i) }.select { |(a, b)| a <= M }
group = ab_list.group_by { |(a, _)| a }
pq = PriorityQueue.new do |(a, b)|
  b
end
ans = 0
M.times do |i|
  w = i + 1
  (group[w] || []).each { |(a, b)| pq.push([a, b]) }
  next if pq.empty?
  _, b = pq.pop
  ans += b
end
puts ans


Measured memory_bytes: 22012
#include <iostream>
typedef long long int ll;
typedef long double ld;

int main(void){
	ll N, X, Y, D, res = 0;
	std::cin >> N >> D;
	for(int i = 0; i < N; i++){
		std::cin >> X >> Y;
		if(X*X + Y*Y <= D*D) res++;
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // 998244353 //  //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << " "; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a/__gcd(a, b))*b; }

void solve(){
    ll n;
    string s;
    cin >> n >> s;
    map<char, ll> mp;
    for(auto x: s) mp[x]++;
    ll ans = 1;
    itr(it, mp){
        ans = (ans*(it->sd+1))%MOD;
    }
    cout << (ans+MOD-1)%MOD;
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

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

template <typename T>
void say(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}


/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int A, B;
	char op;
	cin >> A >> op >> B;
	
	if (op == '+') cout << A + B << endl;
	else cout << A - B << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int W,H,r,x,y;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    int xLeft,xRight,yUp,yDown;
    xLeft = x-r;
    xRight = x+r;
    yUp = y+r;
    yDown = y-r;
    if(xLeft<0 || xRight>W || yUp>H || yDown<0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}


Measured memory_bytes: 2120
#include<stdio.h>
int n,t,r;
char s[6];
void f()
{
	int d[5]={1,3,4,2,5};
	for(r=1;n--;)
	{
		scanf("%s",s);
		switch(s[0])
		{
		case 'N':d[4]=d[0];d[0]=d[3];d[3]=7-d[4];break;
		case 'S':d[3]=d[0];d[0]=d[4];d[4]=7-d[3];break;
		case 'E':d[1]=d[0];d[0]=d[2];d[2]=7-d[1];break;
		case 'W':d[2]=d[0];d[0]=d[1];d[1]=7-d[2];break;
		case 'R':t=d[3];d[3]=d[1];d[1]=d[4];d[4]=d[2];d[2]=t;break;
		case 'L':t=d[4];d[4]=d[1];d[1]=d[3];d[3]=d[2];d[2]=t;break;
		}
		r+=d[0];
	}
	printf("%d\n",r);
}
int main()
{
	for(;scanf("%d",&n),n;)
		f();
	return 0;
}

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

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using D = double;
using S = string;
using SS = stringstream;
using C = char;
using LL = long long;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

template <class T>
void PrintVector(vector<T> & v, unsigned n) {
  rep(i, 0, n - 1) {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main(int argc, char const *argv[]) {
  L n, a, b, c;
  VL v;
  cin >> n;
  cin >> a >> b;
  cin >> c;
  rep(i, 0, n - 1) {
    L ci;
    cin >> ci;
    v.pb(ci);
  }
  sort(v.begin(), v.end(), greater<>());

  D initp = double(c) / a;
  rep(i, 0, n - 1) {
    c += v[i];
    a += b;
    if (double(c) / a > initp) { initp = double(c) / a; }
  }
  cout << int(initp) << endl;
  return 0;
}

Measured memory_bytes: 3144
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const ll INF = std::numeric_limits<long long>::max();
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define sz size
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, sums[2][110], ans = 0;
int main() {
	cin >> n;
	ll num = 0;
	rep(i, n) {
		cin >> num;
		if (i == 0)sums[0][i] = num;
		else sums[0][i] = num + sums[0][i - 1];
	}
	rep(i, n) {
		cin >> num;
		if (i == 0)sums[1][i] = num;
		else sums[1][i] = num + sums[1][i - 1];
	}
	ll nn=0;
	rep(i, n) {
		nn += (i == 0 ? sums[1][n - 1]+sums[0][0]: sums[0][i] + sums[1][n-1] - sums[1][i - 1]);
		ans = max(nn, ans);
		nn = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
 
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    if(n==1||n==2||n==3||n==5||n==6||n==9||n==10||n==13||n==17)
      System.out.println("No");
    else
      System.out.println("Yes");
  }
}

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

char s[1024];
int n;

int main(){
	fgets(s,1024,stdin);
	n = strlen(s);	

	for(int i = 0; i < n-4;i++){
		if(s[i] == 'a' && s[i+1] == 'p' && s[i+2] == 'p' && s[i+3] == 'l' && s[i+4] == 'e'){
			s[i] = 'p';
			s[i+1] = 'e';
			s[i+2] = 'a';
			s[i+3] = 'c';
			s[i+4] = 'h';
			i += 3;
		}
		if(s[i] == 'p' && s[i+1] == 'e' && s[i+2] == 'a' && s[i+3] == 'c' && s[i+4] == 'h'){
			s[i] = 'a';
			s[i+1] = 'p';
			s[i+2] = 'p';
			s[i+3] = 'l';
			s[i+4] = 'e';
			i += 3;
		}
	}
	printf("%s",s);

	return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, r, q;
vector<int> a,b,c;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> q;
        a.push_back(q-1);
    }
    for(int i = 0; i < n; i++){
        cin >> q;
        b.push_back(q);
    }
    for(int i = 1; i < n; i++){
        cin >> q;
        c.push_back(q);
    }
    q = n;
    for(int i : a){
        if (i-q == 1) r += c[q];
        r += b[i];
        q = i;
    }
    cout << r;
}

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

int main(){
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    while(1) {
        if ( x > y ) break;
        ++ans;
        x *= 2;
    }
    cout << ans << endl;
    return 0;
}


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

bool judge(int k, int n, vector<int> a) {
    vector<pair<int, int>> v;
    int size = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > size) {
            size = a[i];
        } else {
            size = a[i];
            while (!v.empty() && v.back().first > a[i]) {
                v.pop_back();
            }
            if (v.empty() || v.back().first != a[i]) {
                v.emplace_back(a[i], 0);
            }
            while (true) {
                if (v.empty() || v.back().first != a[i]) {
                    v.emplace_back(a[i], 0);
                }
                v.back().second++;
                if (v.back().second != k) break;
                else {
                    v.pop_back();
                    a[i]--;
                }
                if (a[i] == 0) return false;
            }
        }
    }
    return true;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    bool flag = true;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i && a[i] <= a[i-1]) flag = false;
    }
    if (flag) {
        cout << 1 << endl;
        return 0;
    }
    int left = 1; int right = n;
    while (right - left > 1) {
        int mid = (right + left) / 2;
        if (judge(mid, n, a)) right = mid;
        else left = mid;
    }
    cout << right << endl;
    return 0;
}

Measured memory_bytes: 2428
#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[21];
    int i;

    scanf("%s", str);
    for (i = strlen(str) - 1; i >= 0; --i) {
        putchar(str[i]);
    }
    printf("\n");

    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> r(N);
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    r.at(a-1)++;
    r.at(b-1)++;
  }
  for(int i=0; i<N; i++) cout << r.at(i) << endl;
}

Measured memory_bytes: 256
while True:
    c=0
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    if n<m:
        n,m=m,n
    while True:
        if m==0:
            print(n,c)
            break
        n=n%m
        n,m=m,n
        c=c+1
    
    


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

using namespace std;

int main(){
  int N, w = 0, b = 0;
  string S;
  cin >> N >> S;

  for (int i = 0; i < N; i++){
    if (S[i] == '.') w++;
  }

  int ans = w;

  for (int i = 0; i < N; i++){
    if (S[i] == '.') w--;
    if (S[i] == '#') b++;
    ans = min(ans, w + b); 
  }
  

  printf("%d\n", ans);
  
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  string N;
  int K;
  cin >> N >> K;
  int size=N.size();
  vi d(size);
  rep(i,size) d[i]=N[i]-'0';
  
  int ans=0,add;
  rep2(i,K,size) {
    add=9;
    rep(j,K-1) {
      add*=(i-1-j)*9;
      add/=(j+1);
    }
    ans+=add;
  }
  if(K<=size) {
    add=d[0]-1;
    rep(j,K-1) {
      add*=(size-1-j)*9;
      add/=(j+1);
    }
    ans+=add;
    if(K==1) ans+=1;
    else {
      int k=1;
      while(k<size) {
        if(d[k]!=0) break;
        k++;
      }
      if(K==2&&k<size) ans+=d[k]+9*(size-k-1);
      else if(K==3&&k<size-1) {
        ans+=(size-k-1)*(size-k-2)/2*81;
        int l=k+1;
        while(l<size) {
          if(d[l]!=0) break;
          l++;
        }
        if(l<size) ans+=(d[k]-1)*9*(size-k-1)+d[l]+9*(size-l-1);
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {

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

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long x = Long.parseLong(str[1]);

		str = br.readLine().split(" ");

		long a[] = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]) - x;
		}

		long g = Math.abs(a[0]);

		for (int i = 0; i < n; i++) {
			g = gcd(g, Math.abs(a[i]));
		}

		System.out.println(g);
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 46332
#include "bits/stdc++.h"
using namespace std;

int main() {
	int K, X;
	cin >> K >>X;
	int l = max(-1000000,(X - K + 1));
	int r = min(1000000, X + K - 1);
	for (int n = l;n<=r;++n) {
		if (n != l) {
			cout << " ";
		}
		cout << n;
	}
	return 0;
}

Measured memory_bytes: 3616
import sys
import math
from fractions import gcd
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = sorted(map(int, input().split()))

    if N == 2:
        print(max(A))
        exit()

    A0, A1, A2 = A[:3]
    A_min_sq = int(math.sqrt(A2)) + 1
    
    gcd_ls = set()
    for i in range(A_min_sq, 0, -1):
        div = set()
        c = 0
        if A0 % i == 0:
            div.add(A0 // i)
            c += 1
        if A1 % i == 0:
            div.add(A1 // i)
            c += 1
        if A2 % i == 0:
            div.add(A2 // i)
            c += 1
        if c < 2:
            continue
        gcd_ls.add(i)

        for j in div:
            if A0 % j == 0 and (A1 % j == 0 or A2 % j == 0):
                gcd_ls.add(j)
            elif A1 % j == 0 and A2 % j == 0:
                gcd_ls.add(j)
    gcd_ls = sorted(gcd_ls, reverse=True)

    for i in gcd_ls:
        wa = False
        for j in A:
            if j % i != 0:
                if wa:
                    break
                wa = True
        else:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 16148
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const a = arg[1].split(" ").map(n=>parseInt(n));
    
    let list = [];
    
    for(let i in a) {
        let temp = a[i] - (parseInt(i) + 1);
        
        list.push(temp);
    }
    
    let b = list.sort((a,b)=>a-b)[Math.floor(N / 2)];
    
    let answer = 0;

    for(let i in a) {
        let temp = Math.abs(a[i] - ((parseInt(i) + 1) + b));
        
        answer += temp;
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 54920
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template <typename T> void s_max(T& a, T b) {
	if (a < b) {
		a = b;
	}
}

const int mxN = 110, mxW = 1e5 + 5;
int N, W;
ll v[mxN], w[mxN], dp[mxN][mxW];

class TaskD {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> N >> W;
		for (int i = 1; i <= N; i++) in >> w[i] >> v[i];
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= W; j++) {
				dp[i][j] = dp[i - 1][j];
				if (j < w[i]) continue;
				s_max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
			}
		}
		out << dp[N][W];
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 81744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

ll solve(long long N, vector<string> S, ll A, ll B){
	bool f = true;
	rep(i, N) {
		rep(j, N) {
			if (S[(A+i)%N][(B+j)%N] != S[(A+j)%N][(B+i)%N]) f = false;
		}
	}
	if (f) return N-A-B; else return 0;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<string> S(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> S[i];
	}
	ll res = 0;
	rep(i,N) {
		res += solve(N, S, i, 0);
	}
	repn(i,N-1) {
		res += solve(N, S, 0, i);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 512
def INSTR():
	return input()

def INNUM():
	return int(INSTR())

def INSTR_S():
	return INSTR().split()

def INNUM_S():
	return map(int, INSTR_S())

def INSTR_SM(n):
	return [tuple(INSTR_S()) for _ in range(n)]

def INNUM_SM(n):
	return [tuple(INNUM_S()) for _ in range(n)]

A, B, C = INSTR_S()
print((A[0]+B[0]+C[0]).upper())

Measured memory_bytes: 3060
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())

minsum = 10**9
for i in range(1, N//2+1):
  j = N-i
  tmp = 0
  for s in str(i)+str(j):
    tmp += int(s)
  minsum = min(tmp, minsum)

print(minsum)




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

int main()
{
	int N;

	cin >> N;

	int A[N];

	for (int i = 1; i <= N; i++)
	{
		cin >> A[i];
	}

	int max1 = 0;
	int max2 = 0;

	int max1memo;
	int max2memo;

	for (int i = 1; i <= N; i++)
	{
		if (max1 < A[i])
		{
			max2 = max1;
			max1 = A[i];
			max1memo = i;
		}
		else if (max2 < A[i])
		{
			max2 = A[i];
			max2memo = i;
		}
	}

	for (int i = 1; i <= N; i++)
	{
		if (i != max1memo)
		{
			cout << A[max1memo] << endl;
		}
		else
		{
			cout << A[max2memo] << endl;
		}
	}

	/* 
	int Lmax = 0;
	int Rmax = 0;

	int Limemo;
	int Rimemo;

	for (int i = 2; i <= N; i++)
	{
		if (A[i] >= Rmax)
		{
			Rmax = A[i];
			Rimemo = i;
		}
	}
	
	cout << Rmax << endl;

	for (int i = 2; i <= N; i++)
	{
		if (A[i - 1] > Lmax)
		{
			Lmax = A[i - 1];
			Limemo = i;
		}

		if (A[i + 1] >)
		{
		}

		cout << max(A[Limemo], A[Rimemo]) << endl;
	}
	*/

	return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e10
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef unsigned long long ll;

ll gcd(ll a, ll b){
    if (a < b) swap(a,b);
    if (a % b == 0) return b;
    return gcd(a % b, b);
}

int main(){
    ll n;
    cin >> n;

    vector<ll> a(n, 0);

    ll currGcd;
    REP(i, n){
        cin >> a[i];
        if (i == 0) currGcd = a[i];
        else currGcd = gcd(currGcd, a[i]);
    }
    cout << currGcd << endl;
}
        

 

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,count=0,sum=0;
    cin >> n >> a >> b;
    char c;
    for(int i=0;i<n;i++){
        cin >> c;
        if(c == 'a'){
            if(count<a+b){
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
            count++;
        }else if(c == 'b'){
            if(count<a+b&&sum<b){
                cout << "Yes" << endl;
                count++;
                sum++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3632