akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int n,a,d,b;
    d=0;
    b=0;
    scanf("%d",&n);
    a=n;
    while(n!=0){
        n /= 10;
        d++;
    }
    if(d%2==0){
        d-=1;
        a=0;
    }
    else{
        a-=pow(10,d-1)-1;
        d-=2;
    }
    while(d>0){
        b+=pow(10,d)-1-(pow(10,d-1)-1);
        d-=2;
    }

    printf("%d\n",b+a);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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 n,m,S;
vector<vector<pair<int,P>>> G;
vector<ll> C,D;

void solve(){
	S = min(S,2500LL);
	vector<vector<ll>> dp(n,vector<ll>(3000,LINF));//dp[i][s] = 0からiに銀貨をs枚持って行くときかかる時間の最小値
	priority_queue<pair<ll,P>, vector<pair<ll,P>>,greater<pair<ll,P>> > q;
	dp[0][S] = 0;
	q.push(mp(0,mp(0,S)));
	while(!q.empty()){
		auto p = q.top();q.pop();
		ll time = p.fs;
		int v = p.sc.fs;
		ll s = p.sc.sc;
		if (time > dp[v][s])continue;

		if (s + C[v] <= 2500){//銀貨を追加する理由があるとき
			ll ns = s + C[v];
			ll ntime = time + D[v];
			if (chmin(dp[v][ns],ntime))q.push(mp(ntime,mp(v,ns)));
		}
		for(auto e:G[v]){
			if (s < e.second.fs)continue;//払えないとき
			int nv = e.fs;
			ll ns = s - e.second.fs;
			ll ntime = time + e.sc.sc;
			if (chmin(dp[nv][ns],ntime))q.push(mp(ntime,mp(nv,ns)));
		}

	}
	for(int i = 1; i < n; i++) {
		ll res = LINF;
		for(int s = 0; s <= 2500; s++) {
			chmin(res,dp[i][s]);
		}
		cout << res << endl;
	}
}

int main(){
	cin>>n>>m>>S;
	G.resize(n);
	for(int i = 0; i < m; i++) {
		ll u,v,a,b;cin>>u>>v>>a>>b;
		u--;v--;
		G[u].pb(mp(v,mp(a,b)));
		G[v].pb(mp(u,mp(a,b)));
	}

	for(int i = 0; i < n; i++) {
		ll c,d;cin>>c>>d;
		C.pb(c);
		D.pb(d);
	}
	solve();
	return 0;
}

Measured memory_bytes: 7456
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const int MAX_N=2e5,MAX_C=2e5;
int rawN,rawC[MAX_N];
int N,C[MAX_N];
ll dp[MAX_N+1],opt[MAX_C];
const ll MOD=1e9+7;
int main(){
	scanf("%d",&rawN);
	REP(i,rawN)scanf("%d",rawC+i);
	REP(i,rawN)rawC[i]--;
	N=0;
	REP(i,rawN){
		if(N==0 || C[N-1]!=rawC[i]){
			C[N++]=rawC[i];
		}
	}
	dp[0]=1;
	REP(i,N){
		dp[i+1]=(dp[i]+opt[C[i]])%MOD;
		opt[C[i]]+=dp[i];
		opt[C[i]]%=MOD;
	}
	printf("%lld\n",dp[N]);
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#pragma GCC                   target ("avx2")
#pragma GCC                   optimize("Ofast")
#pragma GCC                   optimization ("O3")
#pragma GCC                   optimization ("unroll-loops")
#pragma GCC                   target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod                   1000000007
#define INF                   1000000000000000000
#define int                   long long
#define PI                    3.141592653
#define Author                std::ios_base::sync_with_stdio(0);
#define ABHISHEK_SHARMA       cout.tie(0);
#define IIIT_ALLAHABAD        cin.tie(0);
#define all(v)                v.begin(),v.end()
#define pb(a)                 push_back(a)
#define lb(v,t)               lower_bound(all(v),t)-v.begin()
#define ub(v,t)               upper_bound(all(v),t)-v.begin()

clock_t time_p=clock();

void abhishhh1(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(double)(time_p)/(1.0*CLOCKS_PER_SEC)<<"\n";
}

void solve() {
    string s, t;
    cin>>s>>t;
    t.pop_back();
    if(s==t){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}

signed main(){
    //file reader-writer
    //Booster
    Author
    ABHISHEK_SHARMA
    IIIT_ALLAHABAD
    //Driver Code here
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    abhishhh1();
}

Measured memory_bytes: 3776
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	string S;
	int Q;
	cin >> S >> Q;

	bool rev = false;
	string f, b;
	for (int i = 0; i < Q; i++) {
		int q;
		cin >> q;
		if (--q) {
			int r;
			char c;
			cin >> r >> c;
			r--;
			r ^= rev;

			if (r) b += c;
			else f += c;
		}
		else rev ^= 1;
	}

	reverse(f.begin(), f.end());
	string ans = f + S + b;
	if (rev) reverse(ans.begin(), ans.end());

	cout << ans << "\n";

	return 0;
}



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

ll dp[20100];

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

  rep(i,n) {
    int w, s, v;
    cin >> w >> s >> v;
    t[i] = {{w,s},v};
  }
  sort(t.begin(), t.end(),[&](auto a, auto b) {
    return a.first.first + a.first.second < b.first.first + b.first.second;
  });

  for (int i = 0; i < n; i++) {
    for (int j = t[i].first.second; j >= 0; j--) {
      dp[j + t[i].first.first] = max(dp[j + t[i].first.first], dp[j] + t[i].second); 
    }
  }
  ll res = 0;
  for (int i = 0; i <= 20000; i++) {
    res = max(res, dp[i]);
  }
  cout << res << endl;
  return 0;
} 

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

string s;

int main() {
	cin >> s;
	string ans;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0')ans.push_back('0');
		else if (s[i] == '1')ans.push_back('1');
		else {
			if (ans.size() == 0)continue;
			else ans.pop_back();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n;
  int i = 0;
  float x1,y1,x2,y2,x3,y3,x4,y4;
  double a,b;

  scanf("%d",&n);

  while(scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) != EOF){

    if( i >= n )break;

    a = (y2 - y1) / (x2 - x1);
    b = (y4 - y3) / (x4 - x3);

    if( a == b ){
      printf("YES\n");
    }else{
      printf("NO\n");
    }

    i++;

  }

  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    Int ans = 0;
    for (int i = n-1; i >= 0; i--) {
        Int aa = ans + a[i];
        Int tmp = (Int)aa % b[i];
        if (tmp == 0) continue;
        //cout << ((Int)b[i] - tmp) << endl;
        ans += ((Int)b[i] - tmp);
    }   
    cout << ans << endl;
}

Measured memory_bytes: 4004
#include <iostream>

using namespace std;

long int rs(long int n,long int p,long int m){
  if(p == 0) return 1;
  else if(p %2 == 0){
    long int t = rs(n,p/2,m);
    return t * t % m;
  }
  else{
    return (n*rs(n,p-1,m)) % m;
  }
}

int main(void){
  long int M = 1000000007;
  long int n;
  cin >> n;
  int a,b;
  cin >> a >> b;
  long int count = rs(2,n,M);
  long int ax = n,ay = 1;
  for(int i = 2; i <= a;i++){
    ay = (ay * i)%M;
    ax = (ax * (n-i+1)) % M;
  }

  long int aa = rs(ay,M-2,M);

  long int bx = n,by = 1;
  for(int i = 2; i <= b;i++){
    by = (by * i)%M;
    bx = (bx * (n-i+1)) % M;
  }

  long int bb =  rs(by,M-2,M);
  long ans = (count - ((ax*aa)%M) - ((bx*bb)%M) - 1) % M;
  if(ans < 0) ans += M;
  cout << ans << endl;
  return 0;
}

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

void solve(long long N, vector<long long> L){
	SORT(L);
	vector<ll> s;
	ll res = 0;
	rep(i, N) {
		rep(j, N) {
			if (i >= j) continue;
			// cout << i << " " << j << ": " << POSL(L, L[i]+L[j]) << endl;
			res += max(POSL(L, L[i]+L[j])-1-j, 0LL);
		}
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> L(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&L[i]);
	}
	solve(N, L);
	return 0;
}



Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (n, k) = read_touple::<usize>();
    let p: Vec<f64> = read_vec();
    let mut e = vec![0.0; n];

    for i in 0..n {
      e[i] = (p[i] + 1.0) / 2.0;
    }

    let mut sum = vec![0.0; n+1];
    for i in 0..n {
      sum[i+1] = sum[i] + e[i];
    }

    let mut ans = 0.0;
    for i in 0..n+1-k {
      let x = sum[i+k] - sum[i];
      if ans < x {
         ans = x;
      }
    }
    println!("{}", ans);
}


Measured memory_bytes: 13044
#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__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	FOR(i, 1, 8) if (pow(2, i) > n) {
			cout << pow(2, i-1) << endl;
			break;
		    }
	
	return 0;
}


Measured memory_bytes: 4308
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int l, r, d;
    cin >> l >>r >> d;
    int ans = r / d;
    ans -= (l-1)/d;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3560
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    int n;
    vector<pair<int,int>> stu;
    cin >> n;
    
    rep(i,n){
        int a;
        cin >> a;
        stu.push_back(make_pair(a,i+1));
    }
    
    sort(all(stu));
    
    rep(i,n){
        cout << stu[i].second<<space;
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 1780
class RectangleCaliculator
  def calcArea(width, height)
    return width * height
  end

  def calcCircumference(width, height)
    return (width + height) * 2
  end
end

# 入力の横、縦の長さ取得
inputArray = gets.split(nil)
height = inputArray[0].to_i
width = inputArray[1].to_i

# 計算クラスを作成し、面積、周の長さを計算
rect = RectangleCaliculator.new
area = rect.calcArea(width, height)
circumference = rect.calcCircumference(width, height)

# 出力
puts area.to_s + " " + circumference.to_s

Measured memory_bytes: 6096
n = int(input())
s = input()
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alpha_dict = {}
res = ""
for idx, letter in enumerate(alphabet):
    alpha_dict.setdefault(letter, idx)
for char in s:
    tmp = alpha_dict[char] + n
    if tmp >= 26:
        res += alphabet[tmp - 26]
    else:
        res += alphabet[tmp]
print(res)


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;

int main()
{
	scanf("%d",&N);
	vector<ll> A(N * 3);
	FOR(i,0,N * 3){
		scanf("%lld",&A [i]);
	}
	sort(ALL(A));

	ll ans = 0;
	for(int i = N;i < N * 3;i += 2){
		ans += A [i];
	}
	printf("%lld\n",ans);

	return 0;
}


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

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

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll nC,nD,nCD;
    nC = b/c - (a-1)/c;
    nD = b/d - (a-1)/d;
    nCD = b/(c*d/gcd(c,d)) - (a-1)/(c*d/gcd(c,d));

    ll ans = b-a+1;
    ans -= nC+nD-nCD;
    cout << ans << endl;

    return 0;
}


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

#define MAX 1000000
#define NIL -1

vector<int>gGraph[MAX];
int color[MAX];

void dfs(int r,int c){
    stack<int>s;
    s.push(r);
    color[r] = c;
    while(!s.empty()){
        int u = s.top();
        s.pop();
        for(int i = 0;i < gGraph[u].size();++i){
            int v = gGraph[u][i];
            if(color[v] == NIL){
                color[v] = c;
                s.push(v);
            }
        }
    }
}

void assignColor(int number){
    int id = 1;
    for(int i = 0;i < number;++i){
        color[i] = NIL;
    }
    for(int i = 0;i < number;++i){
        if(color[i] == NIL)dfs(i,id++);
        
    }
}

int main(){
    int s,t,m,q,n;
    
    cin >> n >> m;
    
    for(int i = 0;i < m;++i){
        cin >> s >> t;
        gGraph[s].push_back(t);
        gGraph[t].push_back(s);
    }
    
    assignColor(n);
    
    cin >> q;
    
    for(int i = 0;i < q;++i){
        cin >> s >> t;
        if(color[s] == color[t]){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}



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

int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 1;i<=n;i++)
	{
		if(i%3==0||i%5==0);
		else
		{
			ans+=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  long long N, Q;
  cin >> N;

  vector<long long> A(N);
  long long tot = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    tot += A.at(i);
  }

  map<long long, long long> cnt;
  for (int x : A) {
    if (cnt.count(x)) {
      cnt.at(x)++;
    } else {
      cnt[x] = 1;
    }
  }

  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    long long B, C;
    cin >> B >> C;
    if (cnt.count(B)) {
      tot += (C - B) * cnt.at(B);
      cout << tot << endl;
      long long sz = cnt.at(B);
      cnt[C] += sz;
      cnt.at(B) -= sz;
    } else {
      cout << tot << endl;
      continue;
    }
  }
}


Measured memory_bytes: 8816
A = []
for i in range(5):
  a = int(input())
  A.append(a)
k = int(input())  
for i in range(5):
  for j in range(i,5):
    if A[j] -A[i] <= k:
      pass
    else:
      print(":(")
      quit()
print("Yay!")

Measured memory_bytes: 9116
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
c=[[] for i in range(N)]
for a,b in AB:
    c[a-1].append(b-1)
    c[b-1].append(a-1)
v=[1]+[0]*(N-1)
x=[0]
s=[]
parent=[-1]*N
child=[[] for i in range(N)]
while x:
    p=x.pop()
    s.append(p)
    for n in c[p]:
        if v[n]==0:
            v[n]=1
            x.append(n)
            parent[n]=p
            child[p].append(n)
m=10**9+7
fac=[1]*(N+10)
inv=[1]*(N+10)
ifac=[1]*(N+10)
for n in range(2,N+10):
    fac[n]=(fac[n-1]*n)%m
    inv[n]=m-inv[m%n]*(m//n)%m
    ifac[n]=(ifac[n-1]*inv[n])%m
size=[1]*N+[0]
dp=[1]*N+[0]
for n in s[::-1]:
    p=parent[n]
    size[p]+=size[n]
    dp[n]=dp[n]*fac[size[n]-1]%m
    dp[p]=dp[p]*ifac[size[n]]*dp[n]%m
size2=[N-v+1 for v in size]
dp2=[1]*N
for n in s[1:]:
    p=parent[n]
    dp2[n]=dp[p]*ifac[size[p]-1]*dp2[p]*ifac[size2[p]-1]*pow(dp[n],m-2,m)*fac[size[n]]*fac[size2[n]-2]%m
for i in range(N):
    print(dp[i]*dp2[i]*fac[size[i]+size2[i]-2]*ifac[size[i]-1]*ifac[size2[i]-1]%m)

Measured memory_bytes: 154192
n, m = map(int, input().split())
kind = [0 for i in range(m)]
for i in range(n):
    a = list(map(int, input().split()))
    k, a = a[0], a[1:]
    for j in range(k):
        kind[a[j]-1] += 1
count = 0
for i in kind:
    if i == n:
        count += 1
print(count)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#define N_MAX 10001
#define N_MIN 10000001
struct node{
  int key;
  int cost;
  struct node *next;
};
typedef struct node *Gg;
Gg G[N_MAX];
Gg MNode(int key,int cost,Gg Node){
  Gg n;
  n=(Gg)malloc(sizeof(struct node));
  n->key=key;
  n->cost=cost;
  n->next=Node;
  return n;
}
Gg insert(int s,int t,int u){
  Gg GG;
  GG=MNode(t,u,G[s]->next);
  G[s]->next=GG;
}
int main(){
  int i,j,n,count=0,v,c,c1,v1;
  int color[N_MAX],D[N_MAX],pi[N_MAX],minC,ii;
  Gg GG;
  scanf("%d",&n);
  for(i=0;i<n;i++)G[i]=MNode(0,0,NULL);
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&c);
    for(j=0;j<c;j++){
      scanf("%d%d",&v1,&c1);
      insert(i,v1,c1);
    }
  }
  for(i=0;i<n;i++){
    color[i]=0;
    pi[i]=-1;
    D[i]=N_MIN;
  }
  D[0]=0;
  while(1){
    minC=N_MIN;
    for(i=0;i<n;i++){
      if(color[i]!=2&&D[i]<minC){
	minC=D[i];
	ii=i;
      }
    }
    if(minC==N_MIN)break;
    color[ii]=2;
    for(GG=G[ii];GG!=NULL;GG=GG->next){
      if(color[GG->key]!=2&&(GG->cost+D[ii])<D[GG->key]){
	pi[GG->key]=ii;
	D[GG->key]=GG->cost+D[ii];
	color[GG->key]=1;
      }
    }
  }
  for(i=0;i<n;i++)
    printf("%d %d\n",i,D[i]);
  return 0;
}

Measured memory_bytes: 16256
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int INF = 1000000000;
const int MOD = 1e9 + 7;

llong prod(const vector<llong>& V, int upto = INF) {
   llong res = 1;
   REP(i, min(SZ(V), upto)) {
      int x = V[i];
      res = (res * x) % MOD;
      if (res < 0)
         res += MOD;
   }
   return res;
}

int solve(int N, int K, const VI& A) {
   assert(K <= N);
   vector<llong> pos, neg;
   int nzeros = 0;
   for (int x : A) {
      if (x > 0)
         pos.push_back(x);
      else if (x < 0)
         neg.push_back(x);
      else
         ++nzeros;
   }

   if (SZ(pos) + SZ(neg) < K)
      return 0;

   if (SZ(pos) + SZ(neg) == K) {
      if (SZ(neg) % 2 == 0 || nzeros == 0)
         return (prod(pos) * prod(neg)) % MOD;
      return 0;
   }

   sort(pos.begin(), pos.end(), greater<int>());

   if (SZ(neg) == 0) {
      // no negatives
      return prod(pos, K);
   }


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

   if (SZ(pos) == 0) {
      // no positives
      cerr << "HERE" << endl;
      if (K % 2 == 0) {
         return prod(neg, K);
      } else if (nzeros == 0) {
         reverse(neg.begin(), neg.end());
         return prod(neg, K);
      }
      else
         return 0;
   }

   DEBUG(pos);
   DEBUG(neg);

   int best_nneg = -1;
   for (int nneg = 0; nneg <= SZ(neg); nneg += 2) {
      int npos = K - nneg;
      DEBUG(nneg, npos);
      if (npos > SZ(pos)) continue;
      if (npos < 0) break;

      if (best_nneg < 0)
         best_nneg = nneg;

      if (npos == 0) {
         best_nneg = nneg;
         break;
      }
      if (nneg == 0 || npos+1 >= SZ(pos))
         continue;
      DEBUG(neg[nneg-2], neg[nneg-1], pos[npos], pos[npos+1]);
      if (neg[nneg-2] * neg[nneg-1] < pos[npos] * pos[npos+1])
         break;
      best_nneg = nneg;
   }

   DEBUG(best_nneg);
   assert(best_nneg >= 0);
   assert(best_nneg <= SZ(neg));

   int best_npos = K - best_nneg;
   assert(best_npos >= 0);

   return (prod(pos, best_npos) * prod(neg, best_nneg)) % MOD;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N, K;
   cin >> N >> K;
   VI A(N);
   REP(i, N)
      cin >> A[i];

   int res = solve(N, K, A);
   cout << res << endl;

   return 0;
}


Measured memory_bytes: 6212
def main():
    A, B = map(int, input().split())

    for x in range(10000):
        if int(x * 0.08) == A and int(x * 0.1) == B:
            print(x)
            return

    print(-1)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3064
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  n = int(input())
  a = LI()
  cnt = 0
  for i in range(1,n):
    if a[i-1] > a[i]:
      cnt += (a[i-1] - a[i])
      a[i] = a[i-1]
  print(cnt)
  
if __name__ == '__main__':
  main()

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

const int INF = 1000000000;
int n, k, h[101010], dp[101010];

int main(){
  cin >> n >> k;
  rep(i, n) cin >> h[i];
  rep(i, n) dp[i] = INF;
  dp[0] = 0;
  for(int i = 0; i < n - 1; i++){
    for(int j = 1; j <= k; j++){
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  rep(i, n) cerr << dp[i] <<" ";
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
import math
N,D = (int(i) for i in input().split())

X = []
for i in range(N):
  X.append([int(i) for i in input().split()])

count = 0

for i in range(N):
  for j in range(i+1,N):
    check_num = 0
    for k in range(len(X[i])):
      check_num += (X[i][k] - X[j][k])**2

    if float.is_integer(math.sqrt(check_num)):
      count += 1

print(count)


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

int max(int a, int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

int main()
{
    int a,b,c,mx;
    cin >> a >> b >> c;
    mx=max(max(a,b),c);
    if((mx*3-a-b-c)%2){
        cout << ((mx+1)*3-a-b-c-2)/2+1 << endl;
    }else{
        cout << (mx*3-a-b-c)/2 << endl;
    }
    return 0;
}

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

int main(){
  vector<int> t(5),sur(5),quo(5);
  int sum=0;
  for(int i=0;i<5;i++){
    cin >> t.at(i);
    sur.at(i)=t.at(i)%10;
    quo.at(i)=t.at(i)/10;
  }
  for(int i=0;i<5;i++){
    if (sur.at(i)==0){
      sur.at(i)=10;
    }
    else{
      quo.at(i)++;
    }
  }
  for(int i=0;i<5;i++){
    sum+=quo.at(i);
    sur.at(i)=10-sur.at(i);
  }
  sort(sur.begin(),sur.end());
  reverse(sur.begin(),sur.end());
  
  cout << sum*10-sur.at(0)<<endl;
}

Measured memory_bytes: 256
N = int(input())
hh = list(map(int, input().split()))

prev = -999
for i in range(N):
  if prev <= hh[i]-1:
    prev = hh[i]-1
  elif prev <= hh[i]:
    prev = hh[i]
  else:
    print('No')
    exit(0)

print('Yes')
exit(0)


Measured memory_bytes: 14252
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

bool is_prime(long long n)
{
    if (n == 1) {
        return false;
    }

    for (long long i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

int main()
{
    long long n;
    std::cin >> n;

    std::map<long long, bool> m;
    for (int i = 0; i < n; i++) {
        long long temp;
        std::cin >> temp;

        if (m[temp]) {
            std::cout << "NO" << std::endl;
            return 0;
        } else {
            m[temp] = true;
        }
    }

    std::cout << "YES" << std::endl;
}


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

using namespace std;
typedef long long int ll;


int main() {
	// your code goes here
	int k;
	cin>>k;
	
	int cnt=0;
    if(k<=9)
    cout<<k<<"\n";
    else
    {
        k=k-9;
        queue<ll>q;
        for(int i=1;i<=9;i++)
        q.push(i);
        
        int i=0;
        
        ll ans;
        while(i<k)
        {
            ll x=q.front();
            q.pop();
            if(x%10!=0)
            {
                q.push(x*10+(x%10-1));
                i++;
                if(i==k)
                {
                    ans=x*10+(x%10-1);
                    break;
                }
            }
            q.push(x*10+x%10);
            i++;
            if(i==k)
            {
              ans=x*10+(x%10);
              break;  
            }
            if(x%10!=9)
            {
                q.push(x*10+(x%10+1));
                i++;
                if(i==k)
                {
                    ans=x*10+(x%10+1);
                    break;
                }
            }
            
            
        }
        cout<<ans<<"\n";
        
        
    }
	return 0;
}


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

using namespace std;

int main(){
	
	while(1){
		
		int n;
		
		cin >> n;
		
		if(n==0) return 0;
		
		int count=0;
		
		for(int i=1;i<=n/2;i++){
			for(int j=i+1;j<=n/2+1;j++){
				int sum = (i+j)*(j-i+1)/2;
				if(sum==n){
					count += 1;
				}
			}
		}
		
		cout << count <<endl;
	}
}


Measured memory_bytes: 3096
sx, sy, tx, ty = map(int, input().split())

dx = abs(tx -  sx)
dy = abs(ty - sy)
print("U" * dy + "R" * dx + "D" * dy + "L" * dx, end="")
print("L" + "U" * (dy+1) + "R" * (dx+1) + "D" + "R" + "D" * (dy+1) + "L" * (dx+1) + "U")


Measured memory_bytes: 3060
// new day,new strength,new thougts
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) int((c).size())
#define REP(i,n)  for(int i=0;i<int(n);i++)
#define REPD(i,n) for(int i=int(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);i--)
#define all(s) (s).begin(),(s).end()
#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=2e5+10;
const ll mod=1e9+7;

ll a[maxn],sm[maxn];

ll ask(ll l,ll r,ll ng,ll tot){
    while(l<r){
	ll mid=(l+r)/2;
	ll x1=abs(2*sm[mid]-2*ng-tot);
	ll x2=abs(2*sm[mid+1]-2*ng-tot);
	if(x1>x2)
	    l=mid+1;
	else
	    r=mid;
    }
    return abs(2*sm[r]-2*ng-tot);
}

int main(){
    ll n;cin>>n;
    REP(i,n){
	cin>>a[i];
	sm[i]=(i==0?0:sm[i-1])+a[i];
    }

    ll ans=inf;
    FOR(i,1,n-3){
	ll d1=ask(0,i,0,sm[i]),d2=ask(i+1,n-1,sm[i],sm[n-1]-sm[i]);
	ll x1=(sm[i]+d1)/2,x2=(sm[n-1]-sm[i]+d2)/2;
	ll x3=sm[i]-x1,x4=sm[n-1]-sm[i]-x2;
	ans=min(ans,max(x1,max(x2,max(x3,x4)))-min(x1,min(x2,min(x3,x4))));
    }
    cout<<ans;
}


Measured memory_bytes: 3328
from sys import stdin
from collections import defaultdict

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

mod = 10 ** 9 + 7
g = defaultdict(int)

for i in range(N):
    tmp = 1
    a = A[i]
    g_tmp = defaultdict(int)
    while tmp <= A[i] ** 0.5:
        while tmp > 1 and a % tmp == 0:
            a //= tmp
            if tmp not in g_tmp:
                g_tmp[tmp] = 1
            else:
                g_tmp[tmp] += 1
        tmp += 1
    for j in g_tmp:
        if j not in g:
            g[j] = g_tmp[j]
        else:
            g[j] = max(g[j], g_tmp[j])
    if a > 1:
        if a not in g:
            g[a] = 1

l = 1
ans = 0
for i in g:
    l *= pow(i, g[i], mod)
    l %= mod
for a in A:
    ans += l * pow(a, mod - 2, mod)
    ans %= mod

print(ans)

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

using namespace std;

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


 long n,c;
long d[30][30];
long color[3][30];
int main(){

  cin >> n >> c;
 
 
  rep(i,c){
   rep(j,c) cin >> d[i][j];
  }
  
  rep(i,n){
   rep(j,n){
     long x;
     cin >> x;
    color[(i+j)%3][x-1]++; 
   }
  }
  
  long res=1000000000000;
  
  rep(i,c){
   rep(j,c){
   if(i==j) continue;
     rep(k,c){
      if(i==k||j==k) continue;
       long sum=0;
       rep(l,c) sum+=color[0][l]*d[l][i]+color[1][l]*d[l][j]+color[2][l]*d[l][k];
        res=min(sum,res);
     }
   }
  }

cout << res << endl;



}


Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  (n:a:b:c:_) <- fmap (map read . words) getLine :: IO [Int]
  ls <- replicateM n $ readLn :: IO [Int]
  print $ solve n (a,b,c) ls

solve n abc ls = minimum [ totalCost abc ls c | c <- replicateM n "abcn"]

totalCost :: (Int, Int, Int) -> [Int] -> String -> Int
totalCost (a,b,c) ls candidate = as + bs + cs
  where
    as = cost a . map fst . filter (\(_, x) -> x == 'a') $ zip ls candidate
    bs = cost b . map fst . filter (\(_, x) -> x == 'b') $ zip ls candidate
    cs = cost c . map fst . filter (\(_, x) -> x == 'c') $ zip ls candidate

cost _ [] = maxBound `div` 10 :: Int
cost a ls = 10 * length ls + abs (a - sum ls) - 10

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n,m;
  cin>>n>>m;
  vector<vecint> g(n);
  REP(i,m){
    int u,v;
    cin>>u>>v;
    --u;--v;
    g[u].push_back(v);
  }
  int s,t;
  cin>>s>>t;
  --s;--t;
  constexpr int INF = 1000000000;
  vector<vecint> d(3, vecint(n, INF));
  d[0][s] = 0;
  using T = tuple<int,int>;
  deque<T> q;
  q.emplace_back(0,s);
  while(!q.empty()) {
    int c,i;
    tie(c,i) = q.front();
    q.pop_front();
    int cst = (c == 2) ? 1 : 0;
    int nc = (c+1)%3;
    for (int dst : g[i]) {
      if (d[nc][dst] > d[c][i] + cst) {
        d[nc][dst] = d[c][i] + cst;
        if (cst == 0) {
          q.emplace_front(nc,dst);
        } else {
          q.emplace_back(nc,dst);
        }
      }
    }
  }
  if (d[0][t] == INF) {
    cout<<-1<<endl;
  } else {
    cout<<d[0][t]<<endl;
  }
  return 0;
}


Measured memory_bytes: 7296
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] a = new long[N];
		for (int i = 0; i < N; ++i) {
			a[i] = sc.nextLong();
		}
		long[] b = new long[N * (N + 1) / 2];
		int p = 0;
		for (int i = 0; i < N; ++i) {
			long sum = 0;
			for (int j = i; j < N; ++j) {
				sum += a[j];
				b[p] = sum;
				++p;
			}
		}
		long ans = 0;
		Arrays.sort(b);

		for (int t = 0; t < 42; ++t) {
			int[] cnt = new int[42];
			for (int i = 0; i < b.length; ++i) {
				if ((ans & b[i]) != ans)
					continue;
				for (int shift = 0; shift <= 41; ++shift) {
					if (((1L << shift) & b[i]) > 0 && ((1L << shift) & ans) == 0)
						++cnt[shift];
				}
			}
			for (int shift = 41; shift >= 0; --shift) {
				if (cnt[shift] >= K) {
					ans |= 1L << shift;
					break;
				}
			}
		}
		pw.println(ans);
		pw.close();
	}

	static class Scanner {
		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 boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			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() {
			return (int) nextLong();
		}
	}

	public static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 28720
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int d=scn.nextInt();
		int count=0;
		for(int q=1;q<=n;q++) {
			
			int x=scn.nextInt();
			int y=scn.nextInt();
			double dis=Math.sqrt((Math.pow(x, 2)+Math.pow(y, 2)));
			if(dis<=d)
				count++;
			
			
		}
		System.out.println(count);
		
	}

}


Measured memory_bytes: 59576
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define  rep(i,a,b) for(i=a;i<b;i++)
#define endl "\n"
#define ll long long int
#define ld long double
using namespace std;
int main()
{
IOS;
ll n,i;
cin>>n;
ll b[n-1],a[n],sum=0;
rep(i,0,n-1)
{
cin>>b[i];
a[i]=0;
}
a[n-1]=0;
a[0]=b[0];
a[1]=b[0];
rep(i,1,n-1)
{
    a[i+1]=b[i];
    a[i]=min(a[i],b[i]);
}
rep(i,0,n)
sum=sum+a[i];
cout<<sum;
return 0;
}



Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	s[3]='8';
	cout<<s<<endl;
}











Measured memory_bytes: 256
//Name: Illumination
//Level: 3
//Category: 探索,塗り潰し
//Note:

/*
 * 建物を軸にして考えると面倒なので，侵入可能なマスに隣接する建物を考える．
 * 侵入可能なマスは，一繋がりの白マスをたどっていくと盤面の外に出られるもの．
 * したがって，繋がっている白マスを塗り潰しながら建物と共有している辺の数を数え，
 * 塗り潰しの途中で外周に出たかどうかでこの辺の数が有効かどうかを決めればよい．
 */
#include <iostream>
#include <cassert>

using namespace std;

const int DR[6] = {0, -1, -1, 0, 1, 1};
const int DC[2][6] = {
    {-1, -1, 0, 1, 0, -1}, // Even
    {-1, 0, 1, 1, 1, 0}, // Odd
};

int W, H;
int field[102][102];
bool outside(int r, int c) {
    return r < 0 || H <= r || c < 0 || W <= c;
}
int paint_area(int r, int c, bool &valid) {
    field[r][c] = 2;
    int len = 0;
    for(int edge = 0; edge < 6; ++edge) {
        const int nr = r + DR[edge];
        const int nc = c + DC[r&1][edge];
        if(outside(nr, nc)) {
            valid = true;
        }
        else { // inside
            int obj = field[nr][nc];
            if(obj == 1) {
                ++len;
            }
            else if(obj == 0) {
                len += paint_area(nr, nc, valid);
            }
        }
    }
    return len;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> W >> H;
    for(int r = 1; r <= H; ++r) {
        for(int c = 1; c <= W; ++c) {
            cin >> field[r][c];
        }
    }
    W += 2;
    H += 2;
    /*
    for(int r = 0; r < H; ++r) {
        if(r % 2 == 1) cout << ' ';
        for(int c = 0; c < W; ++c) {
            cout << field[r][c] << ' ';
        }
        cout << endl;
    }
    */

    int ans = 0;
    for(int r = 0; r < H; ++r) {
        for(int c = 0; c < W; ++c) {
            if(field[r][c] == 0) {
                bool valid = false;
                int len = paint_area(r, c, valid);
                if(valid) ans += len;
                //cout << r << ' ' << c << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

set<int> all;
map<char, set<int> > variable;

set<int> operator|(const set<int>& a, const set<int>& b)
{
    set<int> ret = a;
    for(set<int>::iterator it=b.begin(); it!=b.end(); ++it)
        ret.insert(*it);
    return ret;
}

set<int> operator&(const set<int>& a, const set<int>& b)
{
    set<int>::iterator it1 = a.begin();
    set<int>::iterator it2 = b.begin();
    set<int> ret;
    while(it1 != a.end() && it2 != b.end()){
        if(*it1 == *it2){
            ret.insert(*it1);
            ++ it1;
            ++ it2;
        }else if(*it1 < *it2){
            ++ it1;
        }else{
            ++ it2;
        }
    }
    return ret;
}

set<int> operator~(const set<int>& a)
{
    set<int>::iterator it1 = a.begin();
    set<int>::iterator it2 = all.begin();
    set<int> ret;
    while(it2 != all.end()){
        if(it1 == a.end() || *it1 != *it2){
            ret.insert(*it2);
            ++ it2;
        }else{
            ++ it1;
            ++ it2;
        }
    }
    return ret;
}

set<int> operator^(const set<int>& a, const set<int>& b)
{
    return (a & ~b) | (~a & b);
}

set<int> solve(string s)
{
    int n = s.size();
    if(n == 1)
        return variable[s[0]];

    int brackets = 0;
    for(int i=n-1; i>=0; --i){
        if(s[i] == '(')
            ++ brackets;
        else if(s[i] == ')')
            -- brackets;
        else if(brackets == 0 && islower(s[i]) && s[i] != 'c'){
            set<int> a, b;
            a = solve(s.substr(0, i));
            b = solve(s.substr(i+1));

            set<int> ret;
            if(s[i] == 'u')
                return a | b;
            else if(s[i] == 'i')
                return a & b;
            else if(s[i] == 'd')
                return a & ~b;
            else
                return a ^ b;
        }
    }

    if(s[0] == 'c')
        return ~solve(s.substr(1));

    return solve(s.substr(1, n-2));
}

int main()
{
    for(;;){
        all.clear();
        variable.clear();

        for(;;){
            char c;
            int n;
            if(!(cin >> c >> n))
                return 0;
            if(c == 'R')
                break;

            for(int i=0; i<n; ++i){
                int a;
                cin >> a;
                all.insert(a);
                variable[c].insert(a);
            }
        }

        string s;
        cin >> s;
        set<int> ret = solve(s);

        if(ret.size() == 0)
            cout << "NULL" << endl;
        else{
            set<int>::iterator it = ret.begin();
            cout << *it;
            while(++ it != ret.end())
                cout << ' ' << *it;
            cout << endl;
        }
    }
}

Measured memory_bytes: 0
#include<stdio.h>
int main() {
	int a,b,d[52],e=0;
	char c;
	scanf("%d",&b);
	for (int i = 0; i < 52; i++) {
		d[i] = 0;
	}
	for (int i = 0; i < b; i++) {
		scanf("%c", &c);
		scanf("%c", &c);
		void putchar();
		scanf("%d", &a);
		void putchar();
		if (c=='S')e = 0;
		else if (c=='H')e = 13;
		else if (c=='C')e = 26;
		else if (c=='D')e = 39;
		
	d[e+a-1] = 1;
	
	}
	for (int i = 0; i < 52; i++) {
		if (d[i] == 0) {
			if(i/13==0)printf("S %d\n", i % 13+1);
			if (i / 13 == 1)printf("H %d\n", i % 13+1);
			if (i / 13 == 2)printf("C %d\n", i % 13+1);
			if (i / 13 == 3)printf("D %d\n", i % 13+1);
		}
	}
}

Measured memory_bytes: 1024
# C
n = int(input())
a = list(map(int, input().split()))

# 累積和ベクトルbを作成
a.reverse()
b = [0]*n
b[0] = a[0]
for i in range(1, n):
    b[i] = b[i-1]+a[i]
a.reverse()
b.reverse()

ans = 0
for i in range(n-1):
    ans += a[i]*b[i+1]

print(ans % (10**9+7))


Measured memory_bytes: 31404