akhauriyash/Code-Regression huggingface dataset:
def counter(n):
	temp = n
	c = 0
	while temp != 0:
		c += temp & 1
		temp = temp >> 1
	return c % 2

def main():
	n,m = map(int,input().split())
	light = []
	for i in range(m):
		line = list(map(int, input().split()))
		temp = 0
		for j in line[1:]:
			temp += 2 ** (j-1)
		light += [temp]
	lst = list(map(int,input().split()))
	ans = 0
	for i in range(2**(n)):
		flg = True
		for j in range(m):
			if lst[j] != counter(light[j] & i):
				flg = False
				break
		if flg:
			ans += 1
	print(ans)

main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<vector>
using namespace std;
//string sss[12500000];
vector<int> g[100000];
vector<int> gp[100001];
int p[100000];
int ch[100000];
int A[100000], B[100000];
int main() {


	int i, j, k;
	int n, m;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	int a, b;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	queue<int> que;
	int chmax = 1;

	//cout << 1 << endl;
	for (i = 0; i < n; i++) {

		if (ch[i] == 0) {
			que.push(i);
			ch[i] = chmax;
			gp[chmax].push_back(i);
			//cout << "gp[" << chmax << "]push(" << i << ")" << endl;
			while (que.size()) {

				j = que.front(); que.pop();
				for (k = 0; k < g[j].size(); k++) {
					if (ch[g[j][k]] == 0) {
						que.push(g[j][k]);
						ch[g[j][k]] = chmax;
						gp[chmax].push_back(g[j][k]);
						//cout << "gp[" << chmax << "]push(" << g[j][k] << ")" << endl;
					}
				}

			}
			chmax++;
		}

	}

	//cout << 1 << endl;

	int counter = 0;
	for (i = 1; i < chmax; i++) {
		for (j = 0; j < gp[i].size(); j++) {
			A[j] = gp[i][j];
			B[j] = p[gp[i][j]];
		}
		sort(A, A + gp[i].size());
		sort(B, B + gp[i].size());
		
		//cout << "i = " << i << endl;
		//for (j = 0; j < gp[i].size(); j++) {
		//	cout << "A[" << j << "]= " << A[j] << endl;
		//	cout << "B[" << j << "]= " << B[j] << endl;

		//}
		
		
		a = 0; b = 0;
		while (a < gp[i].size() && b < gp[i].size()) {
			if (A[a] == B[b]) {
				counter++;
				a++;
				b++;
			}
			else if (A[a] < B[b]) {
				a++;
			}
			else {
				b++;
			}
		}
	}
	cout << counter << endl;
	return 0;





	/*string s;
	cin >> s;
	int k;
	cin >> k;
	int i, j;
	string ss;
	int l = 0;
	//priority_queue<string, vector<string>, greater<string>> que;
	for (i = 0; i < s.size(); i++) {
		ss = "";
		for (j = i; j < s.size(); j++) {
			ss = ss + s[j];
			sss[l] = ss;
			l++;
			if (j > i + 6)break;
		}
	}
	ss = "";
	sort(sss, sss + l);
	for(i = 0;i<l;i++){
		if (ss != sss[i]) {
			ss = sss[i];
			k--;
			//cout << ss << endl;
		}
		if (k == 0) {
			cout << ss << endl;
			return 0;
		}
	}*/

}

Measured memory_bytes: 13120
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

class Combination_Mod{
    public:
        Combination_Mod(long long MAX, long long MOD) : fact(MAX + 1), inv(MAX + 1), finv(MAX + 1), MAX(MAX + 1), MOD(MOD){
            init();
        }

        void init(){
            fact[0] = fact[1] = 1;
            finv[0] = finv[1] = 1;
            inv[1] = 1;
            for(long long i = 2; i < MAX; ++i){
                fact[i] = fact[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] *  (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
            }
        }

        long long bin(long long n, long long r){
            if(n < r || n < 0 || r < 0) return 0;
            return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD;
        }

        long long perm(long long n, long long r){
            return (bin(n, r) * fact[r]) % MOD;
        }

        long long factorial(long long n){
            return fact[n];
        }

        long long modinv(long long n){
            return inv[n];
        }

        long long modfinv(long long n){
            return finv[n];
        }

    private:
        vector<long long> fact;
        vector<long long> inv;
        vector<long long> finv;
        const long long MAX;
        const long long MOD;
};

ll modpow(ll x, ll n){
    ll ret = 1;
    while(n > 0){
        if(n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n = (n >> 1);
    }
    return ret;
}

ll inv[200010], finv[200010];

// return nCr
long long combination(long long n, long long r){
    r = (r < n - r) ? r : n - r;
    long long c = 1;
    for(long long k = 1; k <= r; ++k){
        c = (c * n) % MOD * inv[k];
        c %= MOD;
        n--;
    }
    return c;
}

Combination_Mod c(200010, MOD);

signed main(){
    ll n, a, b;
    cin >> n >> a >> b;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR(i, 2, 200010){
        inv[i] = MOD - inv[MOD % i] *  (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
    PRINT((modpow(2, n) + MOD - combination(n, a) + MOD - combination(n, b) + MOD - 1) % MOD);
    return 0;
}

Measured memory_bytes: 11156
<?php
fscanf(STDIN, '%d', $n);
$arr = [];
$tmp = [];
for($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s', $s);
    $tmp[] = $s;
    $arr[$s] = 0;
}
ksort($arr);

foreach($tmp as $v) {
    if(array_key_exists($v, $arr)) $arr[$v]++;
}
//var_dump($arr);

$max_v = max($arr);
foreach($arr as $k => $v) {
    if($v == $max_v) echo $k, PHP_EOL;
}

Measured memory_bytes: 28916
S = int(raw_input())

X1 = 0
Y1 = 0
X2 = 10**9
Y2 = 1

mod = 10**9

if S%mod == 0:
    X3 = 0
    Y3 = S/mod
else:
    Y3 = S/mod + 1
    X3 = mod - S%mod


print X1, Y1, X2, Y2, X3, Y3


Measured memory_bytes: 2568
def atc_079a(input_value: str) -> str:
    n = 3
    for i in range(0, len(input_value) + 1 - n):
        for j in range(1, n):
            if input_value[i] != input_value[i + j]:
                break
            if j == n - 1:
                return "Yes"
    return "No"


input_value = input()
print(atc_079a(input_value))

Measured memory_bytes: 8972
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    private static int MIN_XY = -100;
    private static int MAX_XY = 100;
    private static int MIN_WHR = 0;
    private static int MAX_WHR = 100;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int[] w_h_x_y_r = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            if (w_h_x_y_r.length != 5) {
                System.out.println("Condition is invalid.");
            }
            int w = w_h_x_y_r[0];
            int h = w_h_x_y_r[1];
            int x = w_h_x_y_r[2];
            int y = w_h_x_y_r[3];
            int r = w_h_x_y_r[4];
            if (w > MAX_WHR || w < MIN_WHR || h > MAX_WHR || h < MIN_WHR
                    || r > MAX_WHR || r < MIN_WHR || x > MAX_XY || x < MIN_XY
                    || y > MAX_XY || y < MIN_XY) {
                System.out.println("Condition is invalid.");
            }
            if (0 > x - r || 0 > y - r
            || w < x + r || h < y + r) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 32096
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nzw = readln.split.to!(int[]);
    auto N = nzw[0];
    auto Z = nzw[1];
    auto W = nzw[2];
    auto as = readln.split.to!(int[]).reverse.array;

    auto DP = new int[][](2, N+1);
    foreach (ref dp; DP) dp[] = -1;
    int solve(int t, int i) {
        auto a = i == N ? W : as[i];
        if (DP[t][i] == -1) {
            auto r = abs(a - as[0]);
            foreach (j; 1..i) {
                r = t == 0 ? max(r, solve(1, j)) : min(r, solve(0, j));
            }
            DP[t][i] = r;
        }
        return DP[t][i];
    }
    writeln(solve(0, N));
}

Measured memory_bytes: 2856
#include <iostream>

int main(int argc, char *argv[])
{
  uint32_t n, a, x;
  std::cin >> n >> a;
  for (uint32_t i=1; i<n; ++i) {
    std::cin >> x;
    a ^= x;
  }
  if (a == 0) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
import heapq
q=int(input())
L=[]
R=[]
heapq.heapify(L)
heapq.heapify(R)
fx=0
for i in range(q):
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    heapq.heappush(L,-a)
    heapq.heappush(R,a)
    l=-heapq.heappop(L)
    r=heapq.heappop(R)
    if l==a and r==a:
      heapq.heappush(L,-l)
      heapq.heappush(R,r)
    else:
      fx+=abs(r-l)
      heapq.heappush(L,-r)
      heapq.heappush(R,l)
    x=-L[0]
    fx+=b
  else:
    print(x,fx)

Measured memory_bytes: 19328
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		HashMap<Integer, Boolean> map = new HashMap<Integer, Boolean>();

		int n = sc.nextInt();
		for (int i = 0; i < n; i ++ ) {
			map.put(sc.nextInt(), true);
		}

		System.out.println(map.size());
	}

}


Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int w;
int h;
int n;

int x[150];
int y[150];

int dist[150][2000];

int main(){
    cin >> w >> h >> n;
    x[0] = 1;
    y[0] = 1;
    rep(i,1,n){
        cin >> x[i] >> y[i];
    }

    x[n + 1] = w;
    y[n + 1] = h;
    using P2 = pair<int,P>;
    priority_queue<P2,vector<P2>,greater<P2>> que;
    que.push({0,{0,0}});
    rep(i,0,1000)rep(j,0,120)
        dist[j][i] = 1e9;
    dist[0][0] = 0;
    while(!que.empty()){
        int v = que.top().second.first;
        int r = que.top().second.second;
        int d= que.top().first;
        que.pop();
        if(dist[v][r] < d) continue;

        for(int i = 1;i <= n + 1;i++){
            if(i == v) continue;
            int now_d = abs(x[v] - x[i]) + abs(y[v] - y[i]);
            int minus = 1;
            if(v == 0 || i ==n + 1) minus = 0;
            int need = max(0,now_d - r - minus);

            if(dist[i][need] > d + need){
                dist[i][need] = d + need;
                que.push({dist[i][need],{i,need}});
            }
        }

        if(r < 1000 && v != 0 && v != n + 1){
            if(dist[v][r + 1] > dist[v][r] + 1){
                dist[v][r + 1] = dist[v][r] + 1;
                que.push({dist[v][r + 1],{v,r + 1}});
            }
        }
    }

    cout << dist[n + 1][0] << endl;
}


Measured memory_bytes: 5484
#include<bits/stdc++.h>
using namespace std;
int n,k,x,ans,cnt;
map<int,int> mp;
int a[200005];
bool cmp(int x,int y){
	return x>y;
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		if (!mp[x]) mp[x]=++cnt;
		a[mp[x]]++;
	}
	sort(a+1,a+cnt+1,cmp);
	ans=n;
	for (int i=1;i<=cnt&&i<=k;i++)
		ans-=a[i];
	printf("%d",ans); 
}

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

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, Adj[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (Adj[u][v])return v;

	}
	return -1;
}
void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;

	stack<int> S;
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
				S.pop();
				color[u] = BLACK;
				f[u] = ++tt;

			}
		}

	}


void dfs() {
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) dfs_visit(u);
	}
	for (int i=0;i<n;i++)
		{
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}

}
int main() {
	
	int  u, k, v;
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			Adj[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			Adj[u][v] = 1;
		}
	}
	
	dfs();
	return 0;
}

Measured memory_bytes: 3120
from collections import Counter

n = int(input())
s = set([input() for _ in range(n)])
cnt = []
for i in s:
    if i[0] in "MARCH":
        cnt.append(i[0])

if len(cnt) < 3:
    print(0)
    exit()

cnt = list(Counter(cnt).values())
N = len(cnt)
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans += cnt[i] * cnt[j] * cnt[k]
print(ans)

Measured memory_bytes: 16248
#cout<< (ll)(((2LL%mod * (n )%mod)%mod - 1%mod)%mod * k%mod)%mod <<'\n';
import sys
# input=sys.stdin.readline
# t = int(input())
# for i in range(t):
# 	n,k=map(int,input().split())
# 	res = (((2**n)%1000000007-1%1000000007)%1000000007 * k%1000000007)%1000000007
# 	print(res)
n = int(input())
if n%9==0:
  print("Yes")
else:
  print("No")

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

int main(void) {
	int K, S;
	cin >> K >> S;

	int c = 0;
	for(int i=0;i<=K;i++)
		for(int j=i;j<=K;j++)
			for (int k = j; k <= K; k++) {
				int t = i + j + k;
				if (t == S){
					if (i == j && j == k)
						c++;
					else if (i != j & j != k)
						c = c + 6;
					else
						c = c + 3;
				
				}
			}

	cout << c << endl;

}

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

using namespace std;

void solve(void)
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - a + b) << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    vector<ll> a(s.size()+10,0),ans(s.size()+10,0);
    ll tmp = 1;
    for(ll i=0;i<s.size()-1;i++){
        if(s[i]=='R' && s[i+1]=='L'){
            a[i] = 0;
            tmp++;
        }
        else if(s[i]=='L' && s[i+1]=='R'){
            a[i] = tmp;
            tmp = 1;
        }
        else{
            a[i] = tmp;
            tmp++;
        }
    }
    a[s.size()-1] = tmp;
    ll c = 0;
    ll num = 0;
    for(ll i=0;i<s.size();i++){
        if(a[i] == 0 && i!=s.size()-1){
            if(a[i+1] == 2 && i != 0){
                ans[c] = (a[i-1]-num-1)/2+1 + num/2;
                ans[c-1] = (num-1)/2+1 + (a[i-1]-num)/2;
                c = i+1;
                num = 1;
            }
            else{
                c = i+1;
                if(i != 0){
                    num = a[i-1]+1;
                }
                else num = 1;
            }
        }   
        else if((a[i]>a[i+1] && a[i+1] != 0)||i==s.size()-1){
            ans[c] = (a[i]-num-1)/2+1 + num/2;
            ans[c-1] = (num-1)/2+1 + (a[i]-num)/2;
        }
    }
    for(ll i=0;i<s.size();i++) cout << ans[i] << " \n"[i+1 == s.size()];
    return 0;
    
}

Measured memory_bytes: 2176
Str = input()
if Str[0] == Str[1]:
  if Str[2] == Str[3] and Str[0] != Str[2]:
    print('Yes')
  else:
    print('No')
    
else:
  if Str[0] == Str[2]:
    if Str[1] == Str[3]:
      print('Yes')
    else:
      print('No')
    
  else:
    if Str[1] == Str[2] and Str[0] == Str[3]:
      print('Yes')
    else:
      print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

void res(int a, int b){
    cout<<((a>b)?"GREATER":((a<b)?"LESS":"EQUAL"))<<endl;
}

void res(string a, string b){
    cout<<((a>b)?"GREATER":((a<b)?"LESS":"EQUAL"))<<endl;
}

int main(){
    string a,b;cin>>a>>b;
    if(a.size()==b.size())res(a,b);
    else res(a.size(),b.size());
}


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

using namespace std;

map<int,char> mp;

int main()
{
	string s;
	int a,b,c,d;
	
	cin >> s;
	a=s[0]-'0';b=s[1]-'0';c=s[2]-'0';d=s[3]-'0';
	mp[0]='-';mp[1]='+';
	
	for(int i=0;i<=7;i++)
	{
		int op1=(i&1),op2=(i&2)/2,op3=(i&4)/4;
		int sum=a;
		if(op1) sum+=b;
		else sum-=b;
		if(op2) sum+=c;
		else sum-=c;
		if(op3) sum+=d;
		else sum-=d;
		
		if(sum==7)
		{
			cout << a << mp[op1] << b << mp[op2] << c << mp[op3] << d << '=' << 7;
			return 0;
		}
	}
	
	return 0;
}

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

int main(){
    ll a; cin >> a;
    cout << a + a*a + a*a*a << endl;

}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

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

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N+2];

#define ld long double
void solve()
{     
      
      ld n;
      cin >> n;
      ld a = n/3;


      cout<<fixed << setprecision(24) << a*a*a << endl;
      
}


int32_t main()
{
      
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
    //  INP(); 
      int t = 1;
      //cin >> t;
      while(t--) solve();

}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/

int N, A;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {

    cin>>N>>A;

    if(N <= A  || (500 <= N && (N % 500)<=  A)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define ld long double
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 2e5+1;
int a[N];
signed main(){
    fast;
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++)
		cin>>a[i];
	int mx = a[1];
	int req = 0;
	for(int i = 2;i<=n;i++){
		if(a[i]<mx){
			req += mx - a[i];
		}
		else{
			mx = a[i];
		}
	}
	cout<<req;
}

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

string solve(string s) {
  string ss = "";
  if(s[((int) s.size()) - 1] != 's') {
    ss = s + "s";
    return ss;
  }
  ss = s + "es";
  return ss;
}

int main() {
  string s;
  cin >> s;
  cout << solve(s);
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll N, D, X, Y;
	cin >> N >> D;
	ll ans = 0;
	rep(i, 0, N) {
		cin >> X >> Y;
		if (X * X + Y * Y <= D * D) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[2000];
typedef bitset<2000001> B;
B dp;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  sort(A, A+N);
  dp.set(0);
  int sum = 0;
  rep(i, N) {
    int a = A[i];
    dp |= dp<<a;
    //for (int j=min(sum+1, 2000000-a); j>=0; j--) dp[j+a] |= dp[j];
    sum += a;
  }
  int m = 0;
  rep(i, sum/2+1) if (dp[i]) m = i;
  cout << sum-m << "\n";
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
t = 999 #平均気温とAとの最短の差
p = 0 #その差を記録したポイント
for i in range(len(H)):
  if t > abs(A - T + H[i]*0.006):
    t = abs(A - T + H[i]*0.006)
    p = i+1
print(p)

Measured memory_bytes: 3060
# ABC103B - String Rotation
s, t = [input().rstrip() for _ in range(2)]
lst_s = [i for i in s]
lst_t = [i for i in t]

if s == t:
    print("Yes")
else:
    for _ in range(len(s)):
        lst_s.insert(0, lst_s.pop())
        if lst_s == lst_t:
            print("Yes")
            break
    else:
        print("No")

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

int main(){
  ll n;
  cin >> n;
  vector<string> s(n);
  for(ll i=0;i<n;i++){
    vector<char> t(10);
    for(ll j=0;j<10;j++){
      cin >> t.at(j);
    }
    sort(t.begin(),t.end());
    for(ll j=0;j<10;j++){
      s.at(i)+=t.at(j);
    }
  }
  sort(s.begin(),s.end());
  
  ll ans=0;
  
  for(ll i=1;i<n;i++){
    ll x=1;
    while(s.at(i-1)==s.at(i)){
      i++;
      x++;
      if(i==n) break;
    }
    ans+=(x-1)*x/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7296
n = int(input())
a = list(map(int,input().split()))
odd = a[0::2]
even = a[1::2]
ans = []
if n%2 == 0:
    even = even[::-1]
    ans = even + odd
else:
    odd = odd[::-1]
    ans = odd + even
for i in range(len(ans)):
    print(str(ans[i])+" ",end="")
print()

Measured memory_bytes: 26016
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string A,B,C;
    cin >> A >> B >> C;
    if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int A;
int B;
int C;
int D;
int main(){
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  if(abs(A-C)<=D || (abs(A-B)<=D && abs(B-C)<=D)){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A, B, C, D;
// {
//   rd(A,B,C,D);
//   wt( if[abs(A-C)<=D || (abs(A-B)<=D && abs(B-C)<=D), "Yes", "No"] );
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int A,B;
    cin>>A>>B;
    int ans=max(A+B,max(A-B,A*B));
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
N, K=map(int, input().split())
S=input()
S=list(S)

if S[K-1]=='A':
  S[K-1]='a'
if S[K-1]=='B':
  S[K-1]='b'
if S[K-1]=='C':
  S[K-1]='c'

print(''.join(S))

Measured memory_bytes: 3060
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(max(D)):
        ans *= p[i] ** p[i + 1]
        ans %= MOD
        if ans == 0:
            break

    print(ans)

else:
    print(0)


Measured memory_bytes: 24516
#include <stdio.h>
int main(){
  long int H,W,num;
  scanf("%ld %ld",&H, &W);
  if(H==1 || W==1) num=1;
  else if(H%2==1 && W%2==1) num=H*W/2+1;
  else num=H*W/2;
  printf("%ld",num);
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

button = [[''],['.',',','!','?',' '], ['a','b','c'], ['d','e','f'], ['g','h','i'], ['j','k','l'], ['m','n','o'], ['p','q','r','s'], ['t','u','v'], ['w','x','y','z']]

n = int(input())
for i in range(n):
    inputStr = list(map(int,list(input())))
    count = 0
    for j in range(len(inputStr)):
        if inputStr[j] != 0:
            count += 1
        if inputStr[j] == 0 and j -1 >= 0 and  inputStr[j-1] != 0:
            print(button[inputStr[j-1]][(count-1)%len(button[inputStr[j-1]])],end='')
            count = 0
    print()

Measured memory_bytes: 6736
import math

N, M = map(int, input().split())

mod = int(1e9+7)

if abs(N-M) > 1:
  ans = 0
elif abs(N-M) == 1:
  ans = (math.factorial(N) % mod) * (math.factorial(M) % mod) % mod
else:
  ans = 2 * (math.factorial(N) % mod) * (math.factorial(M) % mod) % mod

print(ans)

Measured memory_bytes: 4096
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int sum[1000][1000] = {0};

int main() {
  int H,top=0;
  string str;
  
  while(cin >> H) {
    getline(cin,str);// kill \n
    string field[1000] = {""};
    if(H == 0) break;

    for(int i=0;i<H;i++) { //get field for string
      getline(cin,str);
      field[i] = str;
    }
    if(field[0].substr(0,1) == ".") {
      sum[0][0] = 1;
    }
    else {
      sum[0][0] = 0;
    }    
    for(int j=1;j<H;j++) {
      if(field[0].substr(j,1) == ".") {
	sum[0][j] = 1 + sum[0][j-1];
      }
      else {
	sum[0][j] = sum[0][j-1];
      }
    }

    for(int i=1;i<H;i++) {
      if(field[i].substr(0,1) == ".") {
	sum[i][0] = 1 + sum[i-1][0];
      }
      else {
	sum[i][0] = sum[i-1][0];
      }
    }

    for(int i=1;i<H;i++) {
      for(int j=1;j<H;j++) {
	if(field[i].substr(j,1) == ".") {
	  sum[i][j] = 1 + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
	}
	else {
	  sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
	}
      }
    }
    int S;
    for(int i=0;i<H;i++) {
      for(int j=0;j<H;j++) {
	if(field[i].substr(j,1) == ".") {
	  for(int k=1;k<=min(i+1,j+1);k++) {
	    if(i != H-1||j != H-1||k!=min(i+1,j+1)) {
	      S = sum[i][j] - sum[i-k][j] - sum[i][j-k] + sum[i-k][j-k];
	    }
	    else {
	      S = sum[i][j];
	    }

	    if(S == k*k) {
	      top = max(top,k);
	    }
	    else {
	      break;
	    }
	  }
	}
      }
    }
    
    cout << top << endl;
    top = 0;
  }
}

Measured memory_bytes: 4760
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n, a, b = map(int, input().split())
s = input()
total_cnt = 0
b_cnt = 0
for i in s:
    if i == "a":
        if total_cnt < a + b:
            print("Yes")
            total_cnt += 1
        else:
            print("No")
    elif i == "b":
        if total_cnt < a + b and b_cnt + 1 <= b:
            print("Yes")
            total_cnt += 1
            b_cnt += 1
        else:
            print("No")
    elif i == "c":
        print("No")



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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int k, a, b; cin >> k >> a >> b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3616
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<i32>();
    let mut t=0;
    let mut x=0;
    let mut y=0;
    println!("{}",if (0..n).into_iter().all(|_|{
        let tt=read::<i32>();
        let xx=read::<i32>();
        let yy=read::<i32>();
        let flag=(tt-t)>=(xx-x).abs()+(yy-y).abs()&&(tt-t)%2==(xx-x+yy-y).abs()%2;
        t=tt;
        x=xx;
        y=yy;
        flag
    }){"Yes"}else{"No"});
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
	int ABC[256], dummy = 0, i;
	char ori, pre;
	
	ABC['A'] = 1;
	ABC['B'] = 0;
	ABC['C'] = 0;
	
	while (scanf(" %c%*c%c", &ori, &pre) != EOF){
		dummy = ABC[ori];
		ABC[ori] = ABC[pre];
		ABC[pre] = dummy;
	}
	
	for (i = 'A'; i <= 'C'; i++){
		if (ABC[i] == 1) printf("%c\n", i);
	}
	
	
	return (0);
	
}

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

long long kMod = 1e9 + 7;

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}


int main()
{
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  vector<long long> bitcnt(64);
  for (auto x : v) {
    int i = 0;
    while ((1LL << i) <= x) {
      if ((1LL << i) & x) {
        bitcnt.at(i)++;
      }
      i++;
    }
  }
  long long res = 0;
  for (auto x : v) {
    long long sum = 0;
    for (int i = 0; i < 64; i++) {
      long long bit;
      if ((1LL << i) & x) {
        bit = n - bitcnt.at(i);
      } else {
        bit = bitcnt.at(i);
      }
      long long tmp = 0;
      tmp = bit << max(i-30, 0);
      tmp %= kMod;
      tmp = tmp << min(i, 30);
      tmp %= kMod;
      sum += tmp;
      sum %= kMod;
    }
    res += sum;
    res %= kMod;
  }
  cout << res * modinv(2, kMod) % kMod << '\n';
  return 0;
}


Measured memory_bytes: 2560
def get_p(ind):
    if parent[ind] != ind:
        parent[ind] = get_p(parent[ind])
    return parent[ind]



num, swap = map(int, input().split())
data = list(map(int, input().split()))

parent = [i for i in range(num + 1)]

for i in range(swap):
    a, b = map(int, input().split())
    a_parent = get_p(a)
    b_parent = get_p(b)
    if a_parent != b_parent:
        parent[max(a_parent, b_parent)] = min(a_parent, b_parent)

ans = 0

for i in range(num):
    now_int = i + 1
    ind =  data[i]
    if get_p(now_int) == get_p(ind):
        ans += 1
    elif ind == now_int:
        ans += 1

print(ans)




Measured memory_bytes: 89196
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int  x=scn.nextInt();
		int y=scn.nextInt();
		int a=scn.nextInt();
		int b=scn.nextInt();
		int c=scn.nextInt();
		int []arr =new int[a];
		int [] arr1=new int[b];
           int [] arr2=new int[c];
           for(int i=0;i<a;i++){
        	   arr[i]=scn.nextInt();
           }
          for(int i=0;i<b;i++){
        	  arr1[i]=scn.nextInt();
          }
          for(int i=0;i<c;i++){
        	  arr2[i]=scn.nextInt();
        	  
          }
          
          
         
         System.out.println(res(arr,arr1 ,arr2 ,x, y));
	}
	public static long res(int [] arr1,int [] arr2 ,int [] arr3,int x,int y){
		PriorityQueue<Integer> pq =new PriorityQueue<>();
		for(int i=0;i<arr1.length;i++){
			if(pq.size()<x){
				pq.add(arr1[i]);
			}else{
				if(pq.peek()<arr1[i]){
					pq.remove();
					pq.add(arr1[i]);
				}
			}
		}
		PriorityQueue<Integer> pq1 = new PriorityQueue<>();
		for(int i=0;i<arr2.length;i++){
			if(pq1.size()<y){
				pq1.add(arr2[i]);
			}else{
				if(pq1.peek()<arr2[i]){
					pq1.remove();
					pq1.add(arr2[i]);
				}
			}
		}
		while(pq1.size()>0){
			pq.add(pq1.remove());
		}
		for(int i=0;i<arr3.length;i++){
			if(pq.size()<(x+y)){
				pq.add(arr3[i]);
			}else{
				if(pq.peek()<arr3[i]){
					pq.remove();
					pq.add(arr3[i]);
				}
			}
		}
		
		long sum=0;
		while(pq.size()>0){
			sum+=pq.remove();
		}
		return sum;
		
	}

}

Measured memory_bytes: 94224
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
   vector<int> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  int t = 0;
  for(int i = 0; i < n - 2; i++){
    if(vec.at(i) < vec.at(i + 1) && vec.at(i + 1) < vec.at(i + 2)){
      t += 1;
    }
    else if(vec.at(i) > vec.at(i + 1) && vec.at(i + 1) > vec.at(i + 2)){
      t += 1;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = []
c = []
for _ in range(n):
    l = list(map(int,input().split()))
    c += [l[0]]
    a += [l[1:]]

ans = sum(c) + 1
for i in range(2**n):
    tmp = 0
    com = [0] * m
    for j in range(n):
        if i >> j & 1:
            tmp += c[j]
            for k in range(m):
                com[k] += a[j][k]
    ok = True
    for k in range(m):
        if com[k] < x:
            ok = False
            break
    if ok:
        ans = min(ans, tmp)
if ans == sum(c) + 1:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9244
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 1005
#define maxh 10005
int h,n,a[maxn],b[maxn],f[maxh];
int main(){
  h = getint(), n = getint();
  for(int i = 1;i <= n;i++) a[i] = getint(), b[i] = getint();
  memset(f,0x3f,sizeof(f));
  f[0] = 0;
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= h;j++){
      f[j] = min(f[j],f[max(0,j - a[i])] + b[i]);
    }
  }
  putint(f[h],'\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, v[20], c[20];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    int m = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] - c[i]>0) m += v[i] - c[i];
    }
    cout << m << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2874.cc: Pigeonhole principle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (abs(as[j] - as[i]) % (n - 1) == 0) {
	printf("%d %d\n", as[i], as[j]);
	return 0;
      }
  return 0;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
ll dp[101010][13];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    dp[0][0] = 1;
    const int N = s.size();
    reverse(all(s));
    int base = 1;
    rep(i, N) {
        if (s[i] != '?') {
            rep(j, 13) {
                int c = s[i] - '0';
                (dp[i + 1][(c * base + j) % 13] += dp[i][j]) %= MOD;
            }
        } else {
            rep(j, 13) {
                rep(k, 10)(dp[i + 1][(k * base + j) % 13] += dp[i][j]) %= MOD;
            }
        }
        base = base * 10 % 13;
    }
    cout << dp[N][5] << endl;

    return 0;
}

Measured memory_bytes: 10704
N,M = map(int,input().split())

# 約数列挙
def enum_div(N):
    ret = []
    for i in range(1,int(N**0.5)+1):
        if N % i == 0:
            ret.append(i)
            if i**2 != N:
                ret.append(N // i)
        i += 1
    return ret

ans = 0
for i in enum_div(M):
    if i >= N:
        ans = max(ans,M // i)

print(int(ans))

Measured memory_bytes: 9416
function Main(input){
  var all = input.split("\n");
  all.shift();
  var N =input.split("\n")[0].split(" ")[0];
  N = parseInt(N,10);
  var M =input.split("\n")[0].split(" ")[1];
  M = parseInt(M,10);
  var R = [];
  var L = [];
  var Lm = 0,Rm = 0;
  for(i=0;i<=(M-1);i++){
    R[i] = all[i].split(" ")[1];
    R[i] = parseInt(R[i],10);
    L[i] = all[i].split(" ")[0];
    L[i] = parseInt(L[i],10);
    if(i===0){
      Lm = L[i];
      Rm = R[i];
    }else{
      if(Lm<L[i]){
        Lm = L[i];
      }
      if(Rm>R[i]){
        Rm = R[i];
      }
    }
  }
  if(Lm > Rm){
    console.log("0");
  }else{
    var ans = (Rm - Lm) + 1;
    console.log(ans);
  }
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));



Measured memory_bytes: 50352
#include <stdio.h>
int main (void)
{
    int A,B,a,s,v;
    scanf("%d%d",&A,&B);
    a=A+B;
    s=A-B;
    v=A*B;
    if((a>=s)&&(a>=v))
        printf("%d\n",a);
    else if((s>=a)&&(s>=v))
        printf("%d\n",s);
    else
        printf("%d\n",v);
return 0 ;
}

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

int n, k;
int a[300005];
int ans;

struct node {
	int lo, hi, mid, val;
	node *l, *r;
	node(int _lo, int _hi): lo(_lo), hi(_hi), mid((_lo + _hi) / 2), val(0) {
		if (lo != hi) l = new node(lo, mid), r = new node(mid + 1, hi);
	}
	void update(int p, int v) {
		if (lo == hi) {
			val = v;
			return;
		}
		if (p <= mid) l -> update(p, v);
		else r -> update(p, v);
		val = max(l -> val, r -> val);
	}
	int query(int s, int e) {
		s = max(0, s), e = min(300005, e);
		if (lo >= s && hi <= e) return val;
		if (s > mid) return r -> query(s, e);
		else if (e <= mid) return l -> query(s, e);
		else return max(r -> query(s, e),  l -> query(s, e));
	}
} *root;

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	root = new node(0, 300005);
	for (int i = 0; i < n; i++) {
		int cur = root -> query(a[i] - k, a[i] + k);
		root -> update(a[i], cur + 1);
	}
	printf("%d\n", root -> query(0, 300005));
	return 0;
}


Measured memory_bytes: 33096
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner s = new Scanner(System.in);

		int max=0;
		int min=100000;
		int sum=0;
		int ave;
		int[] scr= new int[100];
		while(true){
			int n=s.nextInt();
			if(n==0){
				break;
			}
			for(int i=0;i<n;i++){
				scr[i]=s.nextInt();
				if(scr[i]>max){
					max=scr[i];
				}
				if(scr[i]<min){
					min=scr[i];
				}
				sum+=scr[i];
			}
			sum-=(max+min);
			ave=sum/(n-2);
			System.out.println(ave);
			max=0;
			min=100000;
			sum=0;
		}
	}
}

Measured memory_bytes: 28796
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
  int k, x;
  cin >> k >> x;
  for(int i = x - k + 1; i<= x + k - 1; i++){
    if(i != x - k + 1)cout << " ";
    cout << i;
  }
  cout << endl;
}

Measured memory_bytes: 256
str = gets.chomp
str_array = str.split('').uniq.sort
k = gets.to_i
k_array = []

str_array.each do |c|
  count = str.count(c)
  n = -1
  count.times do |i|
    n = str.index(c, n+1)
    (0..([5, str.size - n].min)).each do |j|
      k_array << str[n..(n+j)]
    end
  end
  k_array = k_array.sort.uniq
  if k_array.size >= k
    puts k_array[k-1]
    exit
  end
end

Measured memory_bytes: 4384