akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
int in(){int x;scanf("%d",&x);return x;}
ll lin(){ll x;scanf("%lld",&x);return x;} 
const int b=8;
VI e[100];
int par[100][b], depth[100], id[100];
int cnt;
void dfs(int now,int past){
    REP(i,e[now].size()){
        int next=e[now][i];
        if (next==past) continue;
        id[next]=cnt++;
        par[next][0]=now;
        depth[next]=depth[now]+1;
        dfs(next,now);
    }
}
int lca(int x,int y){
    if (depth[y]>depth[x]) swap(x,y);
    int d=depth[x]-depth[y];
    REP(i,b){
        if ((d>>i)&1){
            x=par[x][i];
        }
    }
    if (x==y) return x;
    FORR(i,b-1,0){
        if (par[x][i]!=par[y][i]){
            x=par[x][i];
            y=par[y][i];
        }
    }
    return par[x][0];
}
int main(){
    int n,m;
    cin>>n;
    REP(i,n-1){
    	int u=in()-1,v=in()-1;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(0,-1);
    FOR(i,1,b-1){
        REP(j,n){
            par[j][i]=par[par[j][i-1]][i-1];
        }
    }
    cin>>m;
    VI u(m),v(m);
    VVI path(m,VI(n-1));
    REP(i,m){
        u[i]=in()-1,v[i]=in()-1;
        int a=lca(u[i], v[i]);
        int x=u[i];
        while (x!=a){
            path[i][id[x]]=1;
            x=par[x][0];
        }
        x=v[i];
        while (x!=a){
            path[i][id[x]]=1;
            x=par[x][0];
        }
    }
    ll ans=0;
    REP(mask,1<<m){
        int c=0;
        VI ok(n,1);
        REP(i,m){
            if ((mask>>i)&1){
                c++;
                REP(j,n-1) if (path[i][j]) ok[j]=0;
            }
        }
        ll x = 1;
        REP(j,n-1) if (ok[j]) x=2*x;
        if (c%2==0) ans+=x;
        else ans-=x;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

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

int main() {
    int a, b, x, y;
    scanf("%d%d%d%d", &a, &b, &x, &y);
    printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<fstream>
#include<sstream>
#include<vector>
#include<set>
#include<deque>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<set>
#include<stack>
#include<numeric>
#include<map>
#include<cstdio>
#include<bitset>
#include<array>
#include<list>
using namespace std;
#define ll long long 
const ll mod = 1e9 + 7;

ifstream f1;
ofstream f2;

string s;
ll cal[100001][13];

ll solve(ll i = 0, ll last = 0) {
	if (i == s.size()) {
		if (last == 5) {
			return 1;
		}
		return 0;
	}
	if (cal[i][last] > -1) {
		return cal[i][last];
	}
	ll res = 0;
	if (s[i] == '?') {
		for (ll j = 0; j <= 9; j++) {
			res += solve(i + 1, (last * 10 + j) % 13) % mod;
			res %= mod;
		}
	}
	else {
		res += solve(i + 1, (last * 10 + (s[i] - '0')) % 13) % mod;
		res %= mod;
	}
	cal[i][last] = res;
	return cal[i][last];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	f1.open("INP.txt");
	f2.open("OUT.txt");
	cin >> s;
	for (ll i = 0; i < 100001; i++) {
		for (ll j = 0; j < 13; j++) {
			cal[i][j] = -1;
		}
	}
	cout << solve() << '\n';
	//system("pause");
	return 0;
}

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

int n,k,sum=1; 

int main()
{
	cin >> n >> k;
	int a=k;
	while(a <= n)
	{
		a *= k;
		sum++;	
	} 
	cout << sum << endl;
	return 0; 
}


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

using namespace std;
typedef long long ll;

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

  ll sum4 = 0;
  ll sum2 = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    if (a % 4 == 0) {
      sum4++;
    } else if (a % 2 == 0){
      sum2++;
    }
  }

  ll num = N / 2;
  if(num <= sum4 + (sum2/2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func reverseString(s string) string {
	n := len(s)
	bytes := []byte(s)
	for i := 0; i < n/2; i++ {
		bytes[i], bytes[n-1-i] = bytes[n-1-i], bytes[i]
	}
	return string(bytes)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	s := reverseString(next())
	n := len(s)

	// dp[i][j]: 下からi桁目まで見て13で割ったあまりがjとなる数の個数
	dp := make([][13]int, n+1)
	dp[0][0] = 1
	pow := 1
	for i := 0; i < n; i, pow = i+1, (pow*10)%13 {
		if s[i] != '?' {
			x := int(s[i] - '0')
			for j := 0; j < 13; j++ {
				dp[i+1][(j+x*pow)%13] = dp[i][j]
			}
			continue
		}
		for x := 0; x < 10; x++ {
			for j := 0; j < 13; j++ {
				dp[i+1][(j+x*pow)%13] += dp[i][j]
				dp[i+1][(j+x*pow)%13] %= mod
			}
		}
	}

	puts(dp[n][5])
}


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

Measured memory_bytes: 26260
//ALDS1_7_A_RootedTrees.cpp

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const long long INF=2E17;
typedef pair<LL,LL> Pair;
int cnt=0;
const int MAX=100010;
int NIL=-1;
int N,D[MAX];
struct Node{
    int p,l,r;
};

Node T[MAX];

//深さを求める
void setDepth(int u,int p){
    D[u]=p;
    if(T[u].r != NIL){
        setDepth(T[u].r,p);
    }
    if(T[u].l != NIL){
        setDepth(T[u].l,p+1);
    }
}

int main(){
    //初期化
    for(int i=0;i<MAX;i++){
        T[i].p=NIL;
        T[i].l=NIL;
        T[i].r=NIL;
    }
    cin >> N;
    // 入力
    int root;
    for(int i=0;i<N;i++){
        int id;
        cin >> id;
        int cn;
        cin >> cn;
        int prev;
        for(int j=0;j<cn;j++){
            int tmp;
            cin >> tmp;
            T[tmp].p=id;
            if(j==0){
                T[id].l=tmp;
            }else{
                T[prev].r=tmp;
            }
            prev=tmp;
        }
    }

    for(int i=0;i<N;i++){
        if(T[i].p==NIL) root=i;
    }
    setDepth(root,0);

    for(int i=0;i<N;i++){
        cout 
        << "node " << i << ": parent = "<< T[i].p <<
         ", depth = " << D[i] << ", "
        ;
        if(T[i].p==NIL) cout << "root, ";
        else if(T[i].l==NIL) cout << "leaf, ";
        else cout << "internal node, ";
        cout << "[";
        if(T[i].l!=NIL){
            cout << T[i].l;
            int j=T[T[i].l].r;
            while(j!=NIL){
                cout << ", "<< j;
                j=T[j].r ;
            }
            
        }
        cout << "]";
        cout << endl;

    }
    return 0;
}


Measured memory_bytes: 7720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a+b>c+d)
    {
        printf("Left");
    }
    else if(a+b<c+d)
        {
            printf("Right");
        }
        else
        {
            printf("Balanced");
        }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int n;read(n);
    int t=n%10;
    if(t==2||t==4||t==5||t==7||t==9) puts("hon");
    else if(t==0||t==1||t==6||t==8) puts("pon");
    else puts("bon");
    return 0;
}

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

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                sum += d[i] * d[j];
            }
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13396
#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 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;



int main()
{
    int N;
    cin >> N;
    int A[N];
    REP(i,N){
        cin >>A[i];
    }

    sort(A,A+N);
    REP(i,N){
       
            if  ((A[i]==A[i+1])){
                cout << "NO" << endl;
                return 0;
               
                
            
        }
    }
    
    cout <<"YES"<< endl;
}

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

typedef long long ll;
#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(a) (a).begin(), (a).end()
using namespace std;

int main() {
    int N, a[100001];
    cin >> N;
    REP(i, N) cin >> a[i + 1];

    int count = 0;
    int next = 1;
    REP(i, N) {
        if (next == 2) break;
        next = a[next];
        count++;
    }
    if (count == N) cout << -1    << endl;
    else            cout << count << endl;
    return 0;
}

Measured memory_bytes: 768
import math

def equation(A):
    n = len(A)
    for i in range(n):
        j=i
        while A[j][i]==0:
            j+= 1
        A[i], A[j] = A[j], A[i]
        A[i] = [e / A[i][i] for e in A[i]]
        for j in range(n):
            if j==i: continue
            tmp = A[j][i]
            for k in range(n+1):
                A[j][k] -= tmp * A[i][k]
    return

n=input()
for i in range(n):
    A=[]
    seq = map(float, raw_input().split())
    for j in range(3):
        x = seq.pop(0)
        y = seq.pop(0)
        A.append([x, y, 1, -(x**2+y**2)])
    equation(A)

    x0, y0 = -A[0][3]/2, -A[1][3]/2
    r =((x-x0)**2 + (y-y0)**2)**.5
    print "%.3f %.3f %.3f" %(x0, y0, r)

Measured memory_bytes: 4484
#include <stdio.h>
int main(void){
    // Your code here!
int a,b,c,d;

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

if(abs(c-a)<=d || abs(b-a)<=d && abs(c-b)<=d)
{printf("Yes");

}
else
{printf("No");

    
}
return 0;

}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 

const int INF=1e9+5;
using ll=long long;

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	int height[n];
	for(int i = 0; i < n; ++i) {
		cin >> height[i];
	}
	vector<int> dp(n,INF);
	dp[0] = 0; //dp[i] - > min cost to reach stone i
	for(int stone = 0; stone < n; ++stone) {
		for(int x = 1; x <= k; ++x) {
			if(stone + x < n) {
			 dp[stone + x] = min(dp[stone + x], dp[stone] + abs(height[stone]- height[stone + x]));
		}
		}
	}
	printf("%d\n", dp[n-1]);
}

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

int main()
{
  char s[1003];
  int i;
  scanf("%s", s);
 
  i=strlen(s);
  
  if ( s[i-1]=='s' )
  {
    strcat(s,"es");
    printf("%s",s);
    return 0;
  }
   strcat(s,"s");
    printf("%s",s);
  
  return 0;
}

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

using namespace std;
using ll = long long;

long double pi = 3.14159265359;

int main()
{
    int N;cin >> N;
    vector<int> v;
    map<int, int> mp;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        v.push_back(b);
        mp[b] = i;
    }
    int cnt = 0;
    for(auto a : mp){
        v[a.second] = cnt;
        cnt++;
    }
    int ans = 0;
    //for(int i = 0;i < v.size();i++)cout<<v[i]<<endl;
    for(int i = 0;i < N;i++){
        if((v.at(i) % 2) != (i % 2))ans++;
     }
    cout<<ans/2<<endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<double> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    int v = 0;
    for(double i : a) v += i;
    double w = 1.0*v/(4*m);
    int cnt = 0;
    rep(i,n){
        if(a[i] >= w) cnt++;
        else break;
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  
  int n, sum = 0, a;
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> a;
    sum += a - 1;
  }
  cout << sum << endl;

  return 0;
}

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

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i = a ; i >= b; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
#define debug2(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << nl;
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
const int MAXN = 100005;
ll mod=1000000007;


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt;
  tt = 1;
  // cin>>tt;
  while(tt--){
    string s,t;
    cin>>s>>t;
    bool f= 0;
    vector<string> ans;
    if(s.size() < t.size()){
      f = 1;
    }
    else{
      string temp = s;
      rep(i,0,s.size()-t.size()){
        bool ok = true;
        temp = s;
        rep(j,i,i + t.size() - 1){
          if(s[j] == t[j - i]){
              // do nothing
          }
          else{
            if(s[j] == '?'){
                temp[j] = t[j - i];
            }
            else{
              ok = false;
              break;
            }
          }
        }
        if(ok){
          rep(i,0,temp.size()-1){
            if(temp[i]=='?'){
              temp[i] = 'a';
            }
          }
          ans.push_back(temp);
        }
      }
    }
    if(!f and ans.size() > 0){
      sort(ans.begin(),ans.end());
      cout<<ans[0]<<nl;
    }
    else{
      cout<<"UNRESTORABLE"<<nl;
    }
  }
  return 0;
}


Measured memory_bytes: 3588
#include<iostream>

using namespace std;

int main(void){
    int n;
    cin >> n;
    int nums[n];
    for(int i = n-1; i >= 0; i--){
        cin >> nums[i];
    }
    
    for(int i = 0; i < n; i++){
        if(i == n-1){
            cout << nums[i] << endl;
        } else { 
            cout << nums[i] << " ";
        }
    }
}



Measured memory_bytes: 3076
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int A, B;
	cin >> A >> B;

	if (10 <= A + B) {
		cout << "error" << endl;
	}
	else{
		cout << A + B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  for(i=1;i<10;i++)
    for(j=1;j<10;j++)
      if(n == i*j){
        printf("Yes");
        exit(0);
      }
  printf("No");
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import numpy as np

if __name__ == '__main__':
    A , B = map(int, input().split())

    num = 1
    tap = 0

    if B==1:
        print(0)
        exit()

    while True:
        tap += 1
        num -= 1
        num += A

        if num >=B:
            break

    print(tap)


Measured memory_bytes: 21164
input = require('fs').readFileSync(process.stdin.fd, 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
H = lines.shift().split(' ')
max = 0
ans = 1
for (i=0; i<N; i++) {
    if (max <= H[i] * 1) {
        max = Math.max(H[i] - 1, max)
    } else {
        ans = 0
        break;
    }
}
console.log(['No', 'Yes'][ans])

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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
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();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int M, int S, int T, vector<int>& u, vector<int>& v) {
    vector<vector<int>> edges(N+1);
    REP(i,1,M+1) {
        edges[u[i]].emplace_back(v[i]);
    }

    vector<vector<int>> dp(N+1, vector<int>(3, INT_MAX));

    dp[S][0] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int> > > queue;
    queue.push({0, S});

    while (queue.size() > 0) {
        const auto pair = queue.top();
        int currentVertex = pair.second;
        int distance = pair.first;
        queue.pop();

        for (const auto nextVertex : edges[currentVertex]) {
            if (dp[nextVertex][(distance+1)%3] > distance+1) {
                dp[nextVertex][(distance+1)%3] = distance + 1;
                queue.push({distance + 1, nextVertex});
            }
        }
    }

	int answer = dp[T][0] == INT_MAX ? -1 : dp[T][0] / 3;
	stringstream ss;
	ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, M, S, T;
    cin >> N >> M;
    
    vector<int> u(M+1), v(M+1);
    REP(i,1,M+1) cin >> u[i] >> v[i];

    cin >> S >> T;
    
    solve(N, M, S, T, u, v);
    
    return 0;
}



Measured memory_bytes: 11904
n=gets.to_i
s=gets.split.map &:to_i
a=gets.split.map &:to_i
sum=0
for i in 0..n-1
  if s[i]<a[i]
    sum+= (a[i]>=(s[i]+s[i+1]))? (s[i]+s[i+1]):a[i]
    s[i+1]-= a[i]-s[i]
    s[i+1]=0 if s[i+1]<=0
  else
    sum+=a[i]
  end
end
puts sum


Measured memory_bytes: 24680
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007

def solve():
    N,A,B = map(int, input().split())
    if(abs(A - B)%2 == 0):
        print(abs(A-B)//2)
        return

    print(min(A-1,N-B)+1+(B-A-1)//2)    
if __name__ == '__main__':
    solve()


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

int main() {
    int n,m,x;
    int l[100000],r[100000];
    int max=0,maxIndex;
    int min=1000000,minIndex;
    int R,L;

    scanf("%d %d",&n,&m);
    for(int i=0; i<m; i++){
        scanf("%d %d",&l[i],&r[i]);
    }
    
    for(int i=0; i<m; i++){
        if(l[i] > max){
            max = l[i];
            maxIndex = i;
        }
        if(r[i] < min){
            min = r[i];
            minIndex = i;
        }
    }
    L = l[maxIndex];
    R = r[minIndex];
    if(R>=L) printf("%d\n",R-L+1);
    else printf("0\n");
    return 0;
}
   


Measured memory_bytes: 1024
import sys
t = input()
l = len(t)
for i in range(l-1):
    if t[i] == t[i+1]:
        print(i+1,i+2)
        sys.exit()
for i in range(l-2):
    if t[i] == t[i+2]:
        print(i+1,i+3)
        sys.exit()
print(-1,-1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  string s; cin >> s;
  int N = s.size();
  int ansl,ansr;
  ansl = ansr = -1;
  if (s[0] == s[1]) {
    ansl = 1;
    ansr = 2;
  }
  for (int i = 2;i < N; i++) {
    if (s[i] == s[i-1]) {
      ansl = i;
      ansr = i+1;
    } else if (s[i] == s[i-2]) {
      ansl = i-1;
      ansr = i+1;
    }
  }

  cout << ansl << " " << ansr << endl;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    cur=0
    for i,a in enumerate(A):
        if cur>a:
            print('No')
            return
        elif cur==a:
            continue
        else:
            a-=1
            cur=a
    print('Yes')




if __name__ == "__main__":
    main()

Measured memory_bytes: 92336
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=4e5+10;
const int mod=1e9+7;
ll fac[maxn],inv[maxn];
void gcd(ll a,ll b,ll &d,ll &x, ll &y){
	if(b){
		gcd(b,a%b,d,y,x); y-=x*(a/b);
	}
	else {
		d=a,x=1,y=0;
	}
}
void init(){
	fac[0]=fac[1]=1;
	for(int i=2;i<maxn;i++)
		fac[i]=fac[i-1]*i%mod;
}
ll c(ll n,ll k){
	ll x,y,d;
	ll tmp=(fac[k]*fac[n-k])%mod;
	gcd(tmp,mod,d,x,y);
	y=fac[n]*(x%mod)%mod;
	if(y<0) y+=mod;
	return y;
}
int main(){
	ll n,k;
	init();
	cin>>n>>k;
	ll ans=c(2*n-1,n);
	if(k>=n-1){
		//cout<<0;
		cout<<ans; return 0; 
	}
	else {
		for(int i=1;i<n-k;i++){
			ans-=c(n,i)*c(n-1,i-1)%mod;
			ans+=mod;
			ans%=mod;
		}
		cout<<ans;
	}
} 

Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    int m1 = 0;
    int m2 = 0;
    int m3 = 0;
    int m4 = 0;

    for(int i = 0; i < 3; i++){
        int a;
        int b;
        cin >> a >> b;
        if(a == 1){
            m1++;
        }else if(a == 2){
            m2++;
        }else if(a == 3){
            m3++;
        }else if(a == 4){
            m4++;
        }
        
        if(b == 1){
            m1++;
        }else if(b == 2){
            m2++;
        }else if(b == 3){
            m3++;
        }else if(b == 4){
            m4++;
        }
    }
    
    if(m1 <= 2 && m2 <= 2 && m3 <= 2 && m4 <= 2 && m1 > 0 && m2 > 0 && m3 > 0 && m4 > 0){
        cout << "YES";
    }else{
        cout << "NO";
    }

}

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

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int dp[500][500];

vector<int> a(500);
vector<int> sum(500);

int dfs(int l, int r) {
    if (dp[l][r] >= 0) return dp[l][r];
    if (r - l == 1) return dp[l][r] = 0;

    int res = INF;
    FOR(k, l + 1, r - 1) {
        int tmp = dfs(l, k) + dfs(k, r);
        res = min(res, tmp);
    }

    return dp[l][r] = res + sum[r] - sum[l];
}

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

    CLR(dp, -1);

    int N;
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }

    cout << dfs(0, N) << endl;
    return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>

int main()
{
int W, H, x, y, r;
scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

if(r <= x && r <= y && x+r <= W && y+r <= H){
printf("Yes\n");
}

else
printf("No\n");

return 0;
}



Measured memory_bytes: 2100
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0:
        break
    for height in range(H):
        if height%2 == 0:
            flag = True
        else:
            flag = False
        for wide in range(W):
            if flag:
                print('#', end='')
            else:
                print('.', end='')
            flag = not(flag)
        print('')
    print('')

Measured memory_bytes: 8868
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int[][] A = new int[2][N+1];
		for(int i = 1; i <= N; i++){
			A[0][i] = A[0][i-1] + in.nextInt();
		}
		for(int i = 1; i <= N; i++){
			A[1][i] = A[1][i-1] + in.nextInt();
		}
		
		int max = 0;
		for(int i = 1; i <= N; i++){
			int m = (A[0][i] - A[0][0]) + (A[1][N] - A[1][i-1]);
			//System.out.println((A[0][i] - A[0][0]) + " " + (A[1][N] - A[1][i-1]));
			max = Math.max(m, max);
		}
		
		System.out.println(max);
	}
}


Measured memory_bytes: 23124
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;
  cin>>s;
  rep(i,s.size()){
    cout<<'x';
  }
  cout<<endl;
}

Measured memory_bytes: 256
import itertools
def main():
    N, M, Q = map(int, input().split())
    query = [[int(a) for a in input().split()] for i in range(Q)]
    st = ""
    for i in range(M):
        st += str(i)

    total = 0
    for comb in itertools.combinations_with_replacement(st, N):
        A = [ int(a)+1 for a in comb]
        s = 0
        for a, b, c, d in query:
            if A[b-1] - A[a-1] == c:
                s += d
        
        if total < s:
            total = s

    print(total)

if __name__ == "__main__":
    main()

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

std::vector<std::pair<int, int>> dish;
int n, dp[3005][3005];

int f(int i, int minutes) {
  if (i >= n || minutes <= 0) return 0;
  if (dp[i][minutes] != -1) return dp[i][minutes];

  int take = f(i + 1, minutes - dish[i].first) + dish[i].second;
  int dont = f(i + 1, minutes);
  return dp[i][minutes] = std::max(take, dont);
}

int main() {
  int t;
  scanf("%d%d", &n, &t);

  dish.resize(n);
  for (auto &elem : dish)
    scanf("%d%d", &elem.first, &elem.second);

  std::sort(dish.begin(), dish.end());

  memset(dp, -1, sizeof dp);
  printf("%d\n", f(0, t));
  return 0;
}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;


  vector<int> A(N);
  int c;
  for (int i = 0; i < N; i++) {
    cin >> c;
    A[c - 1]++;
  }
  int sum = 0;
  sort(A.begin(), A.end(), greater<int>());
  for (int i = 0; i < N; i++) {
    if (i >= K) {
      sum += A[i];
    }
  }
  cout << sum << endl; 
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
    string st, suba, subb;
    int n, h, size;
    
    while(1){
        cin >> st;
        if(st == "-"){
            break;
        }
        cin >> n;
        size = st.size();
        for(int i=0;i<n;i++){
            cin >> h;
            suba = st.substr(0, h);
            subb = st.substr(h, size-h);
            st = subb + suba;
        }
        
        cout << st << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3192
s = input()
n = len(s)

x = []

for i in range(n):
    if 'A' not in x and s[i] is 'A':
        x.append(i)
        x.append('A')
    elif 'A' in x and s[i] is 'Z':
        x.append(i)

print(x[-1] - x[0] + 1)

Measured memory_bytes: 7512
#include<bits/stdc++.h>
using namespace std;
#define sz 200005
#define mod 1000000007
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
bool stair[sz];
int N;
ll cnt,cnt1[sz],cnt2[sz];

int main()
{
    faster_io;
    int n,y,m;
    ll x;
    cin>>N>>m;
    string s;

    for(int i=0;i<m;i++){
        cin>>x;
        stair[x] = true;
    }

    cnt1[0] = 1;
    x = 1;
    int f=10;
    for(int i=1;i<=N;i++){
        if(stair[i] && stair[i+1]){cout<<0<<endl;exit(0);}
        if(stair[i]){x=cnt1[i-1];f=0;continue;}
        f++;
        if(f==1 || f==2) cnt1[i] = x%mod;
        else{
            cnt1[i]= (x%mod+cnt1[i-2]%mod)%mod;
            x = cnt1[i]%mod;
        }
    }

    cout<<cnt1[N]<<endl;
//    for(int i=0;i<=N;i++) cout<<cnt2[i]<<" ";

    return 0;
}






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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int cost{-1};
	pair<int,int> from;
};

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

	int A=in(),B=in(),C=in(),X=in();

	int num = 0;
	REP(a,A+1){
		REP(b,B+1){
			REP(c,C+1){
				if(X==(500*a+100*b+50*c)){
					num++;
				}
			}
		}
	}
	
	out(num);
	return 0;
}


Measured memory_bytes: 256
// May be i don't deserve your attention...

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

#define F first
#define S second
#define pb push_back
#define elif else if
#define mp make_pair
#define int long long
#define ldd long double
#define vec_i vector<int>
#define pair_i pair<int,int>
#define sz(x) (int)(x.size())
#define vec_p vector<pair<int,int>>
#define vec_vec vector<vector<int>>
#define all(x) (x).begin(),(x).end()

#define forr(x,a,m) for(int x=a;x<m;x+=1)
#define debug(x) cout<<"~~"<<#x<<" => "<<x<<endl;

bool rev(int x, int y) {return x > y;}
void input_arr(int a[], int n) {forr(i, 0, n) cin >> a[i];}
bool sortbysec(const pair_i &a, const pair_i &b) {return a.S < b.S;}
bool sortinrev(const pair_i &a, const pair_i &b) {return (a.F > b.F);}
void print_vec(vec_i &v) {for (auto i : v) cout << i << " "; cout << endl;}
bool sortinrevbysec(const pair_i &a, const pair_i &b) {return (a.S > b.S);}
void print_arr(int a[], int n) {forr(i, 0, n)cout << a[i] << " "; cout << endl;}

template<typename...T>void input(T &...args) {((cin >> args), ...);}
template<typename...T>void print(T &&...args) {((cout << args << endl), ...);}
template<typename...T>void deb(T &&...args) {cout << "~~ "; ((cout << args << " "), ...); cout << endl;}

// ~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.

void stand8th() {
	string s; input(s);
	vec_i v;
	forr(i, 0, 3) {
		if (s[i] == 'R') {
			int val = 0;
			while (s[i] == 'R' && i < 3) {
				i++; val++;
			}
			v.pb(val);
			i--;
		}
	}
	if (sz(v) == 0) {
		print(0);
	}
	else {
		sort(all(v), rev);
		print(v[0]);
	}
}

// ~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.-.~.

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int tin = 1; //input(tin);
	while (tin--) {
		stand8th();
	}
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
double dist(int x, int y){
	return sqrt(pow(x, 2) + pow(y, 2));
}
int main(){
  int n, count=0;
  double d;
  cin>>n>>d;
  for(int i=0; i<n; i++){
  	int x, y;
  	cin>>x>>y;
  	if(dist(x, y) <= d)
  		count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3776
#include <iostream>

using namespace std;

int main()
{
	int n,k,l,m,q,p,a[205],b[205],i,j;
	m=0;
	do{
		cin >> n >> k >> l;
		for(i=0; i<n; i++)
			cin >> a[i];
		p=200000;
		for(j=k; j<=l; j++)
		{
			if(a[j]-a[j-1]<=p)
			{
				p=a[j]-a[j-1];
				q=j;
			}
		}
		b[m]=q;
		m++;
	}while(n!=0||k!=0||l!=0);
	for(i=0; i<m-1; i++)
		cout << b[i] << "\n";
}



Measured memory_bytes: 3116
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
ll n;
  cin>>n;
  n=((n+0.5)/100);
  n=8-((n/2)-2);
  cout <<n;

return 0;
}






ll gcd(ll a, ll b){

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }

}


Measured memory_bytes: 3628
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



#include<bits/stdc++.h>
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<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


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


const int mx = 1e5+123;

int dp[mx], n, h[mx];


int solve ( int i )
{
	if ( i == n-1 ) return 0;
	if ( dp[i] != -1 ) return dp[i];

	int ret1 = inf, ret2 = inf;
	if ( i+1 < n ) ret1 = abs ( h[i] - h[i+1] ) + solve ( i+1 );
	if ( i+2 < n ) ret2 = abs ( h[i] - h[i+2] ) + solve ( i+2 );

	return dp[i] = min ( ret1, ret2 );
}


int main()
{
	optimize();

	cin >> n;
	for ( int i = 0; i < n; i++ ) cin >> h[i];

	mem ( dp, -1 );
	cout << solve ( 0 ) << endl;


	return 0;
}


















Measured memory_bytes: 9048
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int N;
int main(int argc, const char * argv[]) {
  cin >> N;
  
  map<int, ll> cnt;
  for (int i = 1; i <= N; i++) {
    int x = i;
    for (int j = 2; j * j <= x; j++) {
      while (x % j == 0) {
        cnt[j]++;
        x = x / j;
      }
    }
    if (x != 1) {
      cnt[x]++;
    }
  }
  ll ans = 1;
  for (int i = 2; i <= N; i++) {
    ans = ans * (cnt[i] + 1) % mod;
  }
  cout << ans << endl;
  return 0;
}


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


void solve(std::string C){
    cout << static_cast<char>(C.at(0) + 1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string C;
    std::cin >> C;
    solve(C);
    return 0;
}


Measured memory_bytes: 256
// agrawal117
// segment tree

#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
ll arr[500009];
vector<ll> tree[2000009];

vector<ll> null(26,0);
void build(ll start,ll end,ll node)
{
	if(start==end){
		tree[node]=null;
		tree[node][arr[start]]++;
		return;
	}
	ll mid=(start+end)>>1;
	build(start,mid,2*node);
	build(mid+1,end,(2*node)+1);
	for(int i=0;i<26;i++) tree[node].push_back(tree[2*node][i]+tree[2*node+1][i]) ;
}

vector<ll> query(ll start,ll end,ll node,ll l,ll r)
{
	if(start>r || l>end) {				//no overlap case  return that value which does not affect the ans 
		return null;							// as in case of sum we can return 0;
	}
	else if(l<=start && r>=end) {
		return tree[node];           // case of fully overlap
	}
	else{
		ll mid=(start+end)>>1;								//partial overlap so call both children
	    vector<ll> child1=query(start,mid,2*node,l,r);
		vector<ll>child2=query(mid+1,end,(2*node)+1,l,r);
        vector<ll> temp;
        for(int i=0;i<26;i++) temp.push_back(child1[i]+child2[i]);
        return temp;
	}
}

void update(ll start,ll end,ll node,ll idx,ll value)
{
	 if(start==end){
		tree[node].clear();
		tree[node]=null;
		arr[start]=value;
		tree[node][arr[start]]++;
		return;
	}
	ll mid=(start+end)>>1;	
	if(start<=idx && idx<=mid){
	 update(start,mid,2*node,idx,value);
	}
	 else{
		update(mid+1,end,(2*node)+1,idx,value);
	 }
	 tree[node].clear();
	for(int i=0;i<26;i++) tree[node].push_back(tree[2*node][i]+tree[2*node+1][i]) ;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
	ll n;
	cin>>n;
	string s; cin>>s;
	for(ll i=0;i<n;i++) arr[i+1]=s[i]-'a';
// 	for(int i=1;i<=n;i++) cout<<arr[i]<<" ";
// 	cout<<endl;
	build(1,n,1);
	//for(int i=1;i<10;i++) cout<<tree[i]<<endl;
	ll q;
	cin>>q;
	ll a,b,c;
	ll cnt=0;
	for(ll i=0;i<q;i++){
		cin>>a;
		if(a==1) {
		    char ch;
		    cin>>b>>ch;
		    update(1,n,1,b,int(ch-'a'));
		}
		else{
		    cin>>b>>c;
			vector<ll> ans=query(1,n,1,b,c);
			ll cnt=0;
			for(int j=0;j<26;j++) if(ans[j]>0) cnt++;
// 			for(auto it= ans.begin();it!=ans.end();it++) cout<<*it<<" ";
// 			cout<<endl;
			cout<<cnt<<endl;
		}
// 		cnt++;
	}
// 	cout<<cnt<<endl;
	
}














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

int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    ll d=b/a;
    if(d>c)
        cout<<c<<endl;
    else
        cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>)
{
    val s = readString().toByteArray()

    val m = mutableMapOf<Byte, Int>()
    for (item in s) {
        if (m.containsKey(item)) {
            m[item] = m[item]!! + 1
        } else {
            m.put(item, 1)
        }
    }

    val keysize = m.keys.indices.last() + 1
    println(if (keysize == 2 && m.values.all { it == 2 }) "Yes" else "No")
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


Measured memory_bytes: 33816
n = input()
value = 0
answer = 0
over = 0
five = 0

for i in range(len(n)+1):
    if i == len(n):
        if over == 1:
            answer += 1
            break
        else:
            break
    value = int(n[len(n)-1-i]) + over
    if five == 1:
        if value >= 5:
            answer += (10 - value - 1)
            five = 0
            over = 1
        else:
            answer += value
            five = 0
            over = 0
    else:
        if value > 5:
            answer += (10 - value)
            over = 1
        elif value == 5:
            answer += 5
            five = 1
            over = 0
        else:
            answer += value
            over = 0

print(answer)


Measured memory_bytes: 5492