akhauriyash/Code-Regression huggingface dataset:
import heapq


class Dijkstra:

    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point

    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [float("inf") for _ in range(num_of_city)]
        prev = [float("inf") for _ in range(num_of_city)]

        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        route_count = [0 for _ in range(num_of_city)]
        route_count[self.start_point] = 1
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)

            if dist[src] < prev_cost:
                continue

            for dest, cost in self.rote_map[src].items():
                if cost != float("inf") and dist[dest] > dist[src] + cost:
                    dist[dest] = dist[src] + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
                if dist[dest] == dist[src] + cost:
                    route_count[dest] += route_count[src]

        if self.goal_point is not None:
            return self._get_path(self.goal_point, prev)
        else:
            return dist, route_count

    def _get_path(self, goal, prev):
        path = [goal]
        dest = goal

        while prev[dest] != float("inf"):
            path.append(prev[dest])
            dest = prev[dest]

        return list(reversed(path))


N = int(input())
graph = [dict() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    graph[a - 1][b - 1] = 1
    graph[b - 1][a - 1] = 1

path = Dijkstra(graph, 0, N - 1).execute()
cost = len(path) - 1

black = 1
if cost % 2 == 0:
    tmp = (cost - 1) // 2
    black += tmp + 1
else:
    tmp = (cost - 1) // 2
    black += tmp
not_path = set(path[black:])
visited = [False for _ in range(N)]
q = [0]
visited[0] = False
while len(q) != 0:
    dist = q.pop()
    for d in graph[dist].keys():
        if visited[d] or d in not_path:
            continue
        q.append(d)
        visited[d] = True
for p in path:
    visited[p] = False
for v in visited:
    if v:
        black += 1
white = N - black

if black > white:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 51936
#include <iostream>

using namespace std;

int main(){
    int N, X;
    int L[100];
    cin >> N >> X;
    for(int i = 0; i < N; i++) cin >> L[i];
    int d = 0;
    int cnt = 1;
    for(int i = 1; i <= N; i++){
        d = d+L[i-1];
        if(d <= X) cnt++;
    }
    cout << cnt << endl;
}

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

int main(int argc, char *argv[]) {
  int A, B, K;
  scanf("%d %d %d", &A, &B, &K);

  for (int k = 0; k < K; k++) {
    int dA = 0, dB = 0;
    if (k % 2 == 0) {
      if (A % 2 == 1)
        A--;
      dA -= A / 2;
      dB += A / 2;
    } else {
      if (B % 2 == 1)
        B--;
      dA += B / 2;
      dB -= B / 2;
    }
    A += dA;
    B += dB;
  }
  printf("%d %d\n", A, B);
  
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  string t;
  cin>>s>>t;
  int cnt=0;
  for(int i=0;i<(int)s.size();i++)
  {
    if(s[i]!=t[i])cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3916
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <limits>
#include <iomanip>

using namespace std;
long long point[3000][3000];
int N;
int a[3000];

long long rec(int left, int right){
   int turn = (N-(right-left+1))%2;
   if(left > right) return 0;
   if(point[left][right]!=LLONG_MAX) return point[left][right];
   if(turn == 0 ){
      point[left][right] = max(a[left] + rec(left+1, right), a[right]+rec(left,right-1));
   }
   else{
      point[left][right] = min(-a[left] + rec(left+1, right), -a[right]+rec(left,right-1));
   }
   return point[left][right];
}

int main(){
  cin >> N;
  for(int i = 0 ; i <N; i++) cin >> a[i];
  for(int i = 0 ; i < 3000; i++){
     for(int j = 0 ; j < 3000; j++){
        point[i][j] = LLONG_MAX;
     }
  }
  cout << rec(0, N-1) << endl;
  return 0;
}


Measured memory_bytes: 70656
package main

import "fmt"

func main()  {
	var n int
	fmt.Scan(&n)
	dishes := ScanNums(n)
	satisfactions := ScanNums(n)
	extraSatisfactions := ScanNums(n-1)
	totalSatisfaction := 0
	lastDishIndex := -1
	for i := 0; i < n; i++ {
		dishIndex := dishes[i]-1
		totalSatisfaction += satisfactions[dishIndex]
		if lastDishIndex >= 0 && lastDishIndex+1 == dishIndex {
			totalSatisfaction += extraSatisfactions[dishIndex-1]
		}
		lastDishIndex = dishIndex
	}
	fmt.Println(totalSatisfaction)
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, c;cin >> a >> b >> c;
    string ans = "YES";
    if(a*b*c != 5*5*7){
        ans = "NO";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,a[200200];
ll L[200200],R[200200];

int main()
{
    n=read();
    rep(i,0,n) a[i]=read();
    if (a[0])
    {
        if ((n==0) && (a[0]==1)) puts("1");
        else puts("-1");
        return 0;
    }
    per(i,n,0)
    {
        L[i]=a[i]+(L[i+1]+1)/2;
        R[i]=a[i]+R[i+1];
    }
    //cout << L[0] << " " << R[0] << endl;
    if (L[0]>1) {puts("-1");return 0;}
    ll ans=1,now=1;
    //rep(i,1,n) cout << R[i] << " ";cout << endl;
    rep(i,1,n)
    {
        now=min(now*2,R[i]);
        ans+=now;
        now-=a[i];
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 5688
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;

int main(){
    ll a,b,c,d;
    ll ma,mi;
    cin>>a>>b>>c>>d;
    
    cout<<max({a*c,a*d,b*c,b*d});
    return 0;
}

Measured memory_bytes: 3644
from bisect import bisect_left


def solve(m):
    r = N - 1
    l = 0
    cnt = 0
    while 0 <= r and l < N:
        if A[r] + A[l] < m:
            l += 1
        else:
            cnt += N - l
            r -= 1
    return cnt


N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + A[i]

# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = 0
ng = 10 ** 21
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    cnt = solve(mid)
    if cnt >= M:
        ok = mid
    else:
        ng = mid

X = ok
amari = float('inf')
cnt = 0
score = 0
for i, Ai in enumerate(A):
    Aj = X - Ai
    j = bisect_left(A, Aj)
    score += S[N] - S[j] + Ai * (N - j)
    cnt += N - j
    if j < N:
        amari = min(amari, A[i] + A[j])

print(score - (cnt - M) * amari)


Measured memory_bytes: 54936
function Main(input){
  const N = parseInt(input);
  var a = [];
  if (N == 3) {
    a = [2,3,25];
  } else {
    for (var i = 0; i < 30000/12; i++) {
      for(var j of [2,4,3,9,8,10,6,12]){
        a.push(i*12 + j);
      }
    }
    a.splice(N, a.length - N);
    if (N % 2 == 1) {
      a[N-1] = 30000;
    }
  }

  console.log(a.join(" "));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 13420
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int T,h,m,s;
    scanf("%d",&T);
    h = T / 3600;
    T = T % 3600;
    m = T / 60;
    T = T % 60;
    s = T;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



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

#define pb push_back
#define all(a) (a).begin(), (a).end()

using ll = long long;
using pii = pair<ll, ll>;

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
	os << "{";
	for (int i = 0; i < v.size(); ++i) {
		if (i)
			os << ", ";
		os << v[i];
	}
	os << "}";
	return os;
}

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    ll n, x, d; cin >> n >> x >> d;
    if (d == 0) {
    	if (x == 0)
    		cout << 1 << "\n";
    	else
    		cout << n + 1 << "\n";
    	return 0;
    }
    if (d < 0) {
    	x *= -1;
    	d *= -1;
    }
    // kth term: x + (k-1)*d
    map<int, vector<pii>> mp;
    for (ll k = 0; k <= n; ++k) {
    	// pick k terms: k*x + I*d
    	ll st = k * x;
    	// 0+1+...+(k-1)
    	ll lb = k * (k - 1) / 2;
    	// (n-1)+(n-2)+...+(n-k)
    	ll ub = (n - 1 + n - k) * k / 2;
    	mp[st % d].pb({st / d + lb, st / d + ub});
    }
    ll ans = 0;
    for (auto &e : mp) {
    	vector<pii> &v  = e.second;
    	sort(all(v));
    	// cout << v << "\n";
    	ll l = 0, r = 0;
    	int f = 0;
    	for (auto &x : v) {
    		if (!f) {
    			f = 1;
    			l = x.first;
    			r = x.second;
    		}
    		else {
    			if (x.first <= r) 
    				r = max((ll)r, x.second);
    			else {
    				ans += (r - l + 1);
    				l = x.first;
    				r = x.second;
    			}
    		}
    	}
    	ans += (r - l + 1);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 22144
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int Q=303;
const int MOD=998244353;
int f[2][Q*Q];
int g[Q*Q];
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int sub(int a,int b)
{a-=b;return a<0?a+MOD:a;}
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline void Add(int &a,int b)
{a+=b;a>=MOD?a-=MOD:1;}
int main()
{
    int sm=0,n;
    f[0][0]=1;
    int now=0,lst=1;
    scanf("%d",&n);
    g[0]=1;
    for(int i=1,val;i<=n;i++){
        now^=1,lst^=1;
        scanf("%d",&val);
        for(int j=0;j<=sm;j++)
            f[now][j]=mul(2,f[lst][j]);
        for(int j=sm+1;j<=sm+val;j++)f[now][j]=0;
        for(int j=0;j<=sm;j++)
            Add(f[now][j+val],f[lst][j]);
        sm+=val;
        for(int j=sm-val;j>=0;--j)
            Add(g[j+val],g[j]);
    }
    int als=1;
    for(int i=1;i<=n;i++)als=mul(als,3);
    for(int i=(sm+1)/2;i<=sm;i++)
        als=sub(als,mul(3,f[now][i]));
    if(sm%2==0)als=add(als,mul(3,g[sm/2]));
    printf("%d",als);
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

const int SIZE = (1<<15)+1;

int main() {
    bool *is_prime = new bool[SIZE];
    fill(is_prime, is_prime+SIZE, 1);
    is_prime[0] = is_prime[1] = false;

    vector<int> primes;
    for(int i = 2; i < SIZE; ++i) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int j = i*i; j < SIZE; j += i) is_prime[j] = false;
        }
    }

    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        int cnt = 0;
        for(int i = 0; i < primes.size(); ++i) {
            if(primes[i] > N/2) break;
            if(is_prime[N-primes[i]]) ++cnt;
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 0
def inp():
  return sorted([list(map(float, input().split())) for _ in range(8)], key=lambda x:x[1])
lst1 = inp()
lst2 = inp()
lst3 = inp()
rest = lst1[2:] + lst2[2:] + lst3[2:]
rest.sort(key=lambda x:x[1])
select = lst1[:2] + lst2[:2] + lst3[:2] + rest[:2]
for p, t in select:
  print(int(p), t)


Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define pii pair<int,int>
#define MOD 1000000007

void solve(){
    ll n; cin>>n;
    ll cnt = 0;
    for(ll i = 1; i<n; i++){
        cnt+=(n-1)/i;
    }
    cout<<cnt<<endl;
}
int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; 
    // cin>>t;
    while(t-->0){
        solve();
    }
    return 0;
}


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

int main(){
    int n, k, first;
    cin >> n >> k >> first;
    vector<int> a(n-1);
    rep(i,n-1) cin >> a[i];
    ll ans = 1e18;
    rep(i,1<<(n-1)){
        vector<int> b(n-1);
        b = a;
        ll sum = 0;
        if(__builtin_popcount(i)!=k-1) continue;
        int temp = first;
        rep(j,n){
            if(i>>j & 1){
                if(temp >= b[j]){
                    sum += temp - b[j] + 1;
                    b[j] = temp + 1;
                }
                temp = b[j];
            }
            temp = max(b[j], temp);
            
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

signed main(){
    char c; cin >> c;
    if('A' <= c && c <= 'Z'){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }
}

Measured memory_bytes: 3632
let s = read_line () |> Bytes.of_string
let k = Scanf.sscanf (read_line ()) "%d" @@ fun k -> k

let s_len = Bytes.length s - 1
let a_code = int_of_char 'a'
let z_code = int_of_char 'z'

let rec loop pos res =
  let chr_code = int_of_char (Bytes.get s pos) in
  if pos = s_len then begin
    let chr = char_of_int (a_code + (chr_code - a_code + res) mod 26) in
    Bytes.set s s_len chr;
    print_endline @@ Bytes.to_string s
  end else if chr_code = a_code then loop (pos + 1) res
  else begin
    let t = z_code - chr_code + 1 in
    (* Printf.printf "%d\n" t; *)
    if t <= res then begin
      Bytes.set s pos 'a';
      loop (pos + 1) (res - t)
    end else loop (pos + 1) res
  end

let () = loop 0 k

Measured memory_bytes: 2944
n,a,b = map(int,input().split())

mod = 10**9+7

m = 10**5 * 2 +10 
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

comba = 1
for i in range(n,n-a,-1):
    comba *= i
    comba %= mod
comba *= finv[a]
comba %= mod

combb = 1
for i in range(n,n-b,-1):
    combb *= i
    combb %= mod
combb *= finv[b]
combb %= mod

ans = pow(2,n,mod) - comba - combb - 1
ans %= mod
print(ans)

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

signed main() {
  int N;
  cin >> N;
  vector<int> a(N);

  bool flag = false;

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      flag = true;
    }
  }

  if (flag == false) {
    cout << -1 << endl;
    return 0;
  }

  int now = 1, ans = 0;
  for (int i = 0; i < N; i++) {
    if (now == a[i]) {
      now++;
    } else {
      ans++;
    }
  }

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

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

int main() {
    ll a,b;
    std::cin >> a>>b;
    ll tmp;
    ll x = a*b;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
  }
    ll r; 
      /* ユークリッドの互除法 */
      r = a % b;
      while(r!=0){
        a = b;
        b = r;
        r = a % b;
      }
      
     std::cout << x/b << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner scan =new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		
		if((a==b+c)||(b==a+c)||(c==a+b)) System.out.println("Yes");
		else System.out.println("No");
		
	}
	
}

Measured memory_bytes: 22736
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<LL> A(N);
	REP(i, N) cin >> A[i];

	vector<vector<LL>> dp(3, vector<LL>(N, 0));
	dp[0][0] = A[0];

	FOR(i, 1, N){
		dp[0][i] = dp[0][i - 1];
		if(!(i & 1) && i != N - 1){
			dp[0][i] += A[i];
		}
		dp[1][i] = dp[1][i - 1];
		if(i & 1){
			dp[1][i] += A[i];
			if(3 <= i) dp[1][i] = max(dp[0][i - 3] + A[i], dp[1][i]);
		}
		dp[2][i] = dp[2][i - 1];
		if(!(i & 1)){
			dp[2][i] += A[i];
			if(3 <= i) dp[2][i] = max(dp[1][i - 3] + A[i], dp[2][i]);
			if(4 <= i) dp[2][i] = max(dp[0][i - 4] + A[i], dp[2][i]);
		}
		// cerr << i << " : " << dp[0][i] << " " << dp[1][i] << " " << dp[2][i] << endl;
	}

	if(N % 2){
		cout << max({dp[0].back(), dp[1].back(), dp[2].back()}) << endl;
	}
	else{
		cout << max({dp[0].back(), dp[1].back()}) << endl;
	}

	return 0;
}


Measured memory_bytes: 11116
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=2000010;
const LL mod=1e9+7;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int x[7],y[7],X,Y;
LL fac[N],ifac[N],ans;
inline LL qpow(LL a,LL b)
{
	LL ret=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1)ret=ret*a%mod;
	return ret;
}
inline void init(int n)
{
	fac[0]=ifac[0]=1;
	For(i,1,n)fac[i]=fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	rFor(i,n,2)ifac[i-1]=ifac[i]*i%mod;
}
inline LL C(int a,int b){return fac[a+b]*ifac[a]%mod*ifac[b]%mod;}
inline LL C(int a,int b,int c,int d){return (C(c+1,d+1)+mod-C(a,d+1)+mod-C(c+1,b)+C(a,b))%mod;}
int main()
{
	For(i,1,6)read(x[i]);
	For(i,1,6)read(y[i]);
	init(2000005);
	For(i,x[3],x[4])
	{
		X=i,Y=y[3]-1;
		ans=(ans+mod-(X+Y+1)*C(X-x[2],Y-y[2],X-x[1],Y-y[1])%mod*C(x[5]-X,y[5]-Y-1,x[6]-X,y[6]-Y-1)%mod)%mod;
		X=i,Y=y[4];
		ans=(ans+(X+Y+1)*C(X-x[2],Y-y[2],X-x[1],Y-y[1])%mod*C(x[5]-X,y[5]-Y-1,x[6]-X,y[6]-Y-1)%mod)%mod;
	}
	For(i,y[3],y[4])
	{
		X=x[3]-1,Y=i;
		ans=(ans+mod-(X+1+Y)*C(X-x[2],Y-y[2],X-x[1],Y-y[1])%mod*C(x[5]-X-1,y[5]-Y,x[6]-X-1,y[6]-Y)%mod)%mod;
		X=x[4],Y=i;
		ans=(ans+(X+Y+1)*C(X-x[2],Y-y[2],X-x[1],Y-y[1])%mod*C(x[5]-X-1,y[5]-Y,x[6]-X-1,y[6]-Y)%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 31488
#include<iostream>
using namespace std;
int F[30];
int N;
int main()
{
    F[0]=1;
    F[1]=F[0];
    F[2]=F[1]+F[0];
    for(int i=3;i<=30;i++)
    {
        F[i]=F[i-1]+F[i-2]+F[i-3];
    }
    while(cin>>N&&N)
    {
        cout<<((F[N]+9)/10+364)/365<<endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
double w[100010],tmp[100010];int go[100010],tmm[100010];
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lf",&w[i]);double p=w[1];
	for (int i=1;i<n;i++) {w[i]=w[i+1]-w[i];go[i]=i;}
	int m;long long k;scanf("%d%lld",&m,&k);
	for (int i=1;i<=m;i++) {int r;scanf("%d",&r);swap(go[r],go[r-1]);}
	while (k)
	{
		if (k&1)
		{
			for (int i=1;i<n;i++) tmp[i]=w[go[i]];
			for (int i=1;i<n;i++) w[i]=tmp[i];
		}
		for (int i=1;i<n;i++) tmm[i]=go[go[i]];
		for (int i=1;i<n;i++) go[i]=tmm[i];
		k>>=1;
	}
	for (int i=1;i<=n;i++)
	{
		printf("%.10lf\n",p);
		p+=w[i];
	}
}

Measured memory_bytes: 4736
#include<iostream>

using namespace std;

const int INF=1e8;

int a[100];

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=INF;
	for(int i=-100;i<=100;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			int t=a[j]-i;
			sum+=t*t;
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
(* 与えられたリストからk要素を選ぶ順列 *)
let perm k xs =
  let rec perm_aux trace n k i xs ys acc =
    match k, i, xs with
    | 0, _, _ -> trace :: acc
    | _, 0, _ -> acc
    | _, _, [] -> perm_aux trace n k i (List.rev ys) [] acc
    | _, _, x :: xs ->
        perm_aux trace n k (i - 1) xs (x :: ys) @@
        perm_aux (x :: trace) (n - 1) (k - 1) (n - 1) xs ys acc in
  let n = List.length xs in
  perm_aux [] n k n xs [] []

let () = Scanf.scanf "%d %d\n" @@ fun n c ->
  let dss =
    Array.init c @@ fun _ ->
      Array.init c @@ fun _ ->
        Scanf.scanf "%d " @@ fun d -> d in
  let css =
    Array.init n @@ fun _ ->
      Array.init n @@ fun _ ->
        Scanf.scanf "%d " @@ fun c -> c in
  let colours = Array.make_matrix 3 c 0 in
  Array.iteri (fun i ->
    Array.iteri (fun j c ->
      colours.((i + j + 2) mod 3).(c - 1) <- colours.((i + j + 2) mod 3).(c - 1) + 1)) css;
  Array.init c (fun c -> c)
  |> Array.to_list
  |> perm 3
  |> List.map (List.mapi (fun m y ->
      Array.mapi (fun x n -> n * dss.(x).(y)) colours.(m)
      |> Array.fold_left ( + ) 0))
  |> List.map (List.fold_left ( + ) 0)
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"



Measured memory_bytes: 7552
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        s: u64
    }
    print!("{}", (s-1)*s/2);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

ll D, T ,S;


int main(void){

    cin >> D >> T >> S;


    ll ans =  T * S;

    if (ans >= D) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> vec){
	if(vec[0] != vec[1])return false;
	if(vec[0] != vec[2])return false;
	if(vec[1] != vec[2])return false;
	return true;
}
int main(){
	int a, b, c;
	cin>>a>>b>>c;
	vector<int> vec(3, 0);
	vec[0] = a;
	vec[1] = b;
	vec[2] = c;
	sort(vec.begin(), vec.end());
	int res = 0;
	while(!check(vec)){
		if(abs(vec[0] - vec[2]) == 1 && abs(vec[2] - vec[1]) == 1){
			vec[0]++;
			vec[1]++;
			res++;
		}
		else if(abs(vec[2] - vec[0]) == 1 && abs(vec[2] - vec[1]) == 0){
			vec[0] += 2;
			vec[1]++;
			vec[2]++;
			res += 2;
		}
		else{
			int r = abs(vec[0] - vec[2]);
			res += (r / 2);
			vec[0] += (r / 2) * 2;		
		}
		sort(vec.begin(), vec.end());
	}
	//cout<<vec[0]<<" "<<vec[1]<<" "<<vec[2]<<" "<<endl;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	l := 0
	for i, c := range s {
		if c == 'A' {
			l = i
			break
		}
	}
	r := len(s) - 1
	for i := len(s) - 1; i >= 0; i-- {
		if s[i] == 'Z' {
			r = i
			break
		}
	}
	fmt.Println(r - l + 1)
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

double dist(double x1,double y1,double x2,double y2)
{
    double ans=0;
    ans+=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    ans=sqrt(ans);
    return ans;
}

int main(void)
{
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    printf("%lf\n",dist(a,b,c,d));
    return 0;
}


Measured memory_bytes: 3212
#include <stdio.h>
int main(void){
    // int t = 5;
    // printf("%d\n", (int)(t*0.08));
    int a, b;
    scanf("%d %d", &a, &b); // 1 <= a <= b <= 100
    for(int i = b*10; i <= (b+1)*10; i++){
        if((int)(i*0.08) == a && (int)(i*0.1) == b){
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 128
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def gcd(a,b):
    return a if b== 0 else gcd(b, a%b)

def solve():
    n,start =f()
    x = f()
    x.append(start)

    x = sorted(x)

    g = 0
    for i in range(1,n+1):
        g = gcd(g, x[i] - x[i-1])

    print(g)





solve()


Measured memory_bytes: 14480
#include <iostream>
#include <set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int64_t cnvS(string& S) {
  int n = S.size();
  int64_t ret = 0;
  bool count = false;
  int times = 9;
  rep(i, n) {
    if (count) --times;
    if (S[i] == '.')
      count = true;
    else
      ret = ret * 10 + (S[i] - '0');
  }
  rep(i, times) ret *= 10;
  // cout << S << "->" << ret << endl;
  return ret;
}

int cntN(int64_t n, int m) {
  int ret = 0;
  while (n % m == 0) {
    ret++;
    n /= m;
  }
  return ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> num2(N);
  vector<int> num5(N);
  vector<vector<int>> tbl25(19, vector<int>(19, 0));
  rep(i, N) {
    string S;
    cin >> S;
    int64_t A = cnvS(S);
    num2[i] = min(18, cntN(A, 2));
    num5[i] = min(18, cntN(A, 5));
    tbl25[num2[i]][num5[i]]++;
  }
  vector<vector<int>> sum(20, vector<int>(19, 0));
  rep(i, 19) {
    rep(j, 19) {
      sum[i + 1][j + 1] =
          sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + tbl25[i][j];
    }
  }

  // need 1e18 = 2 & 5 >= 18
  int64_t answer = 0;
  rep(i, N) {
    int need2 = 18 - num2[i];
    int need5 = 18 - num5[i];
    answer += sum[19][19] - sum[need2][19] - sum[19][need5] + sum[need2][need5];
    if (9 <= num2[i] && 9 <= num5[i]) answer--;  // subtract for own
  }
  cout << answer / 2 << endl;
  return 0;
}

Measured memory_bytes: 4828
#include <bits/stdc++.h>
        
using namespace std;
        
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
        
#define print(a) {for(auto xxxxx : (a)) cout << xxxxx << ' '; cout << '\n';}
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
        
ll next(){ll x; cin >> x; return x;}
const int maxn = 1e3 + 5, intf = 2e9;
const ll inf = 1e18, mod = 998244353;
const ld eps = 1e-6;

bool check(int mask , int j){
	return ((mask >> j) & 1);
}

void solve(){
	int n , m , x;
	cin >> n >> m >> x;
	vector < vector <int> > a(n , vector <int> (m));
	vector <int> c(n);
	for (int i = 0; i < n; i ++){
		cin >> c[i];
		for (int j = 0; j < m; j ++){
			cin >> a[i][j];
		}
	}

	int ans = intf;
	for (int i = 0; i < (1 << n); i ++){
		int cost = 0;
		vector <int> cur(m , 0); 
		for (int j = 0; j < n; j ++){
			if (check(i , j)){
				cost += c[j];
				for (int k = 0; k < m; k ++){
					cur[k] += a[j][k];
				}
			}
		}

		for (auto t : cur){
			if (t < x)
				cost = intf;
		}

		ans = min(ans , cost);
	}

	if (ans == intf)
		ans = -1;

	cout << ans << '\n';
}
    
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(20);
            
    for (int t = 1; t--;) {
        solve();
    }
        
    return 0;
}
/*
        
        
*/

Measured memory_bytes: 3604
#027A
N,x=map(int,input().split())
children=list(map(int,input().split()))
children.sort()
fun=0 if x!=sum(children) else N
if fun==0:
    for i in range(N):
        x-=children[i]
        if x>=0:fun+=1
        else: break
    if fun==N:fun-=1
print(fun)

Measured memory_bytes: 3060
import math
a,b,c = map(float, input().split())
cc = math.radians(c)
h = b * math.sin(cc)
S = a * h / 2
L = a + b + math.sqrt(h**2 + (a-b*math.cos(cc))**2)
print("{0:.10f}\n{1:.10f}\n{2:.10f}\n".format(S, L, h))

Measured memory_bytes: 7812
import sys

s = input()
for i in range(len(s)):
    if ((i+1) % 2 == 1):
        if (s[i] == 'L'):
            print("No")
            sys.exit()
    elif ((i+1) % 2 == 0):
        if (s[i] == 'R'):
            print("No")
            sys.exit()
print("Yes")

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

int main() {
  int K, X;
  cin >> K >> X;
  if (X-K+1 < -1000000) {
    for (int i = 0; i < 2*K-1; i++) {
      cout << (-1000000 + i) << " ";
    }
  }
  else if (X+K-1 > 1000000) {
    for (int i = 0; i < 2*K-1; i++) {
      cout << (1000000 - (2*K-2) + i) << " ";
    }
  }
  else {
    for (int i = 0; i < 2*K-1; i++) {
      cout << (X-K+1) +i << " ";
    }
  }
  
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, int.Parse);
        var a = new List<int>();
        a.Add(0); a.AddRange(b); a.Add(0);
        var c = a.ToArray();
        var t = 0L;
        for (int i = 0; i <= n; i++)
            t += Math.Abs(c[i] - c[i + 1]);
        for (int i = 1; i <= n; i++)
        {
            var ret = t - Math.Abs(c[i - 1] - c[i]) - Math.Abs(c[i] - c[i + 1]) + Math.Abs(c[i - 1] - c[i + 1]);
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 28508
def solve():
    A, B, M = [int(x) for x in input().split(" ")]
    Ai = [int(x) for x in input().split(" ")]
    Bi = [int(x) for x in input().split(" ")]

    min_val = min(Ai) + min(Bi)

    for _ in range(M):
        x, y, c = input().split(" ")
        x = int(x) - 1
        y = int(y) - 1
        c = int(c)
        min_val = min(Ai[x] + Bi[y] - c, min_val)
    print(min_val)


solve()


Measured memory_bytes: 66648
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("test.in");ofstream coutt("test.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Use __builtin_popcountll for ll;
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int n;cin>>n;
    cout<<ceil(n,2);
}



Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void B();

int main()
{
	B();
	fflush(stdout);
	return 0;
}

static void B()
{
	int N, K;
	getint(N, K);

	std::vector<int> ai(N);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
	}
	std::sort(ai.begin(), ai.end());

	int sum = 0;
	for (int k = 0; k < K; k++) {
		sum += ai[k];
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 3728
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

vector<int> z_function(string s){
    int n = (int)s.length();
    vector<int> z(n, 0);
    for(int i = 1, l = 0, r = 0;i < n;i++){
        if(i <= r)
            z[i] = min(r - i + 1, z[i - l]);
        while(i + z[i] < n and s[z[i]] == s[i + z[i]])
            ++z[i];
        if(i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

vector<int> Z, Z1;
string w;

vector<bool> solve(vector<int> z){
    int n = (int)z.size();
    vector<bool> G(n);
    for(int i = 1;i <= n;i++){
        G[i - 1] = true;
    }
    for(int p = 1;p < n;p++){
        if(!G[p - 1]) continue;
        for(int k = 2;(k - 1) * p <= z[p];k++){
            G[k * p - 1] = false;
        }
    }
    return G;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> w;
    int n = w.length();
    bool flag = true;
    for(int i = 0;i < n;i++){
        if(w[i] != w[0]){
            flag = false;
        } 
    }
    if(flag){
        cout << n << endl;
        cout << 1 << endl;
    }else{
        Z = z_function(w);
        reverse(w.begin(), w.end());
        Z1 = z_function(w);
        vector<bool> G = solve(Z);
        vector<bool> G1 = solve(Z1);
        if(G[n - 1]){
            cout << 1 << endl;
            cout << 1 << endl;
            return 0;
        }else{
            cout << 2 << endl;
            int cnt = 0;
            for(int i = 1;i <= n;i++){
                if(G[i - 1] and G1[n - i - 1]){
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7092
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		int q, order_num, i, j, n = 0, counter;
		boolean[] flag = new boolean[64];
		try (Scanner sc = new Scanner(System.in)) {
			q = sc.nextInt();
			for(j = 0; j < q; j++) {
				order_num = sc.nextInt();
				if(order_num <= 3) {
					n = sc.nextInt();
				}
				switch(order_num) {
				case 0 : System.out.println(flag[n] ? "1" : "0"); break;
				case 1 : flag[n] = true; break;
				case 2 : flag[n] = false; break;
				case 3 : flag[n] = !flag[n]; break;
				case 4 :
					counter = 1;
					for(i = 0; i < 64; i++) {
						if(flag[i] != true) {
							counter = 0;
							break;
						}
					}
					System.out.println(counter); break;
				case 5 :
					counter = 0;
					for(i = 0; i < 64; i++) {
						if(flag[i] != false) {
							counter = 1;
							break;
						}
					}
					System.out.println(counter); break;
				case 6 :
					counter = 1;
					for(i = 0; i < 64; i++) {
						if(flag[i] == true) {
							counter = 0;
							break;
						}
					}
					System.out.println(counter); break;
				case 7 :
					counter = 0;
					for(i = 0; i < 64; i++) {
						if(flag[i] == true) {
							counter++;
						}
					}
					System.out.println(counter); break;
				case 8 :
					BigDecimal sum = new BigDecimal("0");
					BigDecimal big = new BigDecimal("2");
					for(i = 0; i < 64; i++) {
						if(flag[i]) {
							sum = sum.add(big.pow(i));
						}
					}
					System.out.println(sum);
				}
			}
		}
	}
}



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

using namespace std;

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

	int n;
	long long int d,x,y;
	int res = 0;

	cin >> n >> d;

	for(int i=0;i<n;i++)
	{
		cin >> x >> y;
		long long int d1 = x*x + y*y;
		if(d1<=d*d)
		{
			res++;
		}
	}

	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;


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

  long long a[N] = {};

  long long result = 0;;
  for(int i=0;i<N;i++){
    cin >> a[i];
    result += (a[i] - 1);
  }

  cout << result << endl;
  return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int d[200000];
P p[200000];
vector<int>E[200000];
int col[200000];
int A[200000],B[200000];

int main(){
	int n,m;cin>>n>>m;
	rep(i,n){
		scanf("%d",&d[i]);
		p[i].first=d[i];
		p[i].second=i;
	}
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
		A[i]=a;B[i]=b;
	}
	sort(p,p+n);
	memset(col,-1,sizeof(col));
	rep(x,n){
		int i=p[x].second;
		if(col[i]!=-1)continue;
		bool ok=false;
		for(int u:E[i]){
			if(d[u]<=d[i])ok=true;
		}
		if(!ok){
			puts("-1");return 0;
		}
		col[i]=0;
		for(int u:E[i]){
			if(d[u]<=d[i])col[u]=1;
		}
		queue<int>que;
		que.push(i);
		while(!que.empty()){
			int s=que.front();que.pop();
			for(int u:E[s]){
				if(d[u]>=d[s]&&col[u]==-1){
					col[u]=!col[s];
					que.push(u);
				}
			}
		}
	}
	rep(i,n){
		if(col[i])cout<<"W";
		else cout<<"B";
	}
	cout<<endl;
	rep(i,m){
		printf("%d\n",max(d[A[i]],d[B[i]]));
	}
}

Measured memory_bytes: 14592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

string s;

int main() {
	cin >> s;
	int pos[] = { 0,  s.size() };
	REP(i, s.size()) {
		if (s[i] == 'A') {
			pos[0] = i - 1;
			break;
		}
	}
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'Z') {
			pos[1] = i;
			break;
		}
	}
	cout << pos[1] - pos[0] << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, s;
};

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

	vector<pii> q(m), jun(m);

	vector<int> en[100001];

	REP(i, m) {
		int a, b;
		scnaf("%d %d", &a, &b);
		a--, b--;
		q[i] = {a,b};
		jun[i] = { b,i };
		en[a].push_back(i);
	}
	set<int> al;
	int bef = 0;
	int cou = 0;
	sort(ALL(jun));
	REP(i, m) {
		if (!al.count(jun[i].second)) {
			cou++;
			rep(j, bef, jun[i].first) {
				for (auto itr : en[j]) {
					al.insert(itr);
				}
			}
			bef = jun[i].first;
		}
	}
	cout << cou << endl;
	return 0;
}


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

#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(int i=a ; i<=b ; i++)
#define FORD(i,a,b) for(int i=a ; i>=b ; i--)
#define INF 1000000000
#define ll long long int
#define eps (1e-8)
#define sq(x) ( (x)*(x) )
#define all(x) x.begin(),x.end()
#define flog2(n) 64 - __builtin_clzll(n) - 1
#define popcnt(n) __builtin_popcountll(n)

using namespace std;

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

const int MAXN = 100005;

vector<int> v[MAXN];
const ll K = 1e9 + 7;

ll d[MAXN][2];

void dfs(int a, int p) {

	for (auto i: v[a]) {
		if (i == p) continue;
		dfs(i, a);
	}
	
	d[a][0] = d[a][1] = 1;

	for (auto i: v[a]) {
		if (i == p) continue;
		d[a][0] = d[a][0] * (d[i][0] + d[i][1]) % K;
		d[a][1] = d[a][1] * d[i][0] % K; 
	}
}


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

    int n;
    cin >> n;
    FOR (i, 1, n - 1) {
    	int x, y;
    	cin >> x >> y;
    	v[x].pb(y);
    	v[y].pb(x);
    }

    dfs(1, 0);

    cout << (d[1][0] + d[1][1]) % K << endl;

    return 0;
}

Measured memory_bytes: 14208
def main():
  n = int(input())
  a = list(map(int, input().split()))
  
  a.sort()
  
  border = []
  
  key = 2
  for i in range(n):
    while key <= a[i]:
      border.append(i)
      key *= 2
  
  border.append(n)
  border.reverse()
  
  ans = 0
  already = [False]*n
  for v in border:
    index = 0
    for i in range(v-1, -1, -1):
      if already[i]:
        continue
      while index < i and (a[i]+a[index] < key or already[index]):
        index += 1
      if index == i:
        break
      if a[i]+a[index] == key:
        already[i] = True
        already[index] = True
        ans += 1
    
    key //= 2
  
  print(ans)
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 30692
count = 0
N = gets.to_i
a = gets.split.map(&:to_i)
(N - 1).times { |i|
if a[i] == a[i + 1]
  if a[i + 1] == a[i + 2] || a[i + 1] + 1 != a[i + 2]
    a[i + 1] = a[i] + 1
    count += 1
  else
    a[i + 1] = a[i] + 2
    count += 1
  end
end
  }

puts count

Measured memory_bytes: 3836
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var nexts = new[] { "01", "012", "123", "234", "345", "456", "567", "678", "789", "89" };
		var k = int.Parse(Console.ReadLine());
		if (k <= 9) { Console.WriteLine(k); return; }

		var t = 9;
		var q = new Queue<string>(Enumerable.Range(1, 9).Select(i => $"{i}"));

		while (q.TryDequeue(out var s))
		{
			foreach (var c in nexts[s[^1] - '0'])
			{
				q.Enqueue(s + c);
				if (++t == k) { Console.WriteLine(s + c); return; }
			}
		}
	}
}


Measured memory_bytes: 35944
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,M;
	cin >> N >> M;
	vector<bool> vec(M);
	vector<bool> cnt(M);
	for(int i = 0;i < N;i++) {
		int A;
		cin >> A;
		for(int j = 0;j < A;j++) {
			int B;
			cin >> B;
			cnt.at(B - 1) = true;
		}
		for(int j = 0;j < M;j++) {
			if(cnt.at(j) == false) {
				vec.at(j) = true;
			}
		}
		for(int j = 0;j < M;j++) {
			cnt.at(j) = false;
		}
	}
	int ret = 0;
	for(int i = 0;i < M;i++) {
		if(vec.at(i) == false) {
			ret++;
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 256
s=input()
k=int(input())
c=1
b=[]
l=1
r=0
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    b.append(c)
    l=0
    c=1
if s[0]==s[-1]:
  b.append(c)
  c+=b[0]
else:
  b.append(c)
  c=0
if l==1:
  print((len(s)*k)//2)
else:
  if s[0]==s[-1]:
    if len(b)>=2:
      for i in range(len(b)-2):
        r+=(b[i+1]//2)*k
    print(r+b[0]//2+b[-1]//2+(c//2)*(k-1))
  else:
    for i in range(len(b)):
      r+=((b[i]//2)*k)
    print(r)

Measured memory_bytes: 3064