akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------


int main(int argc,char** argv){ fastio; myio;
  int n;
  cin>>n;
  vl a(5,0);
  rep(i,n){
    string s;
    cin>>s;
    switch (s[0])
    {
    case ('M'): a[0]++; break;
    case ('A'): a[1]++; break;
    case ('R'): a[2]++; break;
    case ('C'): a[3]++; break;
    case ('H'): a[4]++; break;
    default:
      break;
    }
  }
  ll ans=0;
  rep(i,5) srep(j,i+1,5) srep(k,j+1,5){
    ans += a[i] * a[j] * a[k];
  }
  cout<<ans;
}

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

int main(void) {
    int N, M;
    cin >> N >> M;
    int l, r;
    for (int i = 0; i < M; ++i) {
        int tl, tr;
        cin >> tl >> tr;
        if (i == 0) {
            l = tl;
            r = tr;
        } else {
            l = max(l, tl);
            r = min(r, tr);
        }
    }
    if (l > r) {
        cout << 0 << "\n";
    } else {
        cout << (r - l + 1) << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
s = int(input())

l = []
l.append(s)

ans = 0

i = 1

while ans == 0:
	if l[i-1]%2 == 0:
		l.append(int(l[i-1]/2))
	else:
		l.append(int(3*l[i-1]+1))
	
	if len(l)!=len(set(l)):
		ans = i
	else:
		i = i + 1

print(i+1)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1);
    ll b;
    a[0]=0;
    for (int i=0;i<n;i++) {
        cin >> b;
        a[i+1] = a[i]+b;
    }
    double mid=a[n]/2+0.5*(a[n]%2);
    int j=lower_bound(a.begin(),a.end(),mid)-a.begin();
    ll ans;
    if (j==1) ans=(a[1]-mid)/0.5;
    else {
        double mi=1.0*min(a[j]-mid,mid-a[j-1]);
        ans=mi/0.5;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    int a[n];
    
    int max = -1000000000; int min;
    cin>>min;
    for(int i=0; i<n-1; i++){
        int temp; 
        cin>>temp;
        if(temp-min>max){
            max = temp-min;
        }
        if(temp<min){
            min = temp;
        }
    
        
    }
    cout<<max<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3224
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#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;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

int main(){
    std::ios::sync_with_stdio(false);
    ll k, a, b;
    cin >> k >> a >> b;

    ll res = 1;
    if (b - a > 2)
    {
        if(((k+1-a)%2) == 0)
        {
            res = (b - a) * ((k+1-a) / 2) + a;
        }
        else
        {
            res = (b - a) * ((k+1-a) / 2) + a + 1;
        }
        
    }
    
    cout << max(1 + k, res) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;
int ans,n;
string s;
char x;
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    cin>>s;
    x=s[0];
    for(int i=0;i<sz(s);i++){
        if(s[i]!=x){
            if(i==n-1)x='A';
            //cout<<i<<"\n";
            ans++;
            x=s[i];
        }
    }
    if(x!='A')ans++;
    cout<<ans;

}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w));
    queue<tuple<int,int,int>> que;
    vector<vector<int>> ans(h,vector<int>(w,-1));
    rep(i,h){
        rep(j,w){
            char a_e;
            cin >> a_e;
            if(a_e=='#'){
                que.push(make_tuple(i,j,0));
                ans[i][j] = 0;
            }
        }
    }
    while(!que.empty()){
        tuple<int,int,int> elem = que.front();
        que.pop();
        int tmp_i = get<0>(elem);
        int tmp_j = get<1>(elem);
        int tmp_ans = get<2>(elem);
        if(tmp_i != h-1){
            if(ans[tmp_i+1][tmp_j] == -1){
                ans[tmp_i+1][tmp_j] = tmp_ans + 1;
                que.push(make_tuple(tmp_i+1,tmp_j,tmp_ans+1));
            }
        }
        if(tmp_i != 0){
            if(ans[tmp_i-1][tmp_j] == -1){
                ans[tmp_i-1][tmp_j] = tmp_ans + 1;
                que.push(make_tuple(tmp_i-1,tmp_j,tmp_ans+1));
            }
        }
        if(tmp_j != w-1){
            if(ans[tmp_i][tmp_j+1] == -1){
                ans[tmp_i][tmp_j+1] = tmp_ans + 1;
                que.push(make_tuple(tmp_i,tmp_j+1,tmp_ans+1));
            }
        }
        if(tmp_j != 0){
            if(ans[tmp_i][tmp_j-1] == -1){
                ans[tmp_i][tmp_j-1] = tmp_ans + 1;
                que.push(make_tuple(tmp_i,tmp_j-1,tmp_ans+1));
            }
        }
    }
    int final_ans = 0;
    rep(i,h){
        rep(j,w){
            final_ans = max(final_ans, ans[i][j]);
        }
    }
    cout << final_ans;
}

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

int main()
{
	int n;
	const char v[10][8] = { "0111111", "0000110", "1011011", "1001111", "1100110", 
							"1101101", "1111101", "0100111", "1111111", "1101111" };

	cin >> n;

	while (n > 0) {
		int d;
		cin >> d;
		cout << v[d] << endl;
		int dp = d;

		for (int i = 1; i < n; i++) {
			cin >> d;
			for (int j = 0; j < 7; j++) {
				if (v[d][j] == v[dp][j])
					cout << 0;
				else
					cout << 1;
			}
			cout << endl;
			dp = d;
		}

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3076
import numpy as np
words = lambda t : list(map(t, input().split()))
n = int(input())
ws = words(int)

less = 0
more = sum(ws)

ans = abs(more-less)
for i in range(n):
    less += ws[i]
    more -= ws[i]
    ans = min(ans, abs(more-less))

print(ans)


Measured memory_bytes: 21768
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 110, M = 100010;
vector<int>v, u;
int num, n, k, x;
int main()
{
	scanf("%d%d", &n, &k);
	if (n == 1)
		return puts("1\n1\n1"), 0;
	if (k == 1)
	{
		scanf("%d", &x);
		printf("%d\n%d\n%d %d", x, 2, x - 1, 1);
		return 0;
	}
	for (int i = 1; i <= k; i++)
	{
		scanf("%d", &x);
		v.push_back(x);
		if (x & 1)
			swap(v[0], v[i - 1]);
		num += x & 1;
	}
	for (int i = 1; i < k; i++)
		if (v[i] & 1)
			swap(v[i], v[k - 1]);
	if (num > 2)
		puts("Impossible");
	else
	{
		for (int i : v)
			printf("%d ", i);
		printf("\n%d\n", v[0] == 1 ? k - 1 : k);
		if (v[0] != 1)
			printf("%d ", v[0] - 1);
		for (int i = 1; i < k; i++)
			printf("%d ", v[i] + (i == k - 1));
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=1e5+5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n1,n2;
	string str1,str2,str3;
	cin>>str1>>str2>>n1>>n2>>str3;
	if(str1==str3)n1--;
	if(str2==str3)n2--;
	cout<<n1<<" "<<n2<<endl;
	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : abc1147c.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

void dfs(string s, long long N, long long &count) {
	long n = stoll(s);
	if(n <= N){
		if(s.find('3') != string::npos && s.find('5') != string::npos && s.find('7') != string::npos){
			++count;
		}
	}
	else{
		return;
	}


	dfs(s + "3", N, count);
	dfs(s + "5", N, count);
	dfs(s + "7", N, count);
}

int main() {
	long long N;
	cin >> N;
	long long count = 0;
	dfs("3", N, count);
	dfs("5", N, count);
	dfs("7", N, count);

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
//解説あり
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int n;
ll s[100005], a[100005];

int main(void) {
  cin >> n;
  rep(i, 1, n+1) scanf("%lld", &a[i]);
  sort(a, a+n+1);
  
  int ng = 0;
  rep(i, 1, n) {
    s[i] = s[i-1]+a[i];
    if (s[i]*2<a[i+1] ) ng = i;
  }
  
  
  cout << n-ng << endl;
  
    return 0;
}



Measured memory_bytes: 1792
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    auto v = vector<double>(n);
    for (auto &v_i : v)
        cin >> v_i;

    while (v.size() >= 2) {
        sort(v.begin(), v.end(), greater<double>());
        auto a = v.back();
        v.pop_back();
        auto b = v.back();
        v.pop_back();
        v.push_back((a + b) * 0.5);
    }

    printf("%.10f\n", v.front());
    return 0;
}


Measured memory_bytes: 256
fn main () {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();
    let mut p = std::collections::HashSet::<String>::new();
    let mut h = Vec::<String>::new();
    let mut r = true;

    for _ in 0..n {
        let mut word = String::new();
        std::io::stdin().read_line(&mut word).unwrap();
        let word: String = word.trim().into();
        if r && p.contains(&word) {
            r = false;
        } else {
            p.insert(word.clone());
            h.push(word);
        }
    }

    println!("{}", if r && h.iter().zip(h.iter().skip(1)).all(|(a, b)| a.chars().last().unwrap() == b.chars().next().unwrap()) { "Yes" } else { "No" });
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int H = in(),W = in();
    vector<string> S(H);
    REP(i,H)S[i] = in<string>();
    REP(i,H){
        REP(l,W){
            int count = 0;
            if(S[i][l] == '.'){
                if(i != 0 && l != 0){
                    if(S[i-1][l-1] == '#')count++;
                }
                if(i != 0){
                    if(S[i-1][l] == '#')count++;
                }
                if(l != 0){
                    if(S[i][l-1] == '#')count++;
                }
                if(i != 0 && l != W-1){
                    if(S[i-1][l+1] == '#')count++;
                }
                if(i != H-1 && l != 0){
                    if(S[i+1][l-1] == '#')count++;
                }
                if(i != H-1 && l != W-1){
                    if(S[i+1][l+1] == '#')count++;
                }
                if(i != H-1){
                    if(S[i+1][l] == '#')count++;
                }
                if(l != W-1){
                    if(S[i][l+1] == '#')count++;
                }
                S[i][l] = count + '0';
            }
        }
    }
    REP(i,H){
        REP(l,W){
            cout << S[i][l];
        }
        cout << "\n";
    }
}

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

using namespace std;

int n, m;
int i, j;
char a, b, c;
char list[1000];

int main()
{
	while (1)
	{
		scanf("%d", &n);
		if (n==0) return 0;
		for (i=0; i<1000; i++) list[i] = i;
		for (i=0; i<n; i++)
		{
			scanf(" %c %c", &a, &b);
			list[a] = b;
		}
		scanf("%d", &m);
		for (i=0; i<m; i++)
		{
			scanf(" %c", &c);
			printf("%c", list[c]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1160
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] s = new int[M];
    int[] c = new int[M];
    for (int i = 0; i < M; i++) {
      s[i] = sc.nextInt();
      c[i] = sc.nextInt();

    }
    sc.close();

    int ans = -1;

    int n0 = (int) Math.pow(10, N - 1);
    if (n0 == 1) n0 = 0;
    int n1 = (int) Math.pow(10, N) - 1;
    for (int i = n0; i <= n1; i++) {
      String v = String.valueOf(i);
      boolean m = true;
      for (int j = 0; j < M; j++) {
        int d = v.charAt(s[j] - 1) - '0';
        if (c[j] != d) {
          m = false;
          break;
        }
      }
      if (m) {
        ans = i;
        break;
      }
    }

    System.out.println(ans);
  }
}

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

int main(){
  int n,m;
  cin >>n >>m;
  if(n==m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000000000000
#define inf -100000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//number of edges in a graph equal (v[i].size() ka summation of all the vertices)/2
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll int n;
    cin>>n;
    ll int i,j,k,z,s=0;
    for(i=1;i<=n;i++)
    {
    	for(j=1;j<=n;j++)
    	{
    		for(k=1;k<=n;k++)
    		{
    			z=__gcd(i,j);
    			z=__gcd(z,k);
    			s=s+z;
    		}
    	}
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3652
# coding:utf-8
# CCCCCCCCCCCC

import math
import re

def inclement_bi(i):
    return bin(i)

def main(params):
    result = 0
    n,m = params[0]
    ks = params[1:]
    ps = ks.pop(-1).split()
    for i in range(2**n):
        bi = str(inclement_bi(i)).replace('0b','')
        if len(bi) < n:
            bi = '0' * (n-len(bi)) + bi
        cnt = 0
        chk = True
        for j in ks:
            tmp = j.split()
            k = tmp[0]
            s = tmp[1:]
            p = int(ps[cnt])
            total = 0
            for si in s:
                si = int(si) - 1
                if bi[si] == '1':
                    total += 1
            cnt += 1
            if total % 2 != p:
                chk = False
                break
        if chk == True:
            result += 1
    print result

if __name__ == "__main__":
    n,m = [int(i) for i in raw_input().split()]
    cnt = m + 1 # TODO: edit here
    params = [[n,m]]
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)



Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P==0) return 1;
    if(P < 0) return 0;
    if(P%2==0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) return N * RS(N,P - 1,M);
    return N * RS(N, P-1, M) % M;
}

/* RMQ：[0,n-1] について、区間ごとの最小値を管理する構造体
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b): [a,b) での最小の要素を取得。O(log(n))
*/
template <typename T>
struct SegmentTree {
    int n;         // 葉の数
    vector<T> dat; // 完全二分木の配列
    SegmentTree(int n_) : n(), dat(n_ * 4, INF) { // 葉の数は 2^x の形
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
    void update(int i, T x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // the minimum element of [a,b)
    T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    T query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return INF;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
    inline T operator[](int a) { return query(a, a + 1); }
};

ll dp[100010]; //dp[i] = 頂点1からiまでの最短距離

int main() {
    int N,M;
    cin >> N >> M;
    vector<tuple<int,int,ll>> graph(M);
    for(int i = 0;i < M;i++) {
        int L,R;
        ll C;
        cin >> L >> R >> C;
        L--;
        R--;
        graph.at(i) = make_tuple(L,R,C);
    }
    sort(graph.begin(),graph.end());
    for(int i = 0;i < 100010;i++) {
        dp[i] = INF;
    }
    dp[0] = 0;
    SegmentTree<ll> seg(N);
    seg.update(0,0);
    for(int i = 0;i < M;i++) {
        seg.update(get<1>(graph.at(i)),min(seg[get<1>(graph.at(i))],seg.query(get<0>(graph.at(i)),get<1>(graph.at(i))) + get<2>(graph.at(i))));
    }
    if(seg[N - 1] == INF) {
        cout << -1 << endl;
    }
    else {
        cout << seg[N - 1] << endl;
    }
}

Measured memory_bytes: 8568
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = readLine()!!.split(" ").map(String::toInt)

    if (xs.toSet().size == 1) {
        println(n / 2)
        return
    }

    val oddNumList = xs.withIndex().filter { it.index % 2 == 0 }.map { it.value }
    val evenNumList = xs.withIndex().filter { it.index % 2 != 0 }.map { it.value }

    val groupby1 = oddNumList.groupBy { it }.map { it.value }.sortedByDescending { it.size }
    val groupby2 = evenNumList.groupBy { it }.map { it.value }.sortedByDescending { it.size }

    val listOfMax1 = groupby1.first()
    val listOfMax2 = groupby2.first()

    if (listOfMax1.first() != listOfMax2.first()) {

        val freq1 = listOfMax1.first()
        val freq2 = listOfMax2.first()

        val count1 = groupby1.filter { it[0] != freq1 }.sumBy { it.size }
        val count2 = groupby2.filter { it[0] != freq2 }.sumBy { it.size }

        println(count1 + count2)
        return
    }


    val freq1 = listOfMax1.first()
    val freq2 = groupby2[1].first()
    val count1 = groupby1.filter { it[0] != freq1 }.sumBy { it.size }
    val count2 = groupby2.filter { it[0] != freq2 }.sumBy { it.size }
    val ans1 = count1 + count2

    val freq3 = groupby1[1].first()
    val freq4 = listOfMax2.first()
    val count3 = groupby1.filter { it[0] != freq3 }.sumBy { it.size }
    val count4 = groupby2.filter { it[0] != freq4 }.sumBy { it.size }
    val ans2 = count3 + count4

    if (ans1 < ans2) {
        println(ans1)
    } else {
        println(ans2)
    }
}

Measured memory_bytes: 84272
import Data.List

-- 与えられた文字列の最大n文字までの部分文字列のリスト
-- 部分文字列を全てに求めると爆発するのでn文字で足きり
-- n+1文字の文字列から先頭から1,..,n文字までの部分文字列が辞書順で前に来る
substrings :: Int -> String -> [String]
substrings n s = foldl (++) [] $ map (heads n) $ tails s

-- 先頭から1文字,2文字,...,n文字までの部分文字列
heads :: Int -> String -> [String]
heads n s = map ((flip take) s) [1..(minimum [n, length s])]

pickup_small :: Ord a => Int -> [a] -> [a]
pickup_small n l = take' n $ sort $ nub l
    where
        take' n l = take (minimum [n, length l]) l

kth :: Int -> String -> String
kth k s = (foldr f [] $ substrings k s) !! (k - 1)
    where
        f e r = pickup_small k (e:r)

main = do
    s <- getLine
    k <- readLn
    putStrLn $ kth k s


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



int main()
{
 ll n,k;
cin>>k>>n;
ll a[n],b[n];
for(ll i=0;i<n;i++)
{
	cin>>a[i];
	
}
ll l,r,ans=1e9;
for(ll i=0;i<n;i++)
{
	l=a[i];
	r=a[(i+n-1)%n];
	if(r<l)r+=k;
	ans=min(ans,r-l);
}

cout<<ans;

}



Measured memory_bytes: 1792
def kakuwa(S):
    A = list(str(S))
    B = [int(x) for x in A]
    return sum(B)
    
N = int(input())
for i in range(1,5):
    if N%(10**i) == 0:
        ans = 10
        break
else:
    ans = kakuwa(N)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int hako[1000]={0},j=0,i=0,out[1000]={0};
	
	while(scanf("%d",&hako[i])!=EOF){
		if(hako[i]==0){
			out[j]=hako[i-1];
			j++;
			i--;
		}
		else if(hako[i]!=0){ i++; }
	}
	for(i=0;i<j;i++)printf("%d\n",out[i]);
return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5+100;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+9;
const ll p = 29;

bool check(ll n,ll k){
    while(n%k==0){
        n/=k;
    }
    n%=k;
    return n==1;
}


int main(){
    FASTIO;
    PRECISION; 

    ll n;
    cin>>n;

    if(n==2){
        cout<<1<<"\n";
        return 0;
    }

    set<ll>ans;

    ll n2 = n-1;

    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            if(check(n,i)){
                ans.insert(i);
            }

            if(check(n,n/i)){
                ans.insert(n/i);
            }
        }

        if(n2%i==0){
            ans.insert(i);
            ans.insert(n2/i);
        }
    }
    ans.insert(n);
    ans.insert(n2);

    cout<<ans.size()<<"\n";


    
 
}


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

int main() {
	char a, b;
	cin >> a >> b;
	if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D'))cout << "H" << endl;
	else cout << "D" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

for i in range(N):
    ans = 0
    ans_dis = float("inf")
    for j in range(M):
        distance = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if distance < ans_dis:
            ans = j + 1
            ans_dis = distance
    print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define N 36
 
typedef struct{
  char mark;
  int value;
}MV;
 
int isStable(MV, MV);
int n;
 
int main()
{
  int i, j, a, b, d=0, min=0;
  MV c[N], c1[N], c2[N], temp;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)
{
    scanf(" %c%d", &c[i].mark, &c[i].value);
    c1[i] = c[i];
    c2[i] = c[i];
  }
 
  for(i=0;i<n-1;i++)
{
    for(j=n-1;j>i;j--)
{
      if(c[j].value < c[j-1].value)
{
    temp = c[j];
    c[j] = c[j-1];
    c[j-1] = temp;
      }
    }
  }
 
  for(i=0;i<n-1;i++) printf("%c%d ", c[i].mark, c[i].value);
  printf("%c%d\n", c[n-1].mark, c[n-1].value);
 
  for(i=0;i<n-1;i++)
{
    for(j=i+1;j<n-1;j++)
{
      for(a=0;a<n-1;a++)
{
    for(b=a+1;b<n-1;b++)
{
      if(c2[i].value == c2[j].value && c2[i].mark == c[b].mark && c2[i].value == c[b].value && c2[j].mark == c[a].mark && c2[j].value == c[a].value) d = 1;
    }
      }
    }
  }
  if(d == 1) printf("Not stable\n");
  else printf("Stable\n");
 
  for(i=0;i<n;i++)

{
    min = i;
    for(j=i;j<n;j++)
{
      if(c1[j].value < c1[min].value) min = j;
    }
    temp = c1[i];
    c1[i] = c1[min];
    c1[min] = temp;
  }
 
  for(i=0;i<n-1;i++) printf("%c%d ", c1[i].mark, c1[i].value);
  printf("%c%d\n", c1[n-1].mark, c1[n-1].value);
   
  for(i=0;i<n-1;i++)
{
    for(j=i+1;j<n-1;j++)
{
      for(a=0;a<n-1;a++)
{
    for(b=a+1;b<n-1;b++)
{
      if(c2[i].value == c2[j].value && c2[i].mark == c1[b].mark && c2[i].value == c1[b].value && c2[j].mark == c1[a].mark && c2[j].value == c1[a].value) d = 1;
    }
      }
    }
  }
  if(d == 1) printf("Not stable\n");
  else printf("Stable\n");
 
  return 0;
}

Measured memory_bytes: 608
n=int(input())
a=[0]+[int(input()) for _ in range(n)]
d=[False]*(n+1)
i=1
ans=0
while d[i]==False and i!=2:
    d[i] = True
    ans += 1
    i=a[i]
if d[i]:
    print(-1)
else:
    print(ans)

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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            while((s = Console.ReadLine()) != "0")
            {
                Console.WriteLine(s.Select(c => c - '0').Sum());
            }
        }

        /*private static bool IsInput(out int[] arr)
        {
            var s = Console.ReadLine();
            if (s == "0 0") { arr = null; return false; }

            arr = s.Split(' ').Select(int.Parse).ToArray();
            return true;
        }
        // */
    }
}


Measured memory_bytes: 16204
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, p, i;
	cin >> n >> p;
	string s;
	cin >> s;
	ll ans = 0;
	if(p == 2 || p == 5) {
		fo(i, 0, n) {
			if((s[i] - '0') % p == 0)
			ans += i + 1;
		}
	}
	else {
		// If x * 10^i  is divisible by p, then x it follows that x | p, since 10 and p are co-prime. 
		map <int, int> mp;
		++mp[0];
		int curr = 0, pw = 1;
		for(int i = n - 1; i >= 0; i--) {
			curr = (((s[i] - '0') * pw + curr)) % p;
			ans += mp[curr];
			++mp[curr];
			pw = (pw * 10) % p;
		}
	}
	cout << ans;
}


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

    int a, b;
    cin >> a >> b;

    if(a < b)
    cout << "a < b" << endl;

    else if(a >b)
    cout << "a > b" << endl;

    else cout << "a == b" <<endl;

    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int m = 1000000007; 



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

	int n, k;
	cin >> n >> k;
	set<int> s;
	while (k--) {
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			int num; cin >> num;
			s.insert(num);
		}
	}
	cout << n-s.size();


	return 0;
}

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

using   namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define  all(v)       (v).begin(),(v).end()
#define  rall(v)      (v).rbegin(),(v).rend()
#define  pb           push_back  
#define  eb           emplace_back
#define  mp           make_pair
#define  ff           first
#define  ss           second
#define  pf           push_front
#define  bs           binary_search
#define  lb           lower_bound
#define  ub           upper_bound
#define  umap         unordered_map
#define  uset         unordered_set
#define  dec(x)       fixed<<setprecision(x)
#define  lcm(a,b)    (a*b/__gcd(a,b))

typedef  priority_queue<ll>  pq;
typedef  priority_queue<ll,vector<ll>,greater<ll>> pqmn;
typedef  pair<ll,ll> pll;

const    ll inf=LLONG_MAX;
const    ll mod=1e9+7;
const    ld pi=acos(-1);
                    
void solution()
{ 
    string s="ACL";
    ll n;
    cin>>n;
    while(n--){
        cout<<s;
    }


}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solution();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3592
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let n: usize = read!();
    let mut abc = Vec::with_capacity(n);
    for _ in 0..n {
        let a: usize = read!();
        let b: usize = read!();
        let c: usize = read!();
        abc.push([a, b, c]);
    }

    let mut dp = vec![vec![0; 3]; n + 10];

    for i in 1..=n {
        for j in 0..3 {
            let iter = (0..3).filter(|&jj| jj != j);
            for k in iter {
                dp[i][j] = dp[i][j].max(dp[i - 1][k] + abc[i - 1][k]);
            }
        }
    }

    println!("{}", [dp[n][0], dp[n][1], dp[n][2]].iter().max().unwrap());
}


Measured memory_bytes: 9968
#include"stdio.h"

int main() {
    int i, j, n, v, count = 0;
    int a[100];

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    for (i = 0; i < n; i++) {
        for (j = n - 1; j > 0; j--)
            if (a[j] < a[j - 1]) {
                v = a[j];
                a[j] = a[j - 1];
                a[j - 1] = v;
                count++;
            }
    }
    for (i = 0; i < n; i++) {
        if (i > 0)
            printf(" ");
        printf("%d", a[i]);
    }

    printf("\n%d\n", count);

    return 0;
}

Measured memory_bytes: 1848
import sys
from collections import deque
import copy
def main():
    N, K = map(int, input().split())
    A = [(int(i) - 1) for i in input().split()]
    d = []
    for i in range(N):
        d.append(-1)
    d[0] = 0
    now = 0
    cycle = 0
    ans = -1
    a = 0
    flag = True
    while K > 0:
        if flag:
            if d[A[now]] == -1:
                d[A[now]] = d[now] + 1
            else:
                cycle = (d[now] + 1) - d[A[now]]
                K %= cycle
                flag = False
                if K == 0:
                    break
        K -= 1
        now = A[now]
    print(now + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33736
s,t='0'+input(),'0'+input()
ns,nt=len(s)+1,len(t)+1
dp=[[0 for i in range(nt)] for i in range(ns)]
for i in range(1,ns):
	for j in range(1,nt):
		if s[i-1]==t[j-1]:dp[i][j]=dp[i-1][j-1]+1
		else:dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i,j=ns-1,nt-1
ans=''
while i>0 or j>0:
	if dp[i][j]==dp[i][j-1]:j-=1
	elif dp[i][j]==dp[i-1][j]:i-=1
	else:
		ans=s[i-1]+ans
		i-=1;j-=1
print(ans[1:])

Measured memory_bytes: 147848
#include<bits/stdc++.h>
using namespace std;
long long ans=0,num[200000];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>num[i];
	if(k>=n){
		cout<<0;
		return 0;
	}
	sort(num,num+n);
	for(int i=n-k-1;i>=0;i--)
		ans+=num[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int odd=0;
		for(int i=0;i<n;i++) {
			int a=scanner.nextInt();
			if(a%2==1)odd++;
		}
		System.out.println(odd%2==0?"YES":"NO");
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 24024
import java.util.Scanner;

/**
 * @author penguin_410
 *         Date: 2014/03/06
 */
public class Main {
    public static void main(String... args) {
        final Scanner scanner = new Scanner(System.in);
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final int x = scanner.nextInt();
            final int y = scanner.nextInt();
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 27620
#include <iostream>
#include <deque>
#define rep(i,a) for (int i = 0; i < (a); i++)
using namespace std;

int W, H, wl, hl, wr, hr, dw, dh;
int nwl, nhl, nwr, nhr, wlg, hlg, wrg, hrg;
int dws[] = {1,0,-1,0}, dhs[] = {0,1,0,-1};
char dummy, A[51][51], B[51][51];
bool visited[51][51][51][51];

struct Array {
    int wl, hl, wr, hr;
    Array(int wl0, int hl0, int wr0, int hr0) {
        wl = wl0, hl = hl0;
        wr = wr0, hr = hr0;
    }
};
        

int main(void){
    while (cin >> W >> H, W) {
        rep(h, H) {
            rep(w, W) cin >> A[h][w];
            rep(w, W) cin >> B[h][w];
        }
        rep(h, H) {
            rep(w, W) {
                if (A[h][w] == 'L') wl  = w, hl  = h;
                if (B[h][w] == 'R') wr  = w, hr  = h;
                if (A[h][w] == '%') wlg = w, hlg = h;
                if (B[h][w] == '%') wrg = w, hrg = h;
            }
        }

        rep(i, H) rep(j, W) rep(k, H) rep(l, W) visited[i][j][k][l] = false;
        visited[hl][wl][hr][wr] = true;
        bool flag = false;
        deque<Array> que;
        que.push_back(Array(wl,hl,wr,hr));
        while (!que.empty()) {
            Array tmp = que.front(); que.pop_front();
            wl = tmp.wl, hl = tmp.hl;
            wr = tmp.wr, hr = tmp.hr;
            if (wl == wlg && hl == hlg && wr == wrg && hr == hrg) {
                cout << "Yes" << endl;
                flag = true;
                break;
            }
            
            rep(i, 4) {
                dw = dws[i], dh = dhs[i];
                nwl = min(W-1,max(0,wl+dw)), nhl = min(H-1,max(0,hl+dh));
                if (A[nhl][nwl] == '#') nwl = wl, nhl = hl;
                nwr = min(W-1,max(0,wr-dw)), nhr = min(H-1,max(0,hr+dh));
                if (B[nhr][nwr] == '#') nwr = wr, nhr = hr;
                
                if (!visited[nhl][nwl][nhr][nwr]) {
                    if ((nwl == wlg && nhl == hlg) ^ (nwr == wrg && nhr == hrg)) continue;
                    visited[nhl][nwl][nhr][nwr] = true;
                    que.push_back(Array(nwl,nhl,nwr,nhr));
                }
            }
        }
        if (!flag) cout << "No" << endl;
    }
    return 0;
}

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

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

    vector<pair<pair<int, int>, int>> a(m);
    rep (i, m)
    {
        cin >> a[i].first.first >> a[i].first.second;
        a[i].second = i;
    }

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

    vector<pair<int, pair<int, int>>> ans(m);
    vector<int> cnt(n + 1, 1);
    rep (i, m)
    {
        ans[i].first = a[i].second;
        ans[i].second.first = a[i].first.first;
        ans[i].second.second = cnt[a[i].first.first]++;
    }

    sort(ans.begin(), ans.end());
    rep (i, m)
        printf("%06d%06d\n", ans[i].second.first, ans[i].second.second);
    return 0;
}

Measured memory_bytes: 5824
use std::io;
use std::str::FromStr;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> BinaryHeap<Rev<u64>> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| Rev(s.parse().unwrap())).collect()
}

fn main() {
    let (n, m) = input_tuple();
    let mut a_vec = input_vec();
    let mut b_vec: Vec<u64> = Vec::new();
    let mut c_vec: Vec<u64> = Vec::new();
    for _ in 0..m {
        let (b, c) = input_tuple();
        b_vec.push(b);
        c_vec.push(c);
    }
    for _ in 0..m {
        let c = c_vec.pop().unwrap();
        for i in 0..b_vec.pop().unwrap() {
            if a_vec.peek().unwrap().0 < c {
                a_vec.pop();
                a_vec.push(Rev(c));
            } else {
                break;
            }
        }
    }
    let mut sum = 0;
    for a in a_vec {
        sum += a.0;
    }
    println!("{}", sum);
}


Measured memory_bytes: 8444
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int n = Integer.parseInt(st.nextToken());
        long d = Long.parseLong(st.nextToken());
        d = d*d;
        int cnt = 0;
        for(int i = 0; i < n; i++){
            st = new StringTokenizer(f.readLine());
            long a = Long.parseLong(st.nextToken());
            long b = Long.parseLong(st.nextToken());
            long dist = a*a + b*b;
            if(dist <= d) cnt++;
        }
        out.println(cnt);


        out.close();
    }
}


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

int main(){
   unsigned c1=0,c5=0,c10=0,c50=0,c100=0,c500=0,call=0;
   cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
   call=c1*1+c5*5+c10*10+c50*50+c100*100+c500*500;
   if(call>=1000){
   cout << 1 << endl;
   }else{
   cout << 0 << endl;
   }
  return 0;
}

Measured memory_bytes: 1156
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp;

fn main() {
    let _n: u32 = read();
    let m: u32 = read();
    let mut l = 0;
    let mut r = 1 << 20;
    for _ in 0..m {
        let a: u32 = read();
        let b: u32 = read();
        l = cmp::max(l, a);
        r = cmp::min(r, b);
    }
    println!("{}", if r < l { 0 } else { r - l + 1 });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INF = 1LL << 60;

 int main() {
   ll K, ans = 0;

   cin >> K;

   vector<vector<ll>> memo(K + 1, vector<ll>(K + 1));
   vector<ll> ab;

   for (ll i = 1; i <= K; i++) {
     for (ll j = 1; j <= K; j++) {
       memo.at(i).at(j) = __gcd(i, j);
       ab.emplace_back(memo.at(i).at(j));
     }
   }

   for (ll v : ab) {
     for (ll i = 1; i <= K; i++) {
       ans += memo.at(v).at(i);
     }
   }

   cout << ans << endl;
 }


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll maxn=1000001,mod=1e9+7;

int main(){
sync

    int x;
    bool t[10];
    memset(t,false,sizeof(t));
    forn(i,4){
        cin>>x;
        t[x]=true;
    }
    if(t[1]&&t[4]&&t[7]&&t[9]){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
  
return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

    	Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] A = new long[n];

        long sumLength = 0;

        for (int i = 0; i < n; i++) {
            A[i] = sc.nextLong();
            sumLength += A[i];
        }

        long min_diff = Integer.MAX_VALUE;

        long sumLength0 = 0;

        for (int i = 0; i < n; i++) {
            sumLength0 += A[i];
            long diff = Math.abs((sumLength - sumLength0) - sumLength0);
            if (diff < min_diff) {
                min_diff = diff;
            }
        }
        System.out.println(min_diff);
    }
}

Measured memory_bytes: 65704
#include<stdio.h>
main()
{
    int a,b,c,i, count=0;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;i<=b;i++)
    {
        if(c%i==0) count++;

    }
    {
        printf("%d\n",count);
    }
}


Measured memory_bytes: 2064
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

struct Combination
{
  int mod;
  vector< int64_t > mfact, rfact;

  Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod)
  {
    mfact[0] = 1;
    for(int i = 1; i < mfact.size(); i++) {
      mfact[i] = mfact[i - 1] * i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for(int i = sz - 1; i >= 0; i--) {
      rfact[i] = rfact[i + 1] * (i + 1) % mod;
    }
  }

  int64_t fact(int k) const
  {
    return (mfact[k]);
  }

  int64_t pow(int64_t x, int64_t n) const
  {
    int64_t ret = 1;
    while(n > 0) {
      if(n & 1) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int64_t inv(int64_t x) const
  {
    return (pow(x, mod - 2));
  }

  int64_t P(int n, int r) const
  {
    if(r < 0 || n < r) return (0);
    return (mfact[n] * rfact[n - r] % mod);
  }

  int64_t C(int p, int q) const
  {
    if(q < 0 || p < q) return (0);
    return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
  }

  int64_t H(int n, int r) const
  {
    if(n < 0 || r < 0) return (0);
    return (r == 0 ? 1 : C(n + r - 1, r));
  }
};

signed main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	Combination comb(h + w, MOD);
	int ans = 0;
	rep (i, h - a) {
		int tmp = 0;
		tmp = comb.C(b - 1 + i, b - 1);
		tmp = (tmp * comb.C(w - b - 1 + h - i - 1, w - b - 1)) % MOD;
		ans = (ans + tmp) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328