akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define ll long long
#define MOD 1000000007

ll n,ans = 1,s[1100];
int main() {
	cin >> n;
	FOR(k, 2, n + 1) {
		ll a = k;
		FOR(i, 2, k + 1) {
			ll now = 0;
			REP(j, INF) {
				if (a % i != 0) break;
				a /= i;
				s[i]++;
			}
		}
	}
	REP(i, 1100) {
		ans *= s[i] + 1;
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
// TLE ...

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

bool testbit(int x, int i) { return (x >> i) & 0x1; }

int countbits(int x) {
  int cnt{};
  while (x) {
    if (x & 0x1) ++cnt;
    x >>= 1;
  }
  return cnt;
}

int ipow(int a, int b) { return b > 0 ? a * ipow(a, b - 1) : 1; }

int nop(const vector<vector<int>> &s, const vector<int> &hsep, int k) {
  int h = s.size();
  int w = s.front().size();
  int nblock = hsep.size();
  vector<int> v(nblock, 0);
  int cnt{0};
  bool flag = false;
  for (auto i = 0; i != w; ++i) {
    int iblock{0};
    for (auto j = 0; j != h; ++j) {
      if (j == hsep[iblock]) ++iblock;
      if (s[j][i]) ++v[iblock];
    }
    if(any_of(v.begin(),v.end(),[&k](int x){ return x > k;})) {
      if (flag) { // separation impossible
        cnt = 10000;
        break;
      }
      --i;
      ++cnt;
      fill(v.begin(), v.end(), 0);
      flag = true;
    } else {
      flag = false;
    }
  }
  return cnt;
}

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<vector<int>> s(h);
  for (auto &r : s) {
    r.resize(w);
    string str;
    cin >> str;
    for (auto i = 0; i != w; ++i) {
      r[i] = str[i]-'0';
    }
  }

  int n = ipow(2, h - 1);
  int mi{h * w};
  vector<int> hsep;
  for (auto i = n-1; i >=0; --i) {
    int nbits = countbits(i);
    if (nbits >= mi) continue;
    hsep.clear();
    for (auto j = 1; j != h; ++j) {
      if (testbit(i, j - 1)) hsep.push_back(j);
    }
    hsep.push_back(h);
    mi = min(nbits + nop(s, hsep, k), mi);
  }

  cout << mi << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

switch = []
for i in range(m):
    k, *tmp = map(int, input().split())
    switch_mask = 0
    for j in tmp:
        switch_mask += 1 << (j-1)
    switch.append(switch_mask)

p = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    all_on = True
    for j in range(len(switch)):
        if not bin(i & switch[j]).count('1') % 2 == p[j]:
            all_on = False
            break
    if all_on:
        ans += 1

print(ans)


Measured memory_bytes: 3064
nm = input().split(' ');
n = int(nm[0]);
m = int(nm[1]);
flag = [0]*(n+1);
count_wa = [0]*(n+1);

for i in range(m) :
	ps = input().rstrip('\n');
	ps = ps.split(' ');
	p = int(ps[0]);
	s = ps[1];
	if flag[p] == 0 and s == 'AC' :
		flag[p] = 1;
	elif flag[p] == 0 and s == 'WA' :
		count_wa[p] += 1;

for i in range(n+1) :
	if flag[i] == 0 :
		count_wa[i] = 0;

print(sum(flag),sum(count_wa));

Measured memory_bytes: 4596
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
#include<stack>

using namespace std;

#define st first
#define nd second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (long long)1e18

typedef long long ll;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

int main() {
		string s;
		cin>>s;
		if(s.size()<4){
				cout<<"No\n";
		}
		else if(s.substr(0,4)=="YAKI"){
				cout<<"Yes\n";
		}
		else cout<<"No\n";





		return 0;
}


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



int main()
{
  string s;
  cin >> s;
  for(int i=0; i<3; i++){
    if(s[i]==s[i+1]){
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
# include <stdio.h>
int count[52];
int n,m,a,b;
int main(void){
    
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        count[a-1]++;
        count[b-1]++;
    }
    for(int i=0;i<n;i++){
        printf("%d\n",count[i]);
    }
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
c = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for j in range(1, N+1):
    print(c - abs(A[j-1] - A[j]) - abs(A[j] - A[j+1]) + abs(A[j-1] - A[j+1]))

Measured memory_bytes: 13920
def main():
    n, m = map(int, input().split())
    l_lst = [0 for _ in range(m)]
    r_lst = [0 for _ in range(m)]

    for i in range(m):
        l, r = map(int, input().split())
        l_lst[i] = l
        r_lst[i] = r

    left = max(l_lst)
    right = min(r_lst)

    if right - left < 0:
        print(0)
    else:
        print(right - left + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 85760
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

long n, m, p, ans;
string s, t;
char c;
map<char, vector<long>> a;

int main(){
	cin >> s >> t;
	n = s.size(); m = t.size();
	for (c = 'a'; c <= 'z'; ++c) a.emplace(c, vector<long>());
	for (int i = 0; i < n; ++i) a[s[i]].push_back(i);
	ans = 0;
	p = -1;
	for (int i = 0; i < m; ++i){
		c = t[i];
		if (a[c].empty()){
			printf("%d", -1);
			return 0;
		}
		if (p >= a[c].back()){
			p = -1;
			ans += n;
		}
		auto iter = upper_bound(a[c].begin(), a[c].end(), p);
		p = *iter;
	}
	ans += p + 1;
	printf("%ld", ans);
}

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() { 
    int n, k;
    cin >> n >> k;
    int res = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        res += min(x, abs(x - k)) * 2;
    }
    cout << res << endl;
}




Measured memory_bytes: 3572
n = int(input())
c = input()

cnt = 0
i = 0
j = n-1
while i < j:
    while c[i] == 'R' and i < j:
        i += 1
    while c[j] == 'W' and i < j:
        j -= 1
    if c[i] != 'W' or c[j] != 'R':
        break
    i += 1
    j -= 1
    cnt += 1

print(cnt)

Measured memory_bytes: 9340
s = input()

ans = 1
tmp = s[0]
t = False

for i in range(1, len(s)):
    if t:
        tmp = s[i - 1] + s[i]
        t = False
        ans += 1
        continue
        
    if tmp == s[i]:
        t = True
        
    else:
        ans += 1
        tmp = s[i]

print(ans)

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

long P = 10^^9 + 7;

int[2*10^^5+1] CS;
long[2*10^^5+1] MEMO;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..N) {
        CS[i] = readln.chomp.to!int;
    }

    int[2*10^^5+1] acc, right;
    foreach_reverse(ii, c; CS[0..N]) {
        int i = ii.to!int;
        if (!acc[c]) {
            acc[c] = i;
        } else {
            right[i] = acc[c];
            acc[c] = i;
        }
    }

    foreach_reverse (i; 0..N) {
        if (i == N-1) {
            MEMO[i] = 1;
        } else {
            long r = MEMO[i+1];
            if (right[i] && right[i] != i+1) r = (r + MEMO[right[i]]) % P;
            MEMO[i] = r;
        }
    }

    writeln(MEMO[0]);
}

Measured memory_bytes: 5244
#include<iostream>
#include<vector>
#include<string>
#include<numeric>
using namespace std;
int main()
{
	string n;
	cin >> n;

	int ans = 0;
	for(auto i :n){
	    ans+=i-'0';
	    }
	    if(stoi(n)%ans==0){
	        cout<<"Yes";
	     }else{
	         cout<<"No";
	     }
}

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

int main()
{
  int64_t nAnum, nBnum, nXpos;
  cin >> nAnum >> nBnum >> nXpos;

  int64_t nDivHigh = nBnum / nXpos;
  int64_t nDivLow;

  if (nAnum - 1 < 0)
  {
    nDivHigh++;
    nDivLow = 0;
  }
  else
    nDivLow = (nAnum - 1) / nXpos;

  cout << (nDivHigh - nDivLow) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        String[] sl = str.split(" ");
        int N = Integer.parseInt(sl[0]);
        int K = Integer.parseInt(sl[1]);
        System.out.println(N-(K-1));
    }
}

Measured memory_bytes: 21204
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
public class Main {
	static final long C =  1000000007;
	static final int CY = 1000000000;
	StringBuilder sb;
	public void calc() {
		sb = new StringBuilder();


		FastScanner sc = new FastScanner();

		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		char[] s = sc.next().toCharArray();

		int ans = 0;

		for (int i=0; i < s.length; i++) {
			if (s[i] == 'a') {
				if (a+b > 0) {
					a--;
					sb.append("Yes\n");
				}else {
					sb.append("No\n");
				}
			}else if (s[i] == 'b') {
				if (a+b > 0 && b > 0) {
					b--;
					sb.append("Yes\n");
				}else {
					sb.append("No\n");
				}
			}else {
				sb.append("No\n");
			}
		}


		System.out.print(sb);
	}



	public static void main(String[] args) {
		Main main = new Main();
		main.calc();

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


Measured memory_bytes: 13520
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back



const int MOD = 1e9+7;
int power(int a, int n)
{
    int res = 1;
    int now = a;
    while(n)
    {
        if (n&1)
        {
            res  = (res*now) %MOD;
        }
        n>>=1;
        now = (now*now)%MOD;
    }
    return res;
}
int inv(int a)
{
    return power(a, MOD-2);
}
int n, k;
vector<int> a;
vector<int> ps, ng;
void solve()
{
    cin>>n>>k;
    a.resize(n);
    forn(i, n)
    {
        cin>>a[i];
        if (a[i] >= 0) ps.pb(a[i]);
        else ng.pb(-a[i]);
    }
    if (n == k || (sz(ps)==0 && k%2))
    {
        sort(a.begin(), a.end(), [](int x, int y)
        {
           return abs(x)<abs(y);
        });
        int ans = 1;
        forn(i, k) ans = (ans * a[i]%MOD + MOD)%MOD;
        cout << ans <<'\n';
        return;
    }
    sort(ps.begin(), ps.end());
    sort(ng.begin(), ng.end());
    vector<int> v;
    int ans = 1;
    if (k%2)
    {
        ans = (ans * ps.back())%MOD;
        ps.pop_back();
    }
    while(sz(ps)>1)
    {
        int x = ps.back(); ps.pop_back();
        x*=ps.back(); ps.pop_back();
        v.push_back(x);
    }
    while(sz(ng)>1)
    {
        int x = ng.back(); ng.pop_back();
        x*=ng.back(); ng.pop_back();
        v.push_back(x);
    }
    sort(v.rbegin(), v.rend());
    forn(i, k/2) ans = (ans * (v[i]%MOD) )%MOD;
    cout << ans%MOD << '\n';
}



signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 8164
#include <cstdio>

int main()
{
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    if(a <= x && x <= a+b)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    while (1) {
        int n;
        cin >> n;
        if (!n) return 0;

        vector<int> power(n);
        map<string, int> mp;
        vector<vector<string>> nearby(n);
        for (int i = 0; i < n; ++i) {
            string s;
            int c;
            cin >> s >> power[i] >> c;
            mp[s] = i;
            nearby[i].resize(c);
            for (int j = 0; j < c; ++j)
                cin >> nearby[i][j];
        }
        vector<long long> isnearby(n, 0LL);
        for (int i = 0; i < n; ++i)
            for (auto& j : nearby[i])
                isnearby[i] |= 1LL << mp[j];

        for (int i = 0; i < n; ++i)
            if ((isnearby[0] >> i) & 1)
                power[i] = -1000000;

        int n1 = n / 2;
        int n2 = n - n1;
        vector<int> dp(1 << n1, -1000000);
        for (int i = 1; i < (1 << n1); i += 2) {
            int ma = 0;
            long long inb = 0;
            dp[i] = 0;
            for (int j = 0; j < n1; ++j) {
                if ((i >> j) & 1) {
                    inb |= isnearby[j];
                    dp[i] += power[j];
                    ma = max(ma, dp[i ^ (1 << j)]);
                }
            }
            if (i & inb)
                dp[i] = ma;
        }
        int ans = 0;
        int msk = (1 << n1) - 1;
        for (int i = 0; i < (1 << n2); ++i) {
            int sum = 0;
            long long inb = 0;
            for (int j = 0; j < n2; ++j) {
                if ((i >> j) & 1) {
                    inb |= isnearby[n1 + j];
                    sum += power[n1 + j];
                }
            }
            if (!(i & (inb >> n1)))
                ans = max(ans, sum + dp[(inb & msk) ^ msk]);
        }
        cout << ans << "\n";
    }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	int W=0,L=0;
	REP(i,S.size()){
		if(S[i]=='o') W++;
		else L++;
	}
	out((15-L)>=8?"YES":"NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);
const int INF = 1e9 + 7;

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k; cin >> n >> k;
    vector<int> v(n), dp(n);
    for (int i = 0 ; i < n; ++i) cin >> v[i];
    int min_cost = INF;
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        dp[i] = INF;
        for (int j = 1; j <= k; ++j) {
            if (i - j >= 0) {
                dp[i] = min(abs(v[i]-v[i-j])+dp[i-j], dp[i]);
            } else break;
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}



Measured memory_bytes: 3988
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;
int D = 161*80*2+3;
bool dp[80][80][160*80*2+3]={0};
int main(){
  int H,W;
  cin>>H>>W;
  int A[H][W],B[H][W];
  REP(h,H)REP(w,W)cin>>A[h][w];
  REP(h,H)REP(w,W)cin>>B[h][w];
  REP(h,H)REP(w,W)A[h][w]-=B[h][w];
  dp[0][0][D/2+A[0][0]]=1;
  dp[0][0][D/2-A[0][0]]=1;
  REP(h,H)REP(w,W){
    if(h>0){
      REP(i,D)if(dp[h-1][w][i]){
        dp[h][w][i+A[h][w]]=true;
        dp[h][w][i-A[h][w]]=true;
      }
    }
    if(w>0){
      REP(i,D)if(dp[h][w-1][i]){
        dp[h][w][i+A[h][w]]=true;
        dp[h][w][i-A[h][w]]=true;
      }
    }
  }
  int ans=D;
  REP(i,D)if(dp[H-1][W-1][i]){
    // cerr<<i-D/2<<endl;
    ans=min(ans,max(i-D/2,D/2-i));
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {

    int idx[100005] = {0};

    idx[3] = idx[4] = idx[5] = 1;
    for (int i = 5; i <= 100000; ++i) {
        bool flag = true;
        for (int j = 2; j <= sqrt(i); ++j)
            if (i % j == 0)
                flag = false;

        if (flag) {
            int n = (i + 1) / 2;
            bool f = true;
            for (int j = 2; j <= sqrt(n); ++j)
                if (n % j == 0)
                    f = false;

            if(f)
                idx[i]++;
        }

        idx[i + 1] += idx[i];
    }

    int Q;
    cin >> Q;

    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        --l;

        cout << idx[r] - idx[l] << "\n";
    }

    return 0;
}

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

const int N = 210;
const int moder = 998244353;

int x[N], y[N];
int n;

int powermod(int a, int exp){
	int ret = 1;
	for ( ; exp; exp >>= 1){
		if (exp & 1){
			ret = 1ll * ret * a % moder;
		}
		a = 1ll * a * a % moder;
	}
	return ret;
}

int det(int x1, int y1, int x2, int y2){
	return x1 * y2 - y1 * x2;
}

bool onSeg(int x1, int y1, int x2, int y2, int x3, int y3){
	return !det(x2 - x1, y2 - y1, x3 - x1, y3 - y1);
}

int main(){
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i){
		scanf("%d%d", &x[i], &y[i]);
	}
	int ans = 0;
	for (int i = 0; i < n; ++ i){
		for (int j = i + 1; j < n; ++ j){
			int cnt = 0;
			for (int k = 0; k < n; ++ k){
				cnt += onSeg(x[i], y[i], x[j], y[j], x[k], y[k]);
			}
			ans = (ans + 1ll * (powermod(2, cnt) - (cnt + 1) + moder) * powermod(cnt * (cnt - 1) >> 1, moder - 2)) % moder;
		}
	}
	ans = (ans + n + 1) % moder;
	return printf("%d\n", (powermod(2, n) - ans + moder) % moder), 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
using namespace std;
long long inf=100000000000007;
#define int long long
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
char fi[1005][1005];
P sg[10];
int d[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int c=0;
int n,m,t;
signed main(){
    string s;cin>>s;
    bool a=false;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'&&s[i+1]=='C')a=true;
    }
    if(a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
A = []
for i in range(M):
    tmp = list(map(int,input().split()))
    A.append(tmp)

l = 1
r = 10**5
for s in range(M):
    if A[s][0] > l:
        l = A[s][0]
    if A[s][1] < r:
        r = A[s][1]
if r < l:
    print(0)
else:
    print(r-l+1)

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

int n,m,k;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

bool valid(int x, int y){
	return x >= 1 and x <= n and y >= 1 and y <= m;
}

void solve(){
	scanf("%d%d%d", &n, &m, &k);
	queue<ii> q;
	char v[n+1][m+1];
	int see[n+1][m+1], x1, y1, x2, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	for(int i = 1; i <= n; i++){
		getchar();
		for(int j = 1; j <= m; j++){
			scanf("%c", &v[i][j]);
			see[i][j] = mod;
		}
	}
	q.push({x1,y1});
	see[x1][y1] = 0;
	while(!q.empty()){
		int i = q.front().fst, j = q.front().snd; q.pop();
		for(int t = 0; t < 4; t++){
			for(int l = 1; l <= k; l++){
				int ni = i + dx[t]*l, nj = j + dy[t]*l;
				if(!valid(ni, nj) or v[ni][nj] == '@' or see[ni][nj] < see[i][j]+1)
					break;
				if(see[ni][nj] > see[i][j]+1){
					see[ni][nj] = see[i][j]+1;
					q.push({ni, nj});
				}
			}
		}
	}
	if(see[x2][y2] == mod)printf("-1\n");
	else printf("%d\n", see[x2][y2]);
}

int main(){
	//fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 10200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        scanner.close();

        int C = A - B * 2;

        if (C <= 0) {
            C = 0;
        }
        System.out.println(C);

    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,j,k,l,m,n,x=0,y=0;
    cin>>n>>k;
    int a[n];
    int dp[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++){
        for(j=1;(j<=k)&&(j<=i);j++){
 dp[i]=min(dp[i],(dp[i-j]+abs(a[i]-a[i-j])));
    }
    }
    cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int a[200001];
bool f[1000001];
int read(){
	char ch=getchar();
	int ans=0;
	bool f=true;
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=~f;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		ans=((ans<<3)+(ans<<1))+(ch^'0');
		ch=getchar();
	}
	if(f) return ans;
	else return -ans;
}
bool cmp(int q1,int q2){
	return q1<q2;
}
int main(){
	n=read();
	int mx=0;
	for(int i=0;i<n;i++){
		a[i]=read();
		mx=max(mx,a[i]);
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++){
		if(!f[a[i]]&&a[i+1]!=a[i]&&a[i-1]!=a[i]) ans++;
		for(int j=1;j*a[i]<=mx;j++) f[a[i]*j]=true;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }


int main() {
  int n, m, x; cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  int ans = INF;
  rep(i, n) {
    cin>>c[i];
    rep(j, m) cin>>a[i][j];
  }

  rep(i, 1<<12) {
    int tmp = 0;
    vector<int> at(m);
    rep(j, n) {
      if (i & (1<<j)) {
        tmp += c[j];
        rep(k, m) at[k] += a[j][k];
      }
    }
    bool good = true;
    rep(j, m) {
      if (at[j] < x) good = false;
    }
    if (good) ans = min(tmp, ans);
  }
  if (ans == INF) print(-1);
  else print(ans);

  return 0;
}

Measured memory_bytes: 3664
primes = [2]

MOD = 10**9 + 7
def isPrime(n):
    if n % 2 == 0 or n < 2:
        return False
    for i in range(3,int(n/2)):
        if n % i == 0:
            return False
    return True

for i in range(3,1000,2):
    if isPrime(i):
        primes.append(i)


N = int(input())
factors = [[0 for j in range(N)] for i in range(len(primes))]

for i in range(N):
    j = i+1
    tmp = j
    a = 0
    while primes[a] <= tmp:
        if tmp % primes[a] == 0:
            factors[a][i] += 1
            tmp /= primes[a]
        else:
            a += 1
l = [sum(t) for t in factors]
ans = 1
for i in l:
    ans *= i+1
print(ans % MOD)

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

// bitsetでフラッグ管理

int main() {
  int N;
  cin >> N;
  
  bitset<101> flag;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    flag.set(num);
  }
  
  cout << flag.count() << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    vi c(n);
    FOR(i,0,m){
        cin >> a >> b;
        c[a-1]++;
        c[b-1]++; 
    }
    FOR(i,0,n){
        cout << c[i] << endl;
    }
    cout << endl;
}

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

int main()
{
    int n,i,k=0,p=0,l=0,m=0;
    string s;
    cin>>n;
    while(n--)
    {
        cin>>s;
        if(s=="AC")
            k++;
        else if(s=="WA")
            p++;
        else if(s=="TLE")
            l++;
        else
            m++;
    }
    cout<<"AC x "<<k<<endl;
    cout<<"WA x "<<p<<endl;
    cout<<"TLE x "<<l<<endl;
    cout<<"RE x "<<m<<endl;

    return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b)
{
    return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long MOD = 2;

void func(long long N, std::vector<long long> A)
{
    int cnt = 0;
    int div = 2;
    bool flag = false;

    do {
        for (int i = 0; i < N; i++) {
            if (A[i] % div != 0) {
                flag = true;
                break;
            }
        }
        div *= 2;
        cnt++;
    } while (!flag);

    printf("%d\n", cnt - 1);
}

int main()
{
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    func(N, std::move(A));
    return 0;
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

vector<int64_t> mybit(int64_t p, int64_t q, int64_t N) //p bit探索 N桁
{
    vector<int64_t> bit;
    while (q >= p)
    {
        int64_t tmp = q % p;
        bit.push_back(tmp);
        q /= p;
    }
    bit.push_back(q % p);
    bit.resize(N);
    return bit;
}

int main()
{
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    int s = S.size() - 1;
    vector<int> list(s + 1);
    for (int i = 0; i < s + 1;i++)
        list[i] = (int)S[i] - 48;
    int64_t ans = 0;
    for (int i = 0; i < pow(2, s); i++)
    {
        auto bt = mybit(2, i, s);
        ans += list[0];
        int64_t keta = 1;
        for (int j = 0; j < s; j++)
        {
            if(bt[j])
                keta *= 10;
            else
                keta = 1;
            ans += list[j + 1] * keta;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4072
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;
int main(){
 double a,b;
 cin >>a>>b;
 if(a<b) cout <<"LESS" <<endl ;
 else if(a>b) cout <<"GREATER"<<endl;
 else cout <<"EQUAL"<<endl;

}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    if (D == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }else if (D == 23){
        cout << "Christmas Eve Eve" << endl;
    }else if (D == 24){
        cout << "Christmas Eve" << endl;
    }else{
        cout << "Christmas" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

struct Node
{
    vector<int> edges;
    int depth = 0;
};

using Graph = vector<Node>;
using Costs = vector<vector<int>>;

bool Extract(stack<int> &st, int last_node)
{
    int len = 1;
    while (st.top() != last_node) {
        st.pop();
        len += 1;
    }
    st.pop();

    len -= (len - 2) / 2;

    return len % 2 == 0 || len == 1;
}

bool Dfs(Graph &g, int node)
{
    g[node].depth += 1;
    for (const auto &next : g[node].edges) {
        if (g[next].depth == 0) {
            g[next].depth = g[node].depth;
            if (!Dfs(g, next)) {
                return false;
            }
        } else if ((abs(g[node].depth - g[next].depth) + 1) % 2 == 1) {
            return false;
        }
    }
    return true;
}

void FindCosts(Costs &costs)
{
    int nodes = costs.size();
    for (int k = 0; k < nodes; k += 1) {
        for (int i = 0; i < nodes; i += 1) {
            for (int j = 0; j < nodes; j += 1) {
                if (i == j || i == k || j == k) {
                    continue;
                }
                if (costs[i][k] != 0 && costs[k][j] != 0) {
                    int cost = costs[i][k] + costs[k][j];
                    costs[i][j] = (costs[i][j] == 0 ? cost : min(costs[i][j], cost));
                }
            }
        }
    }
}

int Solve(Graph &g, Costs &costs)
{
    if (!Dfs(g, 0)) {
        return -1;
    }

    FindCosts(costs);

    int res = 0;
    for (const auto &row : costs) {
        for (const auto &cost : row) {
            res = max(res, cost + 1);
        }
    }
    return res;
}

int main()
{
    int nodes;
    cin >> nodes;
    cin.get();

    Graph graph(nodes);
    Costs costs(nodes, vector<int>(nodes));

    for (int i = 0; i < nodes; i += 1) {
        string edges;
        getline(cin, edges);

        for (int j = 0; j < nodes; j += 1) {
            if (edges[j] == '1') {
                graph[i].edges.push_back(j);
            }
            costs[i][j] = edges[j] - '0';
        }
    }

    auto res = Solve(graph, costs);
    cout << res << "\n";

    return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}


/*{
  }*/

template<int M>
class Combination
{
public:
  int n;
  vector<int> fac, finv;

  Combination(int n_) : n(n_), fac(n_), finv(n_)
  {
    fac[0] = 1;
    for(int i = 1; i < n; i++) fac[i] = fac[i-1]*i%M;
    finv[n-1] = pow(fac[n-1], M-2);
    for(int i = n-1; i > 0; i--) finv[i-1] = finv[i]*i%M;
  }

  int pow(int a, int b)
  {
    if(b == 0) return 1; 
    return pow(a*a%M, b/2)*(b%2?a:1)%M;
  }

  int C(int a, int b)
  {
    if(b < 0 or a < b) return 0;
    return fac[a]*finv[a-b]%M*finv[b]%M;
  }

  int P(int a, int b)
  {
    if(b < 0 or a < b) return 0;
    return fac[a]*finv[a-b]%M; 
  }

  int H(int a, int b){
    if(a == 0 and b == 0) return 1;
    return C(a+b-1, b);
  }
};

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

constexpr int mod = 1e9+7;

signed main(){
  Combination<mod> comb(201010);

  int h, w, a, b;
  cin >> h >> w >> a >> b;

  int ans = 0;
  rep(i, 0, min(h-a, w-b)){
//    cout << h-a-1-i << " " << b+i << " " << a+i << " " << w-b-1-i << endl;
    ans += (comb.C(h-a-1+b, b+i)*comb.C(a+i+w-b-1-i, a+i))%mod;
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}



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

int main(void){
    
    int A, B, K;
    cin >> A >> B >> K;
    
    int AB_min = min(A, B);
    
    for(int i =AB_min; i >= 1; i--){
        if(A % i == 0 && B % i == 0){
            K--;;
            if(K == 0){
                cout << i << endl;
                return 0;
            }
        }
    }

    
}


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

#define pb push_back
#define INF 1e9+9

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

	int n, x, k;	cin >> n >> k;
	vector<int>T;
	for(int i=0; i<n; i++)	
		cin >> x, T.pb(x);	
	vector<int>DP(n, INF);
	DP[0] = 0;
	for(int i=0; i<n; i++)
		for(int j=i+1; j<=i+k; j++)
			if(j<n)
			DP[j] = min(DP[j], DP[i]+abs(T[i]-T[j]));
	cout << DP[n-1];
	return 0;
}


Measured memory_bytes: 1144
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int main() {
    int na, nb, m;
    cin >> na >> nb >> m;
    vector<int> a(na); fr(i, na) cin >> a[i];
    vector<int> b(nb); fr(i, nb) cin >> b[i];
    int best = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());

    int x, y, c, price;    
    fr(_, m) {
        cin >> x >> y >> c;
        price = a[x-1] + b[y-1] - c;
        best = min(best, price);
    }
    cout << best << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;


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

    int i = 0;
    while(N != 0) {
        N /= K;
        i++;  
    }

    cout << i << endl;

    return 0;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll h, a;std::cin >> h >> a;
  std::cout << (h/a) + (h%a!=0?1:0) << '\n';
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

// SegmentTree
template <class DataType>
class SegmentTree
{
public:
    using OpType = std::function<DataType(DataType, DataType)>;
    int N;
    std::vector<DataType> dat;
    DataType e; // identity element
    OpType op;

    SegmentTree(std::vector<DataType>& base,
        DataType e0, OpType op0): e(e0), op(op0)
    {
        N = 1;
        while(N < base.size()) N *= 2;
        dat.resize(2*N-1);
        for(int i=0; i<N; i++)
            dat[i+N-1] = (i<base.size()) ? base[i] : e;
        for(int i=N-2; i>=0; i--) dat[i] = op(dat[2*i+1], dat[2*i+2]);
    }
    void update(int index, DataType value){
        int i = index + N-1;
        dat[i] = value;
        while(i > 0){
            i = (i-1) / 2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
    }
    DataType subQuery(int qleft, int qright, int tmp, int sleft, int sright){
        if(qleft <= sleft && sright <= qright) return dat[tmp];
        if(sright <= qleft || qright <= sleft) return e;

        int mid = (sleft + sright) / 2;
        return op(subQuery(qleft, qright, 2*tmp+1, sleft, mid),
            subQuery(qleft, qright, 2*tmp+2, mid, sright));
    }
    DataType query(int left, int right){
        return subQuery(left, right, 0, 0, N);
    }
    void print(){
        for(int i=N-1; i<2*N-1; i++) std::cout << dat[i] << " ";
        std::cout << std::endl;
    }
};

int main()
{
    const ll MOD = 998244353;

    ll N;
    cin >> N;
    vector<Pll> R(N);
    for(int i=0; i<N; i++) cin >> R[i].first >> R[i].second;
    sort(R.begin(), R.end());
    vector<ll> X(N), D(N);
    for(int i=0; i<N; i++) X[i] = R[i].first;
    for(int i=0; i<N; i++) D[i] = R[i].second;

    // debug(X);
    vector<ll> T(N);
    SegmentTree<ll> segtree(T, (ll)0, [](ll a, ll b)->ll{
        return max(a, b);
    });
    for(int i=N-1; i>=0; i--){
        auto itr = lower_bound(X.begin(), X.end(), X[i]+D[i]);
        ll j = distance(X.begin(), itr);
        if(i+1==j) T[i] = i;
        else T[i] = segtree.query(i, j);
        segtree.update(i, T[i]); 
    }
    // debug(X);
    // debug(D);
    // debug(T);

    vector<ll> dp(N+1);
    dp[N] = 1;
    for(int i=N-1; i>=0; i--){
        dp[i] = (dp[i+1] + dp[T[i]+1]) % MOD;
    }

    cout << dp[0] << endl;
}

Measured memory_bytes: 13696
#include <iostream>
#include <cstdio>
using namespace std;
const int N=1e6+10;
int a[N],n;

int main()
{
    int i,q,key,sum=0;
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i];
    cin>>q;
    for(i=0;i<q;i++){
        cin>>key;
        if(*lower_bound(a, a+n, key)==key)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3424
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

string s;

bool mark[128];

int main()
{
	cin >> s;
	for (int i = 0;i < s.size();i++)
		mark[s[i]] = true;
	cout << ((mark['N'] ^ mark['S']) || (mark['W'] ^ mark['E']) ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#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 RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

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

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<ll, int>> p;
	ll a,b;
	rep(i, n) {
		cin >> a >> b;
		p.emplace_back(a, b);
	}

	sort(all(p));
	ll ans = 0, cnt = 0;
	rep(i, n) {
		//cout << p[i].first << " " << p[i].second << endl;

		if (p[i].second <= m-cnt) {
			cnt += p[i].second;
			ans += p[i].first*p[i].second;
		} else if (p[i].second >= m - cnt) {
			//cout << m - cnt << endl;
			ans += p[i].first*(m - cnt);
			cnt += m - cnt;
		}
		//cout << cnt << " " << ans << endl;
	}
	cout << ans << endl;
}




 

Measured memory_bytes: 2420
import sys
sys.setrecursionlimit(2500)

def dfs(v):
    y, x = v
    checked[y][x] = 1
    ret = 1
    for dy, dx in directions:
        if y+dy>=h or y+dy<0 or x+dx>=w or x+dx<0:
            continue
        elif Map[y+dy][x+dx]==0:
            continue
        if not checked[y+dy][x+dx]:
            ret +=  dfs((y+dy, x+dx))
    return ret


directions = ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1))
while 1:
    w, h = map(int, input().split())
    if w==0 and h==0:
        break
    Map = [list(map(int, input().split())) for _ in range(h)]
    SUM = sum([sum(l) for l in Map])
    checked = [[0]*w for _ in range(h)]
    ans = 0
    cnt = 0
    for i in range(h):
        for j in range(w):
            if not checked[i][j] and Map[i][j]!=0:
                ans += 1
                cnt += dfs((i, j))
            if cnt==SUM:
                break
    print(ans)
    
    
    


Measured memory_bytes: 8104