akhauriyash/Code-Regression huggingface dataset:
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use std::*;

#[allow(dead_code)]
const MOD: i128 = 100_000_007;

#[fastout]
fn main() {
    input!{
        n :usize,
        s : Chars
    }
    let lens = s.len();
    if lens > n {
        println!("{}...",s.iter().take(n).collect::<String>());
    } else {
        println!("{}",s.iter().collect::<String>());
    }
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n ; cin >> n;
    vector<ll> d(n);
    rep(i,n) cin >> d.at(i);
    sort(d.begin(),d.end());
    cout << d.at(n/2) - d.at(n/2 - 1) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <cmath>

#define ll long long int
#define loop(v,n) for(ll v=0;v<n;v++)

using namespace std;

#define MAXN 100000

priority_queue<ll> s,t;


int main() {
    int a,p;
    cin >> a>>p;
    cout << (a*3+p)/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> sum(n,vector<int>(3));
    map<char,int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    sum[n-1][mp[s[n-1]]]++;
    for(int i = n-2; i >= 0; i--){
        rep(j,3) sum[i][j] = sum[i+1][j];
        sum[i][mp[s[i]]] = sum[i+1][mp[s[i]]]+1;
    }
    ll ans = 0;
    rep(i,n-2)repr(j,i+1,n-1){
        if(s[i] == s[j]) continue;
        int k = 3-mp[s[i]]-mp[s[j]];
        ans += sum[j+1][k];
        if(2*j-i < n && mp[s[j+j-i]] == k) ans--;
    }
    cout << ans << endl;
       
}


Measured memory_bytes: 3828
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i];
  }

  double avg = 0.0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      double tmp = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
      avg += sqrt(tmp);
    }
  }
  avg /= N * (N - 1) / 2; 

  cout << setprecision(20) << avg * (N - 1) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>

using namespace std;

int main(){
    vector<int> v(5,0);
    for(int i=0;i<5;i++){
        cin >> v[i];
    }
    vector<int> v_sa(5,0);
    for(int i=0;i<5;i++){
        if(v[i]%10!=0){
            v_sa[i]=10-(v[i]%10);
        }
    }
    sort(v_sa.begin(),v_sa.end());
    int ans=0;
    for(int i=0;i<5;i++){
        ans+=v[i];
        if(i!=4){
            ans+=v_sa[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	cout << (X - A) % B; // a%bはaをbで割った余り
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、必ずケーキを1個買うので持ち金から減らしておく
後は、ドーナツをできるだけ沢山買うので、それは余りを求めることに等しいね
*/

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define inf 1000000000000000
#define eps 1e-9
using namespace std;
typedef long long ll;
ll n,m,ans=-inf,maxn=0,a[100001],s[200001];
int main(){
	memset(s,0,sizeof(s));
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		if(i==1)continue;
		if(a[i-1]>a[i])a[i]+=m;
		maxn+=a[i]-a[i-1];
		if(a[i-1]<a[i]-1){
			s[a[i-1]+2]++;
			s[a[i]+1]-=a[i]-a[i-1];
			s[a[i]+2]+=a[i]-a[i-1]-1; 
		}
		if(a[i]>m)a[i]-=m;
	}
	for(int i=1;i<=m*2;i++)s[i]+=s[i-1];
	for(int i=1;i<=m*2;i++)s[i]+=s[i-1];
	for(int i=1;i<=m;i++){
		ans=max(ans,s[i]+s[i+m]);
	}
	printf("%lld",maxn-ans);
	return 0;
}

Measured memory_bytes: 2560
H, N = map(int, input().split())
special_move = input().split()
def answer(H: int, N: int, special_move: list) -> str:
    damage = 0
    for i in range(0, N):
        damage += int(special_move[i])
    if damage >= H:
        return 'Yes'
    else:
        return 'No'
print(answer(H, N, special_move))


Measured memory_bytes: 16444
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

string s;
int w;

int main(){
    
    cin >> s >> w;

    for(int i = 0; i < sz(s); i += w){
        cout << s[i];
    }
    cout << endl;
    
	return  0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

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

const int mod = 1000000007;

long cost[90005];

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

  int h,w,d,q;
  cin >> h >> w >> d;
  
  map<int, int> x;
  map<int, int> y;

  rep(i, h) {
    rep(j, w) {
      int a;
      cin >> a;
      x[a] = i;
      y[a] = j;
    }
  }

  rep(i, d) {
    int bx, by;
    for(int j = i; j <= h*w; j+=d) {
      if(j-d >= 0) {
        cost[j] = cost[j-d] + abs(x[j]-bx) + abs(y[j]-by);
      } else {
        cost[j] = 0;
      }
      bx = x[j];
      by = y[j];
    }
  }

  cin >> q;
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    cout << cost[r] - cost[l] << endl;
  }

}


Measured memory_bytes: 10240
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,tmp;
    cin >> a;
    cin >> b;
    cin >> c;
    
    if(a>b){
        tmp=b;
        b=a;
        a=tmp;
    }
    if(b>c){
        tmp=c;
        c=b;
        b=tmp;
    }
    if(a>b){
        tmp=b;
        b=a;
        a=tmp;
    }
    cout << a;
    cout << " ";
    cout << b;
    cout << " ";
    cout << c;
    cout << endl;
    
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int n;
int a[200020];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int ans=0;
	for(int i=n;i>=1;i--){
		for(int j=i+i;j<=n;j+=i){
			a[i]^=a[j];
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	for(int i=1;i<=n;i++){
		if(a[i]){
			cout<<i<<endl;
		}
	}
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;



void one_case() {
    int n, a;
    cin >> n >> a;
    cout << (n% 500 <= a ? "Yes\n" : "No\n");
}


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


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


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

using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  string s;
  // S = an... a2 a1
  cin >> s;

  // So that S = an-1 * 10^n-1 + ... + a0 * 10^0
  reverse(s.begin(), s.end());

  int n = s.size();

  // prefix sum mod 2019
  vector<int> sm(n + 1);

  // cnt[i] = how many prefix sum % 2019 == i
  vector<int> cnts(2019);
  cnts[0]++;

  int d = 1;
  for (int i = 0; i < n; ++i) {
    int digit = s[i] - '0';
    sm[i + 1] = ((digit * d) % 2019 + sm[i]) % 2019;
    d = (10 * d) % 2019;

    cnts[sm[i + 1]]++;
  }

  int ret = 0;

  // how many pairs for every resisual mod 2019
  // n choose 2 = n * (n-1) / 2
  for (int cnt : cnts) {
    ret += cnt * (cnt - 1) / 2;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
int n;
vector<double> v;
vector<vector<double>> dp;
double solve(int qntCaras, int i){
    if(qntCaras == (n/2) + 1) return 1.0;
    if(i == n) return 0;
    if(n - i + qntCaras < (n/2) + 1) return 0;
    if(dp[qntCaras][i] != -1) return dp[qntCaras][i];
    double ret = v[i]*solve(qntCaras+1,i+1) + (1-v[i])*solve(qntCaras,i+1);
    dp[qntCaras][i] = ret;
    return ret;
}

int main(){
    cin >> n;
    v.resize(n);
    dp.resize(n);
    for(int i = 0 ; i < n ; i++) dp[i].resize(n,-1);
    for(int i = 0 ; i < n ; i++){
        cin >> v[i];
    }
    cout << fixed << setprecision(10) << solve(0,0) << endl;
}

Measured memory_bytes: 70912
N = int(input())
P = list(map(int, input().split()))

Pi = [0] * (N + 1)
for i, n in enumerate(P, 1):
    Pi[n] = i

i = N - 1
T = 0
f = 0

while i:
    i_f = Pi[f]
    i_i = Pi[i]
    i_ii = Pi[i + 1]
    if i_f < i_ii < i_i or i_i < i_f < i_ii or i_ii < i_i < i_f:
        T += 1
        f = i + 1
    i -= 1

print(T)

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(c-a)<=d){
        cout << "Yes" << endl;
    }
    else if(abs(c-b)<=d&&abs(b-a)<=d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3544
#include <iostream>
#include <tuple>

using namespace std;

tuple <int, int, int> money(int n, int y) {
  int total;
  for (int i = 0; i <= n; i++) {
  	for (int j = 0; j <= n - i; j++) {
      total = 10000 * i + 5000 * j + 1000 * (n - i - j);
      if (total == y) {
        return forward_as_tuple(i, j, n - i - j);
      }
    }
  }
  return forward_as_tuple(-1, -1, -1); 
}

int main () {
  int N, Y;
  cin >> N >> Y;
  int i, j, k;
  tie(i, j, k) = money(N, Y);
  cout << i << " " << j << " " << k << endl;
  return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n;
  cin >> n;
  int ans = n;
  vector<int> a(n);
  for (auto&& i : a) {
    cin >> i;
  }
  sort(a.begin(), a.end());
  auto b = a;
  b.erase(unique(b.begin(), b.end()), b.end());
  for (int i = 0; i < b.size(); i++) {
    int cnt = upper_bound(a.begin(), a.end(), b[i]) - lower_bound(a.begin(), a.end(), b[i]);
    if (cnt >= b[i]) {
      ans -= b[i];
    }
  }
  cout << ans << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  hawawa();
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long ll;

ll W, H, x, y;

int main() {
    cin >> W >> H >> x >> y;
    cout << (double)(W*H)/2 << " ";
    if (W%2 == 0 && H%2 == 0 && W/2 == x && H/2 == y) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

int A,B,C;
int main (){
    cin >> A >> B >> C;
    if( A + B + C == 17 && ((A==5||A==7) && (B==5||B==7))){
        cout << "YES" << endl;
    } else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100, lg = 20;
struct query {
	int i, x, y, sig;
};
vector<tuple<int,int,int> > e[maxn];
vector<query> que[maxn];
int par[lg][maxn], dep[maxn];
void dfs(int u, int p){
	par[0][u] = p;
	for(auto ee : e[u]){
		int to, b, c; tie(to, b, c) = ee;
		if(to != p){
			dep[to] = dep[u] + 1;
			dfs(to, u);
		}
	}
}
int lca(int u, int v){
	if(dep[u] < dep[v]) swap(u, v);
	for(int i = lg - 1; i >= 0; i--) if((dep[u] - dep[v])&(1<<i)) u = par[i][u];
	if(u == v) return u;
	for(int i = lg - 1; i >= 0; i--) if(par[i][u] != par[i][v]) u = par[i][u], v = par[i][v];
	return par[0][u];
}
int ans[maxn], tot[maxn], amn[maxn];
void solve(int u, int p, int d){
	for(auto q : que[u]){
		ans[q.i] += q.sig * (d - tot[q.x] + q.y * amn[q.x]);
	}
	for(auto ee : e[u]){
		int to, c, di; tie(to, c, di) = ee;
		if(to == p) continue;
		tot[c] += di;
		amn[c] += 1;
		solve(to, u, d + di);
		tot[c] -= di;
		amn[c] -= 1;
	}
}
int main(){
	int n, q; cin >> n >> q;
	for(int i = 0; i < n - 1; i++){
		int a, b, c, d; cin >> a >> b >> c >> d;
		e[a].push_back(make_tuple(b, c, d));
		e[b].push_back(make_tuple(a, c, d));
	}
	dfs(1, 0);
	for(int i = 1; i < lg; i++){
		for(int j = 1; j <= n; j++)
			if(par[i - 1][j])
				par[i][j] = par[i - 1][par[i - 1][j]];
	}
	for(int i = 0; i < q; i++){
		int x, y, u, v; cin >> x >> y >> u >> v;
		que[u].push_back({i, x, y, 1});
		que[v].push_back({i, x, y, 1});
		que[lca(u, v)].push_back({i, x, y, -2});
	}
	solve(1, 0, 0);
	for(int i = 0; i < q; i++) cout << ans[i] << endl;
	return 0;
}



Measured memory_bytes: 30836
#include<stdio.h>

int main(){

 int a[10000],b[10000],n,m,i,j;
 int count=0;


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

  scanf("%d",&m);
  for(j=0;j<m;j++){
   scanf("%d",&b[j]);}


  for(j=0;j<m;j++){
    for(i=0;i<n;i++){
if(a[i]==b[j]){count++;
break;
}
}
}
 printf("%d\n",count);
 return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using ll = long long int;
using ld = long double;
using str = string;

int main(){
  kyopro;
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  char c = S.at(K-1);
  if(c == 'A'){
    c = 'a';
  }
  else if(c == 'B'){
    c = 'b';
  }
  else{
    c = 'c';
  }
  S.at(K-1) = c;
  cout << S << rt;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var H int
var W int
var h int
var w int

func main() {
	H = nextInt()
	W = nextInt()
	h = nextInt()
	w = nextInt()
	fmt.Printf("%v", (H-h)*(W-w))
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

#iを始点とする列車。のなかでjを終点とする列車の数をもつ配列
ruiseki = [[0]*(N+1) for i in range(N+1)]

for i in range(M):
    L,R = map(int,input().split())
    ruiseki[L][R]+=1

#累積和をとります
for i in range(0,N+1,1):
    for j in range(1,N+1,1):
        ruiseki[i][j] = ruiseki[i][j]+ruiseki[i][j-1]

ans = []

#クエリ処理
for q in range(Q):
    l,r = map(int,input().split())

    #始点がl-rにあるものすべての列車のなかで終点がl-rにあるもの
    tmpans = 0
    for i in range(l,r+1,1):
        tmpans += ruiseki[i][r]
    ans.append(tmpans)

for i in range(Q):
    print(ans[i])


Measured memory_bytes: 83408
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
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

N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

M=1

dic={}

for a in A:
    Z=1
    arr=factorization(a)
    for b,c in arr:
        if b in dic:
            if c>dic[b]:
                M=M*pow(b,c-dic[b],mod)%mod
                dic[b]=c
        else:
            dic.update({b:c})
            M=M*pow(b,c,mod)%mod
M%=mod

print(sum([M*pow(a,mod-2,mod)%mod for a in A])%mod)


Measured memory_bytes: 70616
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h;
    int w;
    int n;
    int k;
    cin>>h;
    cin>>w;
    cin>>n;
    if(h>w){
        if(n%h>0){
            k=((n-n%h)/h+1);
        }
        else{
            k=n/h;
        }
    }
    else{
        if(n%w>0){
            k=((n-n%w)/w+1);
        }
        else{
            k=n/w;
        }
    }
    cout<<k<<endl;
}


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

    printf("%d\n",sum);
    
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define exchange(a,b) {typeof(a) __tmp=a;a=b;b=__tmp;}
 
 
char A[100001];
int B[100001];
 
 
int Partition(int A[], int p, int r) {
  int i,j;
  int x;
  x = A[r];
  i = p-1;
  for(j = p; j < r; ++j) {
    if(B[A[j]] <= B[x]) { // if(A[j] <= x) {
      i = i+1;
      exchange(A[i], A[j]);
    }
  }
  exchange(A[i+1], A[r]);
  return i+1;
}
 
void Quicksort(int A[], int p, int r) {
  int q;
  if(p < r) {
    q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}
 
int isStable(int A[], int n) {
  int i;
  for(i = 2; i <= n; ++i) {
    if(B[A[i-1]] == B[A[i]] && A[i-1] > A[i]) return 0;
  }
  return 1;
}
 
int main() {
  int i;
  int n;
  int C[100001];
  scanf("%d", &n);
  for(i = 1; i <= n; ++i) {
    scanf(" %c %d", A+i,B+i);
    C[i] = i;
  }
  Quicksort(C,1,n);
  if(isStable(C,n)) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 1; i <= n; ++i) {
    printf("%c %d\n", A[C[i]], B[C[i]]);
  }
  return 0;
}

Measured memory_bytes: 1916
#include <stdio.h>

int main(void)
{
    int N, M;
    int a, b;
    int ab[100000];
    int ai, bi,
        aj, bj;
    int i;
    int ctr = 1;
     
    
    scanf("%d %d", &N, &M);
    
    
    for(i=1; i<N; i++)
        ab[i] = 999999;
    
    
    for(i=1; i<=M; i++)
    {
        scanf("%d %d", &a, &b);
        
        if(ab[a] > b)
            ab[a] = b;
    }
    
    for(i=1; i<N; i++) 
    {
        if(ab[i] != 999999)
        {
            ai = i;
            bi = ab[i];
            
            break;
        }
    }
    
    for(; i<N; i++)
    {
        if(ab[i] != 999999)
        {
            aj = i;
            bj = ab[i];
            
            if(bi <= aj)
            {
                ai = aj;
                bi = bj;
                ctr++;
            }
            else
            {
                ai = aj;
                        
                if(bi > bj)
                    bi = bj;
            }
        }
    }
    
    printf("%d\n", ctr);

    //system("pause");
    
    return 0;
}

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

int main()
{
  long long N,N1,A,B,ans;scanf("%lld %lld %lld",&N,&A,&B);
  if((B-A)%2==0){ans=abs(B-A)/2;printf("%lld",ans);return 0;}
  N1=min(N-B,A-1);ans=N1;
  if(N-B>A-1)
  {
    ans=A;
    B=B-A+1;A=1;
    printf("%lld",ans+(B-A)/2);
  }
  else
  {
    ans=N-B+1;
    A=A+N-B+1;B=N;
    printf("%lld\n",ans+(B-A)/2);
  }
}

Measured memory_bytes: 3828
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int N;
  scanf("%d",&N);
  int x = N/7;
  for(int i=0;i<=x;i++){
    if((N-7*i)%4==0){
      printf("Yes");
      exit(0);
    }
  }
  printf("No");
  return 0;
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか) */

  int n;

  int a,b,c;


  while(1){
    cin>>n;

    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
    

      if(a==100||b==100||c==100){
	cout<<'A'<<endl;
      }else if((a+b)/2>=90){
	cout<<'A'<<endl;
      }else if((a+b+c)/3>=80){
	cout<<'A'<<endl;
      }else if((a+b+c)/3>=70){
	cout<<'B'<<endl;
      }else if((a+b+c)/3>=50&&(a>=80||b>=80)){
	cout<<'B'<<endl;
      }else{
	cout<<'C'<<endl;
      }
    }

  }
    return 0;

  }



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

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> p(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        p[i]=make_pair(a,b);
    }
    for (int i = 0; i < n; i++) {
        swap(p[i].first,p[i].second);
    }
    sort(p.begin(),p.end());
    int time = 0;
    bool f = true;
    for (int i = 0; i < n; i++) {
        time += p[i].second;
        if (time > p[i].first) {
            f = false;
            break;
        }
    }
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1792
main = do
    n:k:_ <- (fmap read).words <$> getLine
    main' n k 1

main' n k i
    | k<i = pure ()
    | otherwise = do
        print$solve n k i
        main' n k (i+1)

solve n k 1
    | n==k = 1
    | n==k+1 = 2
    | otherwise = 2+f z 2 where z=n-k
solve n k i = f k i *** (f z (i-1) + 2*f z i + f z (i+1)) where z=n-k

f l s = g (l-s) s
g l s = c (l+s-1) (s-1)
c _ 0 = 1
c n r = m///l where (m, l) = z n r
z n 1 = (n, 1)
z n r = (n***m, r***l) where (m, l) = z (n-1) (r-1)

inv = inv' y
inv' m = (flip mod y).snd.i m
i x 1 = (0, 1)
i x y
    | mod x y == 1 = (1, -div x y)
    | otherwise = (w, (v-w*k))
        where
            k = div x y
            (v, w) = i y (mod x y)
y = 10^9+7

(***)::Int->Int->Int
(***) a b = mod (a * b) y
(///)::Int->Int->Int
(///) a b = a *** inv b

Measured memory_bytes: 1532
from operator import xor

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


def multiples(n, m):
    # m以下のnの倍数を返す
    lst = list()
    num = n
    while True:
        if num <= m:
            lst.append(num)
            num += n
        else:
            break
    return lst


ans = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    s = 0
    for m in multiples(i, N):
        s += ans[m]
    s %= 2
    ans[i] = xor(s, A[i - 1])

s = sum(ans)
print(s)
if s != 0:
    print(' '.join([str(i) for i in range(1, N + 1) if ans[i] > 0]))




Measured memory_bytes: 14772
#include <stdio.h>

int main(){
  char s[105];
  for(int i=0;i<105;i++){
    s[i]='Z';
  }
  scanf("%s",s);
  int size=-1;
  for(int i=0;i<105;i++){
    if(s[i]=='Z') {size=i;break;}
  }
  printf("%c%d%c",s[0],size-3,s[size-2]);
}


Measured memory_bytes: 128
N, K = map(int, input().split())
hlis = list(map(int, input().split()))
dp = [float('inf')]*(N+1)
dp[1] = 0
for i in range(1, N):
    for j in range(1,min(K+1, N-i+1)):
        dp[i+j] = min(dp[i+j], dp[i] + abs(hlis[i-1]-hlis[i+j-1]))
print(dp[-1])

Measured memory_bytes: 55136
S = list(input())
ans = 'Yes'
for i in range(len(S)):
    if (i + 1) % 2 == 0 and S[i] == 'R':
        ans = 'No'
    if (i + 1) % 2 == 1 and S[i] == 'L':
        ans = 'No'
print(ans)

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll X;
vector<ll> A;

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

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

  cin >> X;
  ll ans = 0;
  ll mai = X/500;
  ans += 1000 * mai;
  X -= 500*mai;
  mai = X/5;
  ans += 5 * mai;
  X /= 5;
  cout << ans << endl;
  return 0;
}


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

using ll = long long;
using namespace std;
int main() {
    ll N, M; cin >> N >> M;

    vector<ll> a(M);
    for(ll i=0;i<M;++i)cin>>a[i];

    ll num[100100] = {};
    ll brokenis1[100100] = {};
    for(ll i=0; i<M; ++i) brokenis1[a[i]] = 1;
    num[0] = 1;
    if(brokenis1[1] == 0) {
        num[1] = 1;
    } else {
        num[1] = 0;
    }
    for (ll i = 2; i <= N; i++) {
        if(brokenis1[i] == 0) {
            num[i] = (num[i-1] + num[i-2]) % 1000000007;
        }
    }
    cout << num[N] << "\n";
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
using namespace std;
const long long m = 1000000007;
long long p(long long b, long long e) {
	if (e == 0) return 1;
	long long a = p(b, e / 2);
	a = a * a % m;
	if (e % 2) a = a * b % m;
	return a;
}
int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	long long fac[n];
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = i * fac[i - 1] % m;
	long long ans = 0;
	for (int i = max(1, n - k); i <= n; ++i) ans = (ans + fac[n - 1] * p(fac[i - 1], m - 2) % m * p(fac[n - i], m - 2) % m * fac[n] % m * p(fac[i], m - 2) % m * p(fac[n - i], m - 2) % m) % m;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1792
import sys
from collections import deque

input = sys.stdin.readline

s = int(input())
a = deque()
a.append(s)
counter = 0

if s == 2 or s == 1:
    print(4)
    exit()

for i in range(10000000):
    if a[i] == 4:
        break
    counter += 1
    if a[i] % 2 == 0:
        a.append(int(a[i]/2))
    else:
        a.append(3*a[i] + 1)

print(counter + 4)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
int main(){
	int x,k;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++){
		cout<<i<<" ";
	}
	cout<<endl;
	return 0;
}

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

int main() {
    int m, f, r;
    
    while(1) {
        cin >> m >> f >> r;
        int sum = m + f;
        if (m == -1 && f == -1 && r == -1) {
            return 0;
        }
        
        if (m == -1 || f == -1) {
            cout << 'F' << endl;
        } else if (sum >= 80) {
            cout << 'A' << endl;
        } else if (sum >= 65) {
            cout << 'B' << endl;
        } else if (sum >= 50) {
            cout << 'C' << endl;
        } else if (sum >= 30) {
            if (r >= 50) {
                cout << 'C' << endl;
            } else {
                cout << 'D' << endl;
            }
        } else {
            cout << 'F' << endl;
        }
    }
}


Measured memory_bytes: 3088
n, k, q = map(int, input().split())
l = [k for _ in range(n)]

l = list(map(lambda x: x - q, l))

for i in range(q):
    a = int(input())
    l[a - 1] += 1

for j in range(n):
    if l[j] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 85800
"use strict"
function main(arg) {
    var yokia = parseInt(arg.trim().split(" ")[0]);
    var yokib = parseInt(arg.trim().split(" ")[1]);
    var yokic = parseInt(arg.trim().split(" ")[2]);

    var kotae = 0;

    var hairumizu = yokia - yokib;
    kotae = yokic - hairumizu;
    
    if(kotae < 0){
        kotae = 0;
    }

    console.log(kotae);


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
n = int(input())
numbers = list(map(int, input().split()))
numbers.sort()

ai = numbers[-1]
r = ai / 2

for i in range(n - 1):
    if numbers[i] == r:
        ans = [ai, int(r)]
        break
    if numbers[i] > r:
        if numbers[i] - r < r - numbers[i - 1]:
            ans = [ai, numbers[i]]
        break
    ans = [ai, numbers[i]]

print(*ans)


Measured memory_bytes: 14432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int n; sc(n);
    bool check = true;
    vector<int> h(n);
    rep(i, 0, n) sc(h[i]);
    for (int i = n-2; i >= 0; i--){
        if (h[i+1] < h[i]) h[i] -= 1;
        if (h[i+1] < h[i]){
            check = false;
            break;
        }
    }
    if (check) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define endl '\n'

using namespace std;

int h[100001];

int a[100001];       

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  long long N;

  cin>>N;

  cout<<((N-1)*(N))/2<<endl;

  
  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 100
#define MAX_W 100000

struct item{
    int v;
    int w;
};

int N,W;
struct item item1[MAX_N];
long long tmp[MAX_N+1][MAX_W+1];

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

    for(int i=0;i<=W;i++){
        tmp[0][i]=0;
    }
    for(int i=1;i<=N;i++){
        struct item it=item1[i-1];
        for(int j=0;j<=W;j++){
            if (j-it.w>=0){
                tmp[i][j] = max(tmp[i-1][j-it.w]+it.v,tmp[i-1][j]);
            }else{
                tmp[i][j] = tmp[i-1][j];
            }
            
        }
    }
    long max=0;
    for(int j=0;j<=W;j++){
        if(tmp[N][j]>max){
            max=tmp[N][j];
        }
    }
    return max;
}
int main(){
    scanf("%d %d",&N,&W);
    
    for(int i=0;i<N;i++){
        scanf("%d %d",&((item1+i)->w),&((item1+i)->v));
    }

    printf("%ld\n",ans());
    
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 2005;
const int mod = 1e9 + 7;

int n, sz[MAXN], p[MAXN];
vector<int> gph[MAXN];

lint dp[MAXN][MAXN][2];
lint fact[MAXN];
lint aux[MAXN][3], nxt[MAXN][3];

int main(){
	fact[0] = 1;
	for(int i=1; i<MAXN; i++) fact[i] = fact[i-1] * i % mod;
	cin >> n;
	for(int i=2; i<=n; i++){
		cin >> p[i];
		gph[p[i]].push_back(i);
	}
	for(int i=n; i; i--){
		memset(aux, 0, sizeof(aux));
		aux[0][0] = 1;
		for(auto &j : gph[i]){
			memset(nxt, 0, sizeof(nxt));
			for(int k=0; k<=sz[j]; k++){
				for(int l=0; l<=sz[i]; l++){
					for(int m=0; m<3; m++){
						nxt[k + l][m] += dp[j][k][0] * aux[l][m] % mod;
						if(m < 2) nxt[k + l + 1][m+1] += dp[j][k][1] * aux[l][m] % mod;
					}
				}
			}
			sz[i] += sz[j];
			for(int j=0; j<=sz[i]; j++){
				for(int k=0; k<3; k++) aux[j][k] = nxt[j][k] % mod;
			}
		}
		for(int j=0; j<=sz[i]; j++){
			dp[i][j][0] = aux[j][0] + aux[j][1] * 2 + aux[j][2] * 2;
			dp[i][j][1] = aux[j][0] + aux[j][1];
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
		}
		sz[i]++;
	}
	lint ret = 0;
	for(int i=0; i<=n; i++){
		lint cur = dp[1][i][0] * fact[n - i] % mod;
		if(i & 1) cur = mod - cur;
		ret += cur;
	}
	cout << ret % mod << endl;
}


Measured memory_bytes: 61952
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int N;
ll A[100005], B[100005];

ll dfs(int cnt, ll pre){
  if (cnt == N+1) return 0;
  ll sm = 0;
  if (A[cnt] <= pre){ //一つ前の勇者で全て倒せた
    sm+= A[cnt];
    sm += dfs(cnt+1, B[cnt]); // 前の勇者は送らない
    return sm;
  }else { //一つ前の勇者をすべて使い、今の勇者も必要
    sm += pre;
    A[cnt]-=pre;
    if (A[cnt] <= B[cnt]){ // 今の勇者で全て倒せた
      sm+=A[cnt];
      sm += dfs(cnt+1, B[cnt]-A[cnt]);
    }else{ // 全ては倒せなかった
      sm += B[cnt];
      sm += dfs(cnt+1, 0);
    }
    return sm;
  }
  
}

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

  cin >> N;
  rep(i, N+1) cin >> A[i];
  rep(i, N) cin >> B[i];

  ll ans = dfs(0, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 300000

ll n,a,b,c,d;
string s;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n>>a>>b>>c>>d;
	a--;b--;c--;d--;
	cin>>s;

	char prev = '0';
	if(b-1>=0) prev = s[b-1];
	bool ok = 0;
	Foe(i,b,d){
		if(prev=='#' && s[i]=='#'){
			cout<<"No"<<endl;
			return 0;
		}
		char next = '0';
		if(i<=n-2) next = s[i+1];
		if(s[i]=='.' && prev=='.' && next=='.') ok=1;
		prev = s[i];
	}

	Foe(i,a,c){
		if(prev=='#' && s[i]=='#'){
			cout<<"No"<<endl;
			return 0;
		}
		prev = s[i];
	}
	
	if(d>c){
		cout<<"Yes"<<endl;
	}else{
		if(ok) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}





	
}

Measured memory_bytes: 592
#include<cstdio>
#include<iostream>

using namespace std;

int main(void) {

	int n, t[100001], x[100001], y[100001], k, time, px, py, jud,yes;

	cin >> n;

	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	yes = 1;

	for (k = 1; k <= n; k++) {
		cin >> t[k] >> x[k] >> y[k];
		if (yes == 1) {
			time = t[k] - t[k - 1];
			px = abs(x[k] - x[k - 1]);
			py = abs(y[k] - y[k - 1]);
			jud = time - px - py;
			if (jud == 0) {
			}
			else if (jud >= 0 && jud % 2 == 0) {
			}
			else {
				yes = 0;
			}
		}
	}
	
	if (yes==1) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}


	/*for (k = 0; k < n; k++) {
		printf("%d %d %d\n", t[k], x[k], y[k]);
	}*/

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i(a); i <= (b); ++i)

#define gc getchar()
struct Reader {
	template <class T> inline operator T() {
		T w; char c, p = 0;
		for(; !isdigit(c = gc); c == '-' && (p = 1));
		for(w = c & 15; isdigit(c = gc); w = w * 10 + (c & 15));
		return p ? -w : w;
	}
}rd;

template <class T> inline bool smin(T&x, const T&y) { return y < x ? x = y, 1 : 0; }
template <class T> inline bool smax(T&x, const T&y) { return x < y ? x = y, 1 : 0; }

typedef long long ll;

int f[100005];
int main() {
	int n = rd, m = rd;
	memset(f, 0x3f, sizeof f);
	f[0] = 0;
	while(n--) {
		int w = rd, v = rd;
		for (int i = 100000; i >= v; --i)
			smin(f[i], f[i - v] + w);
	}
	for (int i = 100000; ~i; --i)
		if (f[i] <= m) return printf("%d\n", i), 0;
	return 0;
}



Measured memory_bytes: 640
import numpy as np

n, m, x = map(int, input().split())
books = [list(map(int, input().split())) for _ in range(n)]
books = np.array(books, dtype=int)

min_cost = 10 ** 9
for bit in range(1, 1 << n):
  purchase = np.zeros(m + 1, dtype=int)
  for i in range(n):
    if bit & 1:
      purchase += books[i]
    bit >>= 1
  if np.all(purchase[1:] >= x):
    min_cost = min(min_cost, purchase[0])
if min_cost == 10 ** 9:
  print(-1)
else:
  print(min_cost)

Measured memory_bytes: 27320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

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

inline int gcd(int a, int b) { if (a%b == 0) { return b; } else { return gcd(b, a%b); } }

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

    ll total = 0;
    for (int i = 0; i < s.length(); i++) {
        int num = s[i] - '0';
        if (num == 1) {
            k -= 1;
        } else {
            k = 0;
        }
        if (0 >= k) {
            cout << num << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>

using namespace std;

int Count(const vector<int>& divs, int n) {
  int res = 0;
  for (int cnt : divs) {
    if (cnt >= n-1) ++ res;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  
  vector<int> divs(N+1);
  for (int i = 2; i <= N; ++i) {
    int n = i;
    for (int j = 2; j <= i; ++j) {
      while (n % j == 0) {
        ++divs[j];
        n /= j;
      }
    }
  }

  int res = 0;
  res += Count(divs, 75);
  res += Count(divs, 25) * (Count(divs, 3) - 1);
  res += Count(divs, 15) * (Count(divs, 5) - 1);
  res += Count(divs, 5) * (Count(divs, 5) - 1) * (Count(divs, 3) - 2) / 2;
  
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static IEnumerable<long> Solve(int N, long[] A)
        {
            Array.Sort(A);
            if (N == 2)
            {
                return new[] { A[1], A[0] };
            }
            else
            {
                long n = A.Last();
                Array.Sort(A, (a, b) => Math.Abs(n - a * 2).CompareTo(Math.Abs(n - b * 2)));
                long r = A.First();
                return new[] { n, r };
            }
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            long[] A = ReadLongs();
            Console.WriteLine(string.Join(" ", Solve(N, A)));
        }
    }
}


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

using namespace std;

long long n , a[200005] , viz[200005] , ciclu[200005];

long long k;

int main()
{
    cin >> n >> k;
    for(long long i = 1 ; i <= n ; i++)
        cin >> a[i];
    long long p = a[1] , d = 1 , j;
    ciclu[d] = p;
    viz[p] = 1;
    while(true)
    {
        p = a[p];
        if(viz[p])
            break;
        viz[p] = 1;
        ++d;
        ciclu[d] = p;
    }
    for(j = 1 ; j <= d && ciclu[j] != p ; j++)
            ;
    if(k <= j)
        cout << ciclu[k] << "\n";
    else
    {
        k -= (j - 1);
        ///cout << d << " " << j << "\n";
        k %= (d - j + 1);
        if(k == 0)
            cout << ciclu[d] << "\n";
        else cout << ciclu[j + k - 1] << "\n";
    }
    return 0;
}


Measured memory_bytes: 8108
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main(){
  string S;

  cin >> S;

  int p = 700;
  for(int i =0; i < 3; i++){
    if(S[i] == 'o') p += 100;
  }

  cout << p << endl;
}


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

int main() {
  ll L, R;
  cin >> L >> R;
  if (R-L > 2100) cout << 0;
  else {
    int res = 100000;
    for (int i = L; i < R; i++) {
      for (int j = i+1; j <= R; j++) {
        int tmp1 = i % 2019;
        int tmp2 = j % 2019;
        int tmp = (tmp1*tmp2) % 2019;
        if (res > tmp) res = tmp;
      }
    }
    cout << res;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORTR(x) sort(ALLR(x))
#define SORT(x) sort(ALL(x))
#define SUM(x) accumulate(ALL(A), 0)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}


void Main()
{
	double R;
	double length;
	cin>>R;
	length=2*M_PI*R;
	cout << length << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int n,q;
  string s;
  cin >> n >> q >> s;

  vector<int> sum_arr(s.size()+1);
  for(int i = 0; i < n; i++) {
    sum_arr[i+1] += sum_arr[i];
    if(s[i]=='A'&&s[i+1]=='C') {
      sum_arr[i+2]++;
    }
    //cout << sum_arr[i+1] << endl;
  }

  for(int loop = 0; loop < q; loop++) {
    int l,r;
    cin >> l >> r;
    int ans = (sum_arr[r]-sum_arr[l-1]);
    if(l>1&&s[l-1]=='C'&&s[l-2]=='A') ans--;
    cout << ans << endl;
  }
}


Measured memory_bytes: 1408
n = gets.to_i

ans = 0
start_with_b = 0
end_with_a = 0
ba = 0

n.times do 
  ss = gets.chomp
  ans += ss.scan("AB").count
  start_with_b += 1 if ss.start_with?("B")
  end_with_a += 1 if ss.end_with?("A")
  ba += 1 if ss.start_with?("B") && ss.end_with?("A")
end

if start_with_b == end_with_a && start_with_b == ba
  puts ans + (ba-1 >= 0 ? ba-1 : 0)
else
  puts ans + [start_with_b, end_with_a].min
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e15;

int ar[ms];


ll go(ll x, ll k, ll d, ll mov)
{
    ll mn=min(k,mov);
    if(x>0)
    {
        x-=(mn*d);
    }
    else{
        x+=(mn*d);
    }
    k-=mn;
    if(k%2)
    {
        return min(abs(x-d),abs(x+d));
    }
    return abs(x);
}

int main()
{
    idfc;
    ll x,k,d;
    cin>>x>>k>>d;

    ll mov=abs(x)/d;
    ll ans=min(go(x,k,d,mov),go(x,k,d,mov+1));
    cout<<ans;
    return 0;
}

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

int main() {
    int A,B; cin >> A >> B;
    if (A >= 13) {
        cout << B << endl;
    }
    else if (A <= 5) {
        cout << 0 << endl;
    }
    else if (6<= A <= 12) {
        cout << B/2 << endl;
    }
}

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

const int INF=1000;

int N,M;
int C[3]={INF,INF,INF};

int pow10(int x){
	if(x==0) return 1;
	else return 10*pow10(x-1);
}

int main(){
	cin>>N>>M;
	bool b=true;
	for(int i=0;i<M;i++){
		int s;
		int c;
		cin>>s>>c;
		if(C[s-1+3-N]==INF || C[s-1+3-N]==c){
			C[s-1+3-N]=c;
		}else{
			b=false;
		}
	}

	if(!b){
		cout<<-1<<endl;
		return 0;
	}
	if(C[3-N]==0 && N>1){
		cout<<-1<<endl;
		return 0;
	}

	if(C[3-N]==INF && N>1){
		C[3-N]=1;
	}

	int ans=0;
	for(int i=0;i<3;i++){
		if(C[i]!=INF){
			ans+=C[i]*pow10(2-i);
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 256