akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int mod=1e9+7;
const int ptr=3;
int c[ptr],r[ptr];
ll quick(ll a,ll b=mod-2)
{
    ll ret=1;
    while(b)
    {
        if(b&1) ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}
int main()
{
    srand(time(NULL));
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<ptr;i++)
    {
        c[i]=rand()%998244353+10000;
        r[i]=quick(c[i]);
    }
    vc<ll> C(ptr);
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<ptr;j++)
        {
            if(s[i]=='+')
                C[j]=(C[j]+1)%mod;
            else if(s[i]=='-')
                C[j]=(C[j]-1+mod)%mod;
            else if(s[i]=='>')
                C[j]=C[j]*c[j]%mod;
            else C[j]=C[j]*r[j]%mod;
        }
    }
    map<vc<ll>,int> cnt;
    vc<ll> A(ptr,1),cur(ptr);
    ll ans=0;
    cnt[cur]++;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<ptr;j++)
        {
            if(s[i]=='+')
                cur[j]=(cur[j]-A[j]+mod)%mod;
            else if(s[i]=='-')
                cur[j]=(cur[j]+A[j])%mod;
            else if(s[i]=='>')
            {
                A[j]=A[j]*r[j]%mod;
            }
            else{
                A[j]=A[j]*c[j]%mod;
            }
        }
        vc<ll> tar=C;
        for(int j=0;j<ptr;j++) tar[j]=(cur[j]+tar[j]*A[j]%mod)%mod;
        ans+=cnt[tar];
        //dbg(i,cur,tar);
        cnt[cur]++;
    }
    print(ans);
}


Measured memory_bytes: 55172
#include<stdio.h>
#define N 10000
int main(void){
  int i,num,bi=-1,ci=0;
  int a[N]={0},b[N]={0},c[N]={0};

  for(i=0;((scanf("%d",&a[i]))==1);i++){}
  num=i;
  for(i=0;i<num;i++){
    if(1<=a[i] && a[i]<=10){
      bi++;
      b[bi]=a[i];
    }else if(a[i]==0){
      c[ci]=b[bi];
      ci++;
      b[bi]=0;
      bi--;
    }
  }
  for(i=0;c[i]!=0;i++){
    printf("%d\n",c[i]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;cin>>s;
  int s1=0,s2=0;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='0')s1++;
      else s2++;
    }
    else{
      if(s[i]=='0')s2++;
      else s1++;
    }
  }
  cout<<min(s1,s2)<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>

int main(void)
{
    int N;
    scanf("%d",&N);

    int i,q,r;
    for(i=9;i>0;i--){
        if(N%i == 0){
            q = N/i;
            break;
        }
    }
        if(0<q && q < 10){
            printf("Yes");
        }
        else printf("No");
    
    return 0;   
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#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 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 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))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { 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;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int k, n;
    cin >> k >> n;
    vi a(n+1);
    rep(i,n) {
        cin >> a[i];
    }
    vi dist(n);
    int sum = 0;
    rep(i, n) {
        if (!i) continue;
        dist[i-1] += a[i] - a[i-1];
        sum += dist[i-1];
    }
    int ans = sum;
    dist[n-1] = k - a[n-1] + a[0];
    rep(i, n+1) {
        sum -= dist[i];
        sum += dist[(i + n - 1) % n];
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
from collections import deque
K = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])
count = 1
while count <= K:
  num = queue.popleft()
  if num%10!=0:
    queue.append(num*10+num%10-1)
  queue.append(num*10+num%10)
  if num%10!=9:
    queue.append(num*10+num%10+1)
  count+=1
  
print(num)

Measured memory_bytes: 18832
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int c = 0;
  for (int i = 2; i < s.size() - 1; i++) {
    if (s[i] == 'C')
      c++;
  }
  if (c != 1) {
    cout << "WA" << endl;
    return 0;
  }
  c = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] >= 'A' && s[i] <= 'Z')
      c++;
  if (c != 2) {
    cout << "WA" << endl;
  } else {
    cout << "AC" << endl;
  }
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	
	if(n % 10 == 9) {
		cout << "Yes";
	} else if(n / 10 == 9) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 3612
/*
ID: vasu090
TASK: 
LANG: C++
*/
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define mp make_pair
#define pb push_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

int32_t main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int N; cin >> N;
	string S; cin >> S;
	
	int ans = 0;
	for(int i=0;i<N-2;i++){
		if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C') ans++;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 384
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn read_pair() -> (i64, i64) {
    let s = read_line();
    let mut it = s.split_whitespace().map(|s| s.parse().unwrap());
    let h = it.next().unwrap();
    let w = it.next().unwrap();
    (h, w)
}

fn main() {
    let (n, k) = read_pair();
    let ps: Vec<_> = (0..n).map(|_| read_pair()).collect();

    let mut ans = i64::max_value();

    let (mut xs, mut ys): (Vec<_>, Vec<_>) = ps.iter().cloned().unzip();
    xs.sort();
    ys.sort();

    for ix1 in 0..xs.len() {
        for ix2 in (ix1 + 1)..xs.len() {
            for iy1 in 0..ys.len() {
                for iy2 in (iy1 + 1)..ys.len() {
                    let x1 = xs[ix1];
                    let x2 = xs[ix2];
                    let y1 = ys[iy1];
                    let y2 = ys[iy2];

                    let mut cnt = 0;
                    for &(x, y) in ps.iter() {
                        if x1 <= x && x <= x2 && y1 <= y && y <= y2 {
                            cnt += 1;
                            if cnt >= k {
                                break;
                            }
                        }
                    }

                    if cnt >= k {
                        ans = std::cmp::min(ans, (x2 - x1) * (y2 - y1));
                    }
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;
void func()
{
	string N;
	cin >> N;
	
	long sum = 0;
	for (int i = 0; i < N.length(); ++i)
	{
		sum += N[i] - '0';
	}

	if(sum%9==0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}

int main() {
//	while(1)
	func();
	return 0;
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define repin(V,N) for(int i = 0; i < N; i++) {int tmp; cin >> tmp; V.push_back(tmp);}

using namespace std;

ll mypow(int n, int a){
    ll ans = 1;
    for(int i = a; i > 0; i--){
        ans = ans * n;
    }
    return ans;
}

void vinc(vector<int>* v, int n){
    for(int i = 0; i < n; i++){
        if((*v)[i] == 3){
            (*v)[i] = 0;
        }else{
            (*v)[i]++;
            break;
        }
    }
}

int main(){

    int n,a,b,c;

    vector<int> l;

    cin >> n >> a >> b >> c;

    repin(l,n)

    vector<int> v(8,0);

    ll cnt = mypow(4,n);
    int ans = INT_MAX;

    for(ll i = 0; i < cnt; i++){

        int tmpans = 0;
        vector<int> s(4,0);
        vector<int> mc(4,0);

        rep(j,n){
            s[v[j]] = s[v[j]] + l[j];
            mc[v[j]]++;
        }

        vinc(&v, n);

        if(mc[1] == 0 || mc[2] == 0 || mc[3] == 0) continue;

        rep(j,3){

            if(mc[j + 1] > 1) tmpans = tmpans + 10 * (mc[j + 1] - 1);
        }
        
        tmpans = tmpans + abs(a - s[1]) + abs(b - s[2]) + abs(c - s[3]);

        ans = min(ans,tmpans);
        
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define maxim INT_MAX
#define fi first
#define se second
#define INF 1e16
/* 1. If you can't keep solution in mind, then visualize it on a paper.
 * 2. Try to identify the type of problem - DP, Greedy, Graph, Constructive,
 * 	  Prefix/Suffix, Difference Array, BIT/Segment Tree, etc.
 * 3. Look at the problems from different perspectives - reverse the problem,
 * 	  add instead of delete (maybe?)
 * 4. Divide difficult solutions into cases and/or sequences.
 * 5. Use math rules to solve Nested Summation.
 * 6. Optimisation problems are generally solved with DP, greedy, binary search or brute-force.
 * 7. Try fixing a solution then proving we can't do better or worse than that.
 * ------------------------------------------------------------------
 */

int main()
{
    ll n,w;
    cin>>n>>w;
    ll k=0;
    ll ar[n+1];
    ll br[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>ar[i]>>br[i];
        k+=br[i];
    }
    ll dp[k+1];
    for(ll i=1;i<=k;i++)
        dp[i]=INF;
    dp[0]=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=k;j>=br[i];j--)
        {
            dp[j]=min(dp[j],dp[j-br[i]]+ar[i]);
        }
    }
    for(ll i=k;i>=0;i--)
    {
        if(dp[i]<=w)
        {
            cout<<i;
            return 0;
        }
    }

}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			var nm = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
			int n = nm[0];
			int m = nm[1];
			int[,] matrix = new int[n, m];
			for (int i = 0; i < matrix.GetLength(0); ++i) {
				var array = Console.ReadLine().Split(' ').Select(j => int.Parse(j)).ToArray();
				for (int j = 0; j < array.Length; ++j) {
					matrix[i, j] = array[j];
				}
			}

			int[] vector = new int[m];
			for (int i = 0; i < vector.Length; ++i) {
				var v = int.Parse(Console.ReadLine());
				vector[i] = v;
			}

			int[] answer = new int[n];
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					answer[i] += matrix[i, j] * vector[j];
				}
			}

			for (int i = 0; i < answer.Length; ++i) {
				Console.WriteLine($"{answer[i]}");
			}

			Console.ReadKey();
		}
	}
}


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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, k;

bool read() {
    if (!(cin >> n >> k))
        return false;

    return true;
}

void solve() {
    long double ans = 0;

    for (int i = 1; i <= n; ++i) {
        long double cur = 1;

        for (int x = i; x < k; x *= 2)
            cur *= 0.5;

        ans += cur;
    }

    cout << setprecision(10) << fixed << ans / n << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
k,n = map(int,input().split())
mod = 998244353

max_n = 5000
fac, finv, inv = [0]*max_n, [0]*max_n, [0]*max_n

def comInit(max_n):
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,max_n):
      fac[i] = fac[i-1]* i% mod
      inv[i] = mod - inv[mod%i] * (mod // i) % mod
      finv[i] = finv[i-1] * inv[i] % mod

comInit(max_n)

# 二項係数の計算
def com(n,k):
    if(n < k):
        return 0
    if( (n<0) | (k < 0)):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ex2 = [1]*1010
for i in range(1,1010):
    ex2[i] = (ex2[i-1]*2)%mod

ans = []
for j in range(2,k+2):
    tmp = 0
    x = (j-1)//2
    for i in range(j//2 + 1):
        comb1 = com(n+k-j,n-i)
        comb2 = (com(x,i) * ex2[i])%mod
        if(j%2==0):
            comb1 += com(n+k-j-1,n-i-1)
            comb1 %= mod
        tmp += comb1*comb2
        tmp %= mod

    ans.append(tmp)

ans2 = ans[:-1]
ans += ans2[::-1]
print('\n'.join(map(str,ans)))

Measured memory_bytes: 74648
#include<iostream>
 
using namespace std;
 
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if(a<=c){
    if(d<=b){
      cout<< d-c;
    }else if(b<=d && c<=b){
      cout << b-c;
    }else if(b<=c){
      cout << "0";
    }
  }
  else if(a>c){
    if(b<=d){
      cout << b-a;
    }else if(b>=d &&a<=d){
      cout << d-a;
    }else if(a>=d){
      cout <<"0";
    }
  } 
  
  return 0;
}


Measured memory_bytes: 256
n=parse(Int,readline())
a=map(x->parse(Int,x),split(readline()))
s=[0]
for i=1:n
	push!(s,s[i]+a[i])
end
function f(L,R)
	sum=div(s[R]+s[L],2)
	l=L
	r=R-1
	while r-l>1
		m=div(r+l,2)
		if s[m]>sum
			r=m
		else
			l=m
		end
	end
	k=r
	c=s[k]-s[L]
	d=s[R]-s[k]
	k-=1
	if k>L
		C=s[k]-s[L]
		D=s[R]-s[k]
		if max(c,d)-min(c,d)>max(C,D)-min(C,D)
			return min(C,D),max(C,D)
		end
	end
	min(c,d),max(c,d)
end
ans=s[n+1]
for i=3:n-1
	x,z=f(1,i)
	y,w=f(i,n+1)
	ans=min(ans,max(z,w)-min(x,y))
end
println(ans)


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

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

using namespace std;

int n;
char vvc[300][600];

bool checkc(int ii){
    REP(i,n){
        REP(j,n){
            if(vvc[i][j+ii] != vvc[j][i+ii]) return false;
        }
    }
    return true;
}

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

    cin >> n;
    REP(i,n){
        REP(j,n){
            char c;
            cin >> c;
            vvc[i][j] = vvc[i][j+n] = c;
        }
    }

    ll ans=0;
    REP(i,n) if(checkc(i)) ans += n;
    cout << ans << endl;
    return 0;
}


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

struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for(int i = 0; i < N; i++) par[i] = i;
  }
 
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
 
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main(void){

    ll N,M,K;cin>>N>>M>>K;
    vector<ll> A(M),B(M),C(K),D(K);
    UnionFind tree(N);
    vector<vector<ll>> bs(N,vector<ll>());
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--;B[i]--;
        tree.unite(A[i],B[i]);
        bs[A[i]].push_back(B[i]);
        bs[B[i]].push_back(A[i]);
    }
    for(int i=0;i<K;i++){
    cin>>C[i]>>D[i];
    C[i]--;D[i]--;
    bs[C[i]].push_back(D[i]);
    bs[D[i]].push_back(C[i]);
    }

    vector<ll> roots(N);
    vector<ll> roots_sum(N);
    for(int i=0;i<N;i++){
        roots[i] = tree.root(i);
        roots_sum[roots[i]]++;
    }
    for(int i=0;i<N;i++){
        ll res = roots_sum[roots[i]];
        res--;
        for(int j=0;j<bs[i].size();j++){
            if(roots[bs[i][j]] == roots[i])res--;
        }
        cout<<res<<" ";
    }
  
  //for(int i=0;i<N;i++)cout<<roots[i]<<" ";

    return 0;
}

Measured memory_bytes: 14720
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()

def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret

print(dfs('0'))

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

int main(){
  int i,j,cnt=0;
  string s;
  cin>>s;
  int ma=0,mi=INT_MAX;
  for(i=0;i<26;i++){
    ma=0;
    cnt=-1;
    for(j=0;j<s.size();j++){
      if(s[j]=='a'+i){
        ma=max(j-cnt-1,ma);
        cnt=j;
      }
    }
    ma=max(j-cnt-1,ma);
    mi=min(mi,ma);
  }
  cout<<mi;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = if N % 500 <= A { "Yes" } else { "No" };

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 2019;

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

  int64_t N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (auto& a : A) {
    cin >> a;
    a--;
  }
  int64_t prologue = 0;
  int64_t loop_size = 0;
  int64_t hopcnt = 0;
  int loop_start_idx = -1;
  vector<int> loop;

  vector<bool> visited(N, false);
  int idx = 0;
  for (int i = 0; i <= N; i++) {
    if (visited[idx] == true) {
      loop_start_idx = idx;
      break;
    } else {
      visited[idx] = true;
      idx = A[idx];
      hopcnt++;
    }
  }
  //cout << "start:" << loop_start_idx << endl;
  
  idx = 0;
  for (int i = 0; i <= N; i++) {
    if (idx == loop_start_idx) {
      break;
    } else {
      prologue++;
      idx = A[idx];
    }
  }
  loop_size = hopcnt - prologue;
  //cout << "p_size:" << prologue << endl;
  //cout << "l_size:" << loop_size << endl;

  if (K < prologue) {
    idx = 0;
    for (int i = 0; i < K; i++) {
      idx = A[idx];
    }
  } else {
    K -= prologue;
    int offset = K % loop_size;
    idx = loop_start_idx;
    for (int i = 0; i < offset; i++) {
      idx = A[idx];
    }
  }
  cout << idx + 1 << endl;
  return 0;
}



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

int main() {

    int N, D;
    cin >> N >> D;
    int X[N][D];
    rep(i, N) rep(j, D) cin >> X[i][j];

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i+1; j < N; ++j)
        {
            int norm = 0;
            for (int k = 0; k < D; ++k)
            {
                int diff = abs(X[i][k] - X[j][k]);
                norm += diff * diff;
            }
            bool flag = false;
            for (int k = 0; k <= norm; ++k)
            {
                if (k * k == norm)
                {
                    flag = true;
                }
            }
            if (flag) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> ans(2*h, vector<char>(w));

    for(int i = 0; i < 2*h; i += 2)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> ans[i][j];
        }
        for(int j = 0; j < w; j++)
        {
            ans[i+1][j] = ans[i][j];
        }
    }

    for(int i = 0; i < 2*h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cout << ans[i][j];
        }
        cout << endl;
    }
}



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

int main(){
    int A, B, C; cin>>A>>B>>C;
    int cnt=0;
    if(A==B) cnt++;
    if(A==C) cnt++;
    if(B==C) cnt++;
    if(cnt==1){
        cout<<"Yes"<<endl;
        return 0;
    }

    cout<<"No"<<endl;
}


Measured memory_bytes: 3628
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
MOD = 10**9 + 7
h = Array.new(n) { 0 }
a.each do |e|
  h[e] += 1
end
if n % 2 == 0
  (0..n-1).each do |i|
    if (i % 2 == 0 && h[i] != 0) || (i % 2 == 1 && h[i] != 2)
      puts 0
      exit
    end
  end
  puts 2 ** (n/2) % MOD
else
  if h[0] != 1
    puts 0
    exit
  end
  (1..n-1).each do |i|
    if (i % 2 == 1 && h[i] != 0) || (i % 2 == 0 && h[i] != 2)
      puts 0
      exit
    end
  end
  puts 2 ** ((n-1)/2) % MOD
end


Measured memory_bytes: 9100
#include<set>
#include<stack>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const int MAXN = 100011;
int N;
int U[MAXN];
set<int> G[MAXN], H[MAXN];

int root(int x) {
    return U[x] == x? x: U[x] = root(U[x]);
}


void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	U[i] = i;
    }

    stack<pair<int, int> > st;
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].insert(y);
	G[y].insert(x);
	st.emplace(x, y);
    }
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	H[x].insert(y);
	H[y].insert(x);
	st.emplace(x, y);
    }
    while (!st.empty()) {
	int x = root(st.top().first);
	int y = root(st.top().second);
	st.pop();

	if (x == y) continue;
	if ((G[x].count(y) || G[y].count(x)) && (H[x].count(y) || H[y].count(x))) {
	    if (G[x].size() + H[x].size() > G[y].size() + H[y].size()) {
		swap(x, y);
	    }
	    EACH (e, G[x]) {
		int z = root(*e);
		if (z != x) {
		    G[y].insert(z);
		    st.emplace(y, z);
		}
	    }
	    G[x].clear();
	    EACH (e, H[x]) {
		int z = root(*e);
		if (z != x) {
		    H[y].insert(z);
		    st.emplace(y, z);
		}
	    }
	    H[x].clear();
	    U[x] = y;
	}
    }

    bool yes = (*min_element(U, U+N) == *max_element(U, U+N));
    puts(yes? "YES": "NO");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 30464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
using ll = long long;

const int INF = (int) 1e9 + 9;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    vi score(n, k-q);
    int a = 0;
    rep(i, 0, q) {
        cin >> a;
        --a;
        score[a]++;
    }
//    for (int x : score) cout << x << '\n';
    rep(i, 0, n) {
        if (score[i] > 0) puts("Yes");
        else puts("No");
    }

    return 0;
}


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

int cul(int n1, int n2);

int main() {
		int t[4], n[4];
		for(int i = 0; i < 4; i++){
			cin >> t[i] >> n[i];
		}
		for(int i = 0; i < 4; i++){
			cout << cul(t[i], n[i]) << endl;
		}
	return 0;
}

int cul(int n1, int n2){
	switch(n1){
		case 1:
			return (6000 * n2);
			break;
		case 2:
			return (4000 * n2);
			break;
		case 3:
			return (3000 * n2);
			break;
		case 4:
			return (2000 * n2);
			break;
		default:
			break;
	}
	
	
}

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

void calc(string s,int n){
    string ss=s.substr(0,n/2);
    string tt=s.substr(n/2,n/2);
    if(ss==tt){
        cout1(n)
        exit(0);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    int n=s.size();
    while(n-2>0){
        n-=2;
        calc(s.substr(0,n),n);
    }
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val H = IntArray(N) { sc.next().toInt() }
        var prev = H[0]
        H.forEach { h ->
            if (h < prev) {
                pw.println("No")
                return
            } else if (h != prev) {
                prev = h - 1
            }
        }
        pw.println("Yes")
    }
}


Measured memory_bytes: 44424
using System;

namespace AtC168
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int len = N.Length;
            char X = N[len - 1];
            string ans = "";
            if (X == '2' || X == '4' || X == '5' || X == '7' || X == '9') ans = "hon";
            else if(X == '0' || X == '1' || X == '6' || X == '8') ans = "pon";
            else ans = "bon";

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 25804
n = int(input())
a = list(map(int, input().split()))

prod = 1
frg_overflow = False

if 0 in a:
  print(0)
else:
  for i in range(n):
    if prod <= 10**18:
      prod = prod * a[i]
    else:
      frg_overflow = True
  if frg_overflow == True:
    print(-1)
  elif prod > 10**18:
    print(-1)
  else:
    print(prod)

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

int main() {
    ll n, p;
    string s;
    cin >> n >> p >> s;
    if(p == 2 || p == 5){
        ll ans = 0;
        rep(i, n) {
            if(ll(s[i] - '0') % p == 0){
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    ll tens = 1, running = 0, ans = 0;
    map<ll, ll> counter;
    counter[0] = 1;
    for (ll i = n - 1; i >= 0; i--) {
        running += (s[i] - '0') * tens;
        running %= p;
        tens *= 10;
        tens %= p;
        ans += counter[running]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4128
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))


def main():
    mod=10**9+7
    N,K=MI()
    
    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return (fact[n] * factinv[r] * factinv[n-r])%mod

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]

    for i in range(2, N*2 + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)

    ans=0
    
    #空き部屋がk個
    for i in range(min(K+1,N)):
        a=i#動く人
        b=N-i#割り当てる部屋
        temp=cmb(a+b-1,a,mod)
        
        #空き部屋の選び方
        temp2=cmb(N,i,mod)
        temp*=temp2
        
        ans=(ans+temp)%mod
        
    print(ans)
        
    

main()


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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    vector<int> a( N );
    REP( i, N ) cin >> a[i];

    int ans = 0;
    REP( i, a.size() - 1 ){
        for( int j = i + 1; j < a.size(); j++ ){
            ans += a[i] * a[j];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;


ll cmb[100][100];
int main(){
   rep(i, 55){
      rep(j, i + 1){
         if(j == 0 || j == i)cmb[i][j] = 1;
         else cmb[i][j] = cmb[i - 1][j - 1] + cmb[i - 1][j];
      }
   }
   int n, a, b;
   cin >> n >> a >> b;
   a--;b--;
   vector<ll> v(n);
   map<ll, ll> mp;
   rep(i, n){
      cin >> v[i];
      mp[v[i]]++;
   }
   sort(ALL(v), greater<ll>());
   ll sum = 0;
   long double res = 0;
   vector<int> que;
   rep(i, a)sum += v[i];
   REP(i, a, b){
      sum += v[i];
      if(res < (long double)sum / (i + 1)){
         que = vector<int>(0);
         que.push_back(i);
         res = (long double)sum / (i + 1);
      }
      else if(res == (long double)sum / (i + 1)){
         que.push_back(i);
      }
   }
   map<ll, ll> mpp;
   que.push_back(INF);
   ll ans = 0;
   rep(i, n){
      mpp[v[i]]++;
      if(i == *lower_bound(ALL(que), i)){
         ll tmp = 1;
         for(auto p : mpp){
            tmp *= cmb[mp[p.first]][p.second];
         }
         ans += tmp;
      }
   }
   cout << fixed << setprecision(10) << res << endl;
   cout << ans << endl;
   //rep(i, (int)que.size())cout << que[i] << " ";
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define mod 1000000007
#define abdo(); std::ios_base::sync_with_stdio(0);cin.tie(NULL);
#define lowcase(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define uppcase(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define M 80
#define LENGTH 12
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
typedef vector<int> vi;
const double PI = acos(-1.0);
int dir_r[] = {1       , 0    , -1, 0   , -1     , 1         , -1      , 1        };
int dir_c[] = {0       , 1    , 0 , -1  , -1     , 1         , 1       , -1       };



int main(void)
{
    //freopen("colors.in", "r", stdin) ;
    //freopen("auxiliary.out", "w", stdout);
    int n, k, index, res; cin >> n >> k;
    index = k;
    k--;


    vi v(n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &v[i]);
    }
    sort(all(v));
    res = v[k] - v[0];
    for(int i = 1; i < n - k; i++, index++)
        res = min(res, v[index] - v[i]);
    cout << res;

}



Measured memory_bytes: 640
#include <assert.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>

 
using namespace std;

typedef string str;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define trav(a, x) for (auto &a : x)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define PRINT_ARRAY(a, N)        \
  F0R(z, N) cout << a[z] << " "; \
  cout << "\n"
 
const int MOD = 1000000007;  // 998244353;
const ll INF = 1e18;
const ld PI = 4 * atan((ld)1);


int main() {
		ll K;
		string s;
		cin >> K >> s;

		if ((int) s.size() > K) {
				cout << s.substr(0, K) << "..." << endl;
		} else {
				cout << s << endl;
		}

}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Optional;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int[] white = new int[n + 1];
    int[] black = new int[n + 1];
    for (int i = 0; i < s.length(); i++) {
      white[i + 1] = white[i] + (s.charAt(i) == '.' ? 1 : 0);
      black[i + 1] = black[i] + (s.charAt(i) == '#' ? 1 : 0);
    }
    int min = n;
    for (int i = 0; i < s.length() + 1; i++) {
      min = Math.min(min, black[i] + white[n] - white[i]);
    }
    System.out.println(min);
  }
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    mp[t]++;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (mp[i] >= i) {
      sum += i;
    }
  }
  cout << n - sum << endl;
  return 0;
}


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

int main () {
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    }
}




Measured memory_bytes: 26264
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;
const int tree_size = (1 << 19);

struct zapr {
    ll l, r, ind;
};
ll n, q, mas[500005], x, y, ans[500005], kz, last[500005], uc, tree[tree_size * 2];
zapr a[500005], p;
set<ll> myset;
bool fcmp(const zapr& a, const zapr& b) {
    return (a.r < b.r);
}
void upd(ll ind, ll elem) {
    ind += (tree_size - 1);
    tree[ind] = elem;
    ind >>= 1;
    while (ind > 0) {
        tree[ind] = tree[ind * 2] + tree[ind * 2 + 1];
        ind >>= 1;
    }
}
ll sum(ll l, ll r, ll tecl, ll tecr, ll ind) {
    if (tecr < l || tecl > r)
        return 0;
    if (tecr <= r && tecl >= l)
        return tree[ind];
    ll one = sum(l, r, tecl, (tecr + tecl) / 2, ind * 2);
    ll two = sum(l, r, (tecr + tecl) / 2 + 1, tecr, ind * 2 + 1);
    return (one + two);
}
ll get_sum(ll l, ll r) {
    return sum(l, r, 1, tree_size, 1);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for (ll i = 1; i <= n; ++i)
        cin >> mas[i];
    for (ll i = 1; i <= q; ++i) {
        cin >> x >> y;
        p.l = x;
        p.r = y;
        p.ind = i;
        a[++kz] = p;
    }
    sort(a + 1, a + q + 1, fcmp);
    for (ll i = 1; i <= n; ++i)
        last[i] = -inf;
    uc = 1;
    for (ll i = 1; i <= q; ++i) {
        while (uc <= a[i].r) {
            if (last[mas[uc]] != -inf)
                upd(last[mas[uc]], 0);
            last[mas[uc]] = uc;
            upd(uc, 1);
            ++uc;
        }
        ans[a[i].ind] = get_sum(a[i].l, a[i].r);
    }
    for (ll i = 1; i <= q; ++i)
        cout << ans[i] << endl;
    return 0;
}


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

using namespace std;

int a[100001],b[100001],c[100001],A,B,C,n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>> n >> a[0] >> b[0] >> c[0];
    for(int i=1; i < n;i++)
    {
        cin>> A >> B >> C;
        a[i]=max(b[i-1],c[i-1])+A;
        b[i]=max(a[i-1],c[i-1])+B;
        c[i]=max(a[i-1],b[i-1])+C;
    }
    cout << max(max(a[n-1],b[n-1]),c[n-1]);
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}
ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

int main(void){
  int n,m;
  INI(n);
  INI(m);
  int a;
  FOR(i,m){
    INI(a);
    n-=a;
  }
  if(n<0){
    PRN(-1);
  }else{
    PRN(n);
  }
  return 0;
}

Measured memory_bytes: 1720
n = map(int, raw_input().split(' '))[0]


def dfs(i, mx, n, res, cur = []):
	if i==n:
		res.append(''.join(cur[::]))
		return


	for v in range(0, mx + 1):
		dfs(i + 1, mx + (1 if v == mx else 0), n , res, cur + [chr(v+ ord('a'))])

res =[]
dfs(0,0,n,res)
for w in res: print w

Measured memory_bytes: 47516
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
void solve(){
     //cout<<fixed<<setprecision(10);
     double x;
     cin>>x;
     x=2*(3.14000)*x;
     cout<<x;
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


Measured memory_bytes: 3796
#include <cstdint>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

int main(void)
{
    int64_t n, k;
    std::cin >> n >> k;

    std::vector<int64_t> h(n);
    std::vector<int64_t> costs(n);

    for (int64_t i=0; i < n; ++i) {
        std::cin >> h.at(i);
    }

    for (int64_t i=0; i < n; ++i) {
        int64_t min_cost = INT64_MAX;
        for (int64_t j=i-k; j < i; ++j) {
            if (i == j || j < 0) continue;
            int64_t cost = costs.at(j);
            cost += std::abs(h.at(j) - h.at(i));
            min_cost = std::min(min_cost, cost);
        }
        if (min_cost == INT64_MAX) min_cost = 0;
        costs.at(i) = min_cost;
    }

    std::cout << costs.at(n-1) << std::endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
  int A, B, K, ans[100]={}, SumAmari;
  cin >> A >> B >> K;
  int j = 0;
  for(int i=min(A,B); i>0; i--){
    SumAmari = A%i + B%i;
    if(SumAmari==0){
      ans[j]=i;
      j++;
    } 
  }
  cout << ans[K-1] << endl;
}

Measured memory_bytes: 256
N = int(input())
W = [[0, 0] for _ in range(N)]
for i in range(N):
  A, B = map(int, input().split())
  W[i] = [B, A]
W.sort()
t = 0
for b, a in W:
  if b < t + a:
    print('No')
    break
  t += a
else:
  print('Yes')

Measured memory_bytes: 35616