akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int h,n;
    cin>>h>>n;

    VI a(n);
    REP(i, n) cin >> a[i];

    LL sum = 0;
    REP(i,n){
        sum += a[i];
    }

    if(sum >= h){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

	return;
}

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

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
INF = float("inf")


def main():
    n, k = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    h.sort()
    ans = INF
    for i in range(n - k + 1):
        diff = h[i + k - 1] - h[i]
        ans = min(ans, diff)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7384
#include <bits/stdc++.h>
// https://boostjp.github.io/tips/multiprec-int.html
// https://boostjp.github.io/tips/multiprec-float.html
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using namespace std;

#define ll long long
#define ld long double

const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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; }

ll n,m,k;
string s;
int main() {
    INIT();

    cin >> s;

    cout << REPLACE(s, "s$", "se") << "s";
}

Measured memory_bytes: 3768
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    cout << min({a*x + b*y, c * 2 * x + (y - x > 0 ? b * (y-x):0), (x-y>0?a * (x-y):0) + c * 2 * y}) << endl;

    return 0;
}

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

struct Node {
  int parent;  // 節点の親
  int left;    // 節点の一番左の子
  int right;   // 節点の右隣の兄弟
};


int getDepth(Node T[], int u) {
  int depth = 0;
  while (T[u].parent != NIL) {
    u = T[u].parent;
    depth ++;
  }
  return depth;
}

string getType(Node T[], int u) {
  if(T[u].parent == NIL) return "root";
  else if(T[u].left != NIL) return "internal node";
  else return "leaf";

}

void printChildren(Node T[], int u) {
  vector<int> printList;
  int c = T[u].left;
  while(c != NIL) {
    printList.push_back(c);
    c = T[c].right;
  }

  cout << "[";
  rep(i, printList.size()) {
    if(i == printList.size()-1) cout << printList[i];
    else cout << printList[i] << ", ";
  }
  cout << "]";
}

int main() {
  int n; cin>>n;
  Node T[n];

  rep(i, n) T[i].parent = T[i].right = T[i].left = NIL;

  rep(i, n) {
    int id, child;
    cin >> id >> child;

    int tmp;
    rep(j, child) {
      int cid; cin >> cid;
      if(j == 0) T[id].left = cid;
      else T[tmp].right = cid;  // 一個左の兄弟のrightを自分にする

      tmp = cid;
      T[cid].parent = id;
    }
  }

  //TODO: printChildren前でセグフォが起きている
  rep(i, n) {
    cout << "node " << i << ": ";
    cout << "parent = " << T[i].parent << ", ";
    cout << "depth = " << getDepth(T, i) << ", ";
    cout << getType(T, i) << ", ";
    printChildren(T, i);
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 4536
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int main() {
    int n;
    cin >> n;
    vector<int> v(n+1), w(n+1);
    rep(i, n) cin >> v[i+1] >> w[i+1];
    int k = 1;
    int p = 2;
    while (n >= p) {
        k++;
        p <<= 1;
    }
    int k2 = k/2;
    const int maxl = 1e5;
    auto dp = make_vec<int>(1<<k2, maxl+1);
    rep(i, 1<<k2) {
        rep(j, maxl+1) {
            chmax(dp[i][j], dp[i/2][j]);
            if (j != 0) chmax(dp[i][j], dp[i][j-1]);
            if (j+w[i] <= maxl) chmax(dp[i][j+w[i]], dp[i/2][j] + v[i]);
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int u, W;
        cin >> u >> W;
        int res = 0;
        rep(bit, 1<<(k-k2)) {
            int s = u;
            int noww = 0, nowv = 0;
            rep(i, k-k2) {
                if (bit>>i&1) {
                    noww += w[s];
                    nowv += v[s];
                }
                s >>= 1;
            }
            if (noww <= W) {
                nowv += dp[s][W-noww];
                chmax(res, nowv);
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 206548
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll A;
string B;
ll BB;
int main()
{
    cin >> A >> B;
    B.erase(1,1);
    BB = stoll(B);
    ll C = A * BB;
    string D = to_string(C);
    if(D.length() <= 2)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << D.substr(0, D.length()-2) << endl;
    return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  char ch; std::cin >> ch;
  if('A' <= ch && ch <= 'Z') fin('A');
  fin('a');
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    
    sort(x.begin(), x.end());
    ll ans = ll(1e18) + 1;
    reps(p, x[n - 1] + 1,x[0])
    {
        ll tmp = 0;
        rep(i, n)
        {
            tmp += (p - x[i]) * (p - x[i]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    
 //   system("pause");
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  int p_count = 0;
  for(int i = 0; i < s.length(); ++i) p_count += s[i] == '1';
  cout << min(p_count, (int)s.length() - p_count) * 2;
  
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3732
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
      	char c[] = str.toCharArray();
        int answer = 0;
        char now = c[0];
        answer += 1;
        for (int i = 1; i < n; i++) {
            if (now != c[i]) {
              answer++;
              now = c[i];
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 27348
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;
int opinions[15][15];

int check(int arr[], int n) 
{ 
    bool posible = true;
    int ans = 0;
    bool rectify[n][2];

    for (int i = 0; i < n; i++) { 
        //cout<<arr[i];
        rectify[i][0] = 0;
        rectify[i][1] = 0;
        if(arr[i]){
            rectify[i][1] = 1;
        }else{
            rectify[i][0] = 1;
        }
    }
    /*cout<<"\n";
    fore(i,0,n){
        fore(j,0,n){
            cout<<opinions[i][j]<<" ";
        }
        cout<<"\n";
    }*/

    fore(i,0,n){
        fore(j,0,n){
            if(arr[i]){
                if(opinions[i][j] == 0){
                    rectify[j][0] = 1;
                }else if(opinions[i][j] == 1){
                    rectify[j][1] = 1;
                }
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if(rectify[i][0] && rectify[i][1]){
            posible = false;
            break;
        }
        if(rectify[i][1]){
            ans++;
        }  
    }
    //cout<<posible<<" "<<ans<<" \n\n";
    if(posible){
        return ans;
    }else{
        return 0;
    }

} 

int generateAllBinaryStrings(int n, int arr[], int i) 
{ 
    if (i == n) { 
        return check(arr, n);  
    } 
 
    arr[i] = 0; 
    int a = generateAllBinaryStrings(n, arr, i + 1); 
 
    arr[i] = 1; 
    int b = generateAllBinaryStrings(n, arr, i + 1); 

    return max(a,b);
} 

int main(){
    int persons;cin>>persons;
    std::fill(*opinions,*opinions + 15*15,-1);
    fore(i,0,persons){
        int q;cin>>q;
        fore(j,0,q){
            int a,b;cin>>a>>b;
            opinions[i][a-1] = b;
        }
    }
    int arr[persons];
    int sol = generateAllBinaryStrings(persons,arr,0);
    cout<<sol;
    
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100;
long long f[maxn];
int main(){
	int A,B,C;
	long long K;
	scanf("%d%d%d",&A,&B,&C);
	scanf("%lld",&K);
	if(K&1) swap(A,B);
	printf("%d\n",A-B);
	return 0;
}


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

int main(void){
    int h, w;
    vector <string> c;
    string s;
    int i;
    vector <string> ans;
    
    cin >> h >> w;
    
    for(i = 0; i < h; i++){
        cin >> s;
        c.push_back(s);
    }
    
    for(i = 0; i < h; i++){
        ans.push_back(c[i]);
        ans.push_back(c[i]);
    }
    

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int e=0,w=0,S=0,n=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='E')
			e=1;
		else if(s[i]=='W')
		{
			w=1;
		}
		else if(s[i]=='S')
			S=1;
		else if(s[i]=='N')
			n=1;
	}
	if(e!=w||S!=n)
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
#define LL long long
inline int read()
{
    int res=0,f=1;
    char ch=getchar();
    while(ch!='-'&&(ch>'9'||ch<'0'))
        ch=getchar();
    if(ch=='-')
        f=-1,ch=getchar();
    while(ch>='0'&&ch<='9')
        res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
    return res*f;
}
const int N=105;
int n,t[N],s[N];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	for(RI i=1;i<=n;++i)
	{
		t[i]=read();
		s[i]=s[i-1]+t[i];
	}
	int m=read();
	for(RI i=1;i<=m;++i)
	{
		int p=read(),x=read();
		printf("%d\n",s[n]-t[p]+x);
	}
	return 0;
}


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

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    set<ll> s={x};
    vector<ll> a(n),dp(x+1,0LL);
    for(int i=0;i<n;i++)cin>>a[i];dp[x]=1;
    sort(a.rbegin(),a.rend());
    for(int i=0;i<n;i++){
    	ll m=a[i];
    	for(auto& v:s){
    		s.insert(v%m);
    		ll k=dp[v];
    		(dp[v]*=(n-i-1))%=mod;
    		(dp[v%m]+=k)%=mod;
    	}
    }
    ll ans=0;
    for(int i=0;i<=x;i++)(ans+=dp[i]*i)%=mod;
    cout << ans << endl;
    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[11111];

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    rep(i,N){
        int b;cin>>b;A[i]-=b;
    }

    int K=-accumulate(A,A+N,0ll);
    if(K<0){
        cout<<"No"<<endl;
        return 0;
    }

    int T=0;
    rep(i,N)if(A[i]<0)T+=(-A[i]+1)/2;
    if(T<=K)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <cctype>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
using namespace std;


int main(){
  while(1){
    string x;
    int y=0;
    cin>>x;
    if(x=="0")break;
    size_t sin=x.length();
    rep(i,sin){
       x[i]-='0';
    
    y+=x[i];
    }
    cout<<y<<endl;
  }

}


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

typedef long long ll;
using namespace std;

struct lst
{
    private:
        int n;
        vector<ll> node;
        vector<ll> lazy;
        vector<bool> lflg;

        void lazy2node(int k, int l, int r)
        {
            if(lflg[k])
            {
                node[k]+=(r-l+1)*lazy[k];
                lflg[k]=false;
                prop(lazy[k], k, l, r);
                lazy[k]=0;
            }
        }
        
        void prop(int v, int k, int l, int r)
        {
            if(r-l>0)
            {
                lazy[2*k+1]+=v;
                lazy[2*k+2]+=v;
                lflg[2*k+1]=lflg[2*k+2]=true;
            }
        }

    public:
        lst(int sz)
        {
            n=1; while(n<sz) n*=2;
            node.resize(2*n-1, 0);
            lazy.resize(2*n-1, 0);
            lflg.resize(2*n-1, false);
        }

        void update(int qa, int qb, int v, int k=0, int l=0, int r=-1)
        {
            if(r<0) r=n-1;
            lazy2node(k, l, r);
            if(qb<l || r<qa) return;
            if(qa<=l && r<=qb)
            {
                node[k]+=(r-l+1)*v;
                prop(v, k, l, r);
            }
            else
            {
                int m=(l+r)/2;
                update(qa, qb, v, 2*k+1, l, m);
                update(qa, qb, v, 2*k+2, m+1, r);
                node[k]=node[2*k+1]+node[2*k+2];
            }
        }

        ll get(int qa, int qb, int k=0, int l=0, int r=-1)
        {
            if(r<0) r=n-1;
            lazy2node(k, l, r);
            if(qb<l || r<qa) return 0;
            if(qa<=l && r<=qb) return node[k];
            else
            {
                int m=(l+r)/2;
                ll ls=get(qa, qb, 2*k+1, l, m);
                ll rs=get(qa, qb, 2*k+2, m+1, r);
                return ls+rs;
            }
        }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    lst tree=lst(n);
    for(int i=0; i<q; i++)
    {
        int c;
        scanf("%d", &c);
        if(c)
        {
            int s, t;
            scanf("%d %d", &s, &t);
            printf("%lld\n",tree.get(s-1,t-1));
        }
        else
        {
            int s, t, x;
            scanf("%d %d %d", &s, &t, &x);
            tree.update(s-1, t-1, x);
        }
    }
    return 0;
}


Measured memory_bytes: 7044
from collections import defaultdict
H,W,N = map(int,input().split())
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    for dy in range(-1,2):
        for dx in range(-1,2):
            if a+dy >= 2 and a+dy <= H-1 and b+dx >= 2 and b+dx <= W-1:
                d[(a+dy,b+dx)] += 1
ans = [0]*10
ans[0] = (H-2)*(W-2)-len(d)
for i in d.values():
    ans[i] += 1
for i in ans:
    print(i)

Measured memory_bytes: 194544
use std::io::stdin;
use std::str::FromStr;
use std::cmp::max;

fn main(){
    let n: usize = get_one();
    let vs: Vec<i64> = get_vec();
    let cs: Vec<i64> = get_vec();
    let mut ans = 0;
    for i in 0..n {
        ans += max(0, vs[i]-cs[i]);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	string s;
	cin >> s;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] == '9') {
			cout << "Yes" << endl;
			exit(0);
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let p: u32 = read();
    let q: u32 = read();
    let r: u32 = read();

    println!("{}", [p + q, q + r, r + p].iter().min().unwrap());
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
#define endl '\n'
#define rep(i, n) for(ll i=0;i<n;++i)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=a;--i)

int main(){
    int n;
    long long d;
    cin >> n >> d;
    int ans = 0;
    for(int i=0;i<n;++i){
        long long  x,y;
        cin >> x >> y;
        if(x*x+y*y <= d*d)ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-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; }

template<typename T>
T gcd(T x, T y) {
    if (y==0) return x;
    return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y) {
    T g = gcd(x, y);
    return x / g * y;
}

int main() {
    ll x, y; cin >> x >> y;
    if (x % y == 0) cout << -1 << endl;
    else cout << lcm(y, x) - x << endl;
}


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

using namespace std;

int solve(int a, int b) {
    vector<int> abc { 1, 2, 3 };
    for (int n=0; n<(int)abc.size(); ++n) {
        if (abc.at(n) != a && abc.at(n) != b)
            return abc.at(n);
    }
}

int main() {
    int a,b;
    cin >> a >> b;
    cout << solve(a,b);
}


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

using namespace std;

const int MAXN = (int) 2e5 + 10;

string str;

int fr[26];

int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int i, j;
    ios::sync_with_stdio(false);
    cin >> str;
    ll ans = 1;
    for(auto it : str) {
        for(j = 0; j < 26; j++) {
            if(j != it - 'a')
                ans += fr[j];
        }
        fr[it - 'a']++;
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


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

using namespace std;

const int MOD = (int)1e9 + 7;
int mat[30];
int n;
int dp[21][(1<<21) + 2];

long long funct(int idx, int mask) {

	if(idx == n) {
		// cout << "a ";
		if(mask == 0) return 1;
		// cout << "b\n";
		return 0;
	}
	// cout << idx << " " << mask << "\n";
	// cout << dp[idx][mask] <<" ";
	if(dp[idx][mask] != -1) return dp[idx][mask];


	long long cur = 0;
	for(int i = 0; i < n; ++i) {
		if((mat[idx]&(1<<i)) and (mask&(1<<i)))
			cur += funct(idx + 1, mask - (1<<i) );
	}
	cur %= MOD;
	dp[idx][mask] = cur;
	return cur;
}

int main() {

	for(int i = 0; i < 21; ++i) {
		for(int j = 0; j < (1<<21); ++j) {
			dp[i][j] = -1;
		}
	}

	cin >> n;

	for(int i = 0; i < n; ++i) {
		mat[i] = 0;
		for(int j = 0; j < n; ++j) {
			int nn; cin >> nn;
			if(nn) mat[i] += (1<<j);
		}
	}


	long long ans = funct(0, (1<<n) - 1);

	cout << ans << " ";
}

Measured memory_bytes: 172288
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll p[20]={0ll,9ll,99ll,999ll,9999ll,99999ll,999999ll,9999999ll,99999999ll,999999999ll,9999999999ll,99999999999ll,999999999999ll,9999999999999ll,99999999999999ll,999999999999999ll,9999999999999999ll,99999999999999999ll,999999999999999999ll};

ll count(ll x){
	ll ret=0ll,i,t,r,l;
	ret += (x/3)*4;
	ret += (x/5)*4;
	for(i=1ll; i<=18ll; ++i){
		t = 0ll;
		r = min(p[i],x);
		l = min(p[i-1],x);
		t += r-r/3-r/5+r/15;
		t -= l-l/3-l/5+l/15;
		ret += t*i;
	}
	return ret;
}

ll get(ll x){
	ll l=0ll,r=100000000000000000ll,m;
	while(r-l>1){
		m = (l+r)/2;
		if(count(m)>x){
			r = m;
		}else{
			l = m;
		}
	}
	return l;
}

char s[100];

int main(void){
	ll x,l,j,i=0,n,p;
	cin >> x;
	--x;
	n = get(x);
	l = x - count(n);
	++n;
	while(i<l+20){
		j = i;
		p = n;
		if(!(p%3)){
			s[i] = 'F';
			s[i+1] = 'i';
			s[i+2] = 'z';
			s[i+3] = 'z';
			i += 4;
		}
		if(!(p%5)){
			s[i] = 'B';
			s[i+1] = 'u';
			s[i+2] = 'z';
			s[i+3] = 'z';
			i += 4;
		}
		if(p%3 && p%5){
			while(p){
				s[i] = p%10+'0';
				p /= 10;
				++i;
			}
			reverse(s+j,s+i);
		}
		++n;
	}
	for(i=0; i<20; ++i){
		cout << s[i+l];
	}
	cout << endl;
	return 0;
}



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

h, w, d = map(int, input().split())
n = h*w
place = [0]*n
for i in range(h):
  a = [int(x) for x in input().split()]
  for j in range(w):
    place[a[j]-1] = (i, j)

bit = [0]*n
for i in range(n):
  if i < d:
    continue
  bit[i] = bit[i-d]+abs(place[i][0]-place[i-d][0])+abs(place[i][1]-place[i-d][1])

q = int(input())
for i in range(q):
  l, r = map(int, input().split())
  print(bit[r-1]-bit[l-1])

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

using namespace std;

vector <string> generate()
{
    vector <string> pins;

    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                string s = "";
                s = s + (char)(i+'0');
                s = s + (char)(j+'0');
                s = s + (char)(k+'0');

                pins.push_back(s);
            }
        }
    }

    return pins;
}

bool check(string s, string p)
{
    int n = s.length();

    int i = 0;

    while (i < n && s[i] != p[0])
        i++;

    i++;

    int j = n-1;
    while (j > i && s[j] != p[2])
        j--;

    j--;
    for (int k = i; k <= j; k++)
    {
        if (s[k] == p[1])
            return true;
    }

    return false;
}

int main()
{
    vector <string> pins = generate();

    int n;
    string s;

    cin >> n >> s;

    long long int ans = 0;

    for (string pin: pins)
    {
        if (check(s, pin))
        {
            ans++;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int st=s.size();
    int sum=0;
    for(int i=0;i<st;i++){
        sum+=(s[i]-'0');
    }
    if(sum%9==0){
        cout<<"Yes";
    }else cout<<"No";
    return 0;
}


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

int main(void){
    int i,j,k,K,S,X,Y,Z,ans=0;
    cin >> K;
    cin >> S;
    for(i=0;i<=K;i++){
        for(j=i;j<=K;j++){
            for(k=j;k<=K;k++){
                if (i+j+k==S){
                    if(i==j && j!=k) ans+=3;
                    else if(j==k && i!=k) ans+=3;
                    else if(i==k && j!=k) ans+=3;
                    else if(i==k && j==k && k==i) ans+=1;
                    else ans+=6;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
$s=str_split(trim(fgets(STDIN)));
$q=trim(fgets(STDIN));
$r=0;
while($q>0){
  $i=trim(fgets(STDIN));
  if($i[0]==1){
    ++$r;
  }elseif($r%2==0){
    if($i[2]==1){
      $p[]=$i[4];
      //array_unshift($s,$i[4]);
    }else{
      $s[]=$i[4];
    }
  }else{
    if($i[2]==2){
      $p[]=$i[4];
      //array_unshift($s,$i[4]);
    }else{
      $s[]=$i[4];
    }
  }
  --$q;
}
echo ($r%2==0)? join("",array_reverse($p)) . join("",$s):join("",array_reverse($s)) . join("",$p);

Measured memory_bytes: 33260
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < k; i++){
            int num = scanner.nextInt();
            set.add(num);
        }
        for(int i = n; i < 100000; i++){
            String t = String.valueOf(i);
            boolean flag = true;
            for(int j = 0; j < t.length(); j++){
                if(set.contains(t.charAt(j) - '0')){
                    flag = false;
                    break;
                }
            }
            if(flag){System.out.println(i);return;}
        }
    }
}

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

const int M=1e5+5;
int a[M][3];
int dp[M][3];

int main()
{
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
			scanf("%d",&a[i][j]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
			dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
	}
	int ans=0;
	for(int i=0;i<3;i++)
		ans=max(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    ll n, m, r;
    cin >> n >> m >> r;
    ll R[r];
    rep(i, r) { cin >> R[i]; }

    ll d[n + 1][n + 1];

    rep(i, n + 1) {
        rep(j, n + 1) { d[i][j] = mod; }
    }
    rep(i, n + 1) { d[i][i] = 0; }

    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }

    rep(k, n + 1) {
        rep(i, n + 1) {
            rep(j, n + 1) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
        }
    }

    sort(R, R + r);
    ll ans = mod;
    do {
        ll ans_temp = 0;
        repd(i, 1, r) {
            ll from = R[i - 1], to = R[i];
            ans_temp += d[from][to];
        }
        ans = min(ans, ans_temp);
    } while (next_permutation(R, R + r));

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
function floor_sum(n, m, a, b)
  ans = 0
  if a >= m
    ans += (n - 1) * n * (a ÷ m) ÷ 2
    a %= m
  end
  if b >= m
    ans += n * (b ÷ m)
    b %= m
  end
  y_max = (a * n + b) ÷ m
  x_max = (y_max * m - b)
  if y_max == 0; return ans; end
  ans += (n - (x_max + a - 1) ÷ a) * y_max
  ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
  return ans
end
p()=parse.(Int,split(readline()))
n=parse(Int,readline())
function main()
  for i=1:n
    n,m,a,b=p()
    floor_sum(n,m,a,b) |> println
  end
end
main()

Measured memory_bytes: 206640
#include <iostream>

using namespace std;

int main()
{
    string S,x="Sunny",y="Rainy",z="Cloudy";
    int sum=0,sunny=0,cloudy=0,rainy=0;
    cin >> S;
    for (int i=0; i<S.length(); i++){
        sum+=S[i];
    }
    for (int i=0; i<x.length(); i++){
        sunny+=x[i];
    }
    for (int i=0; i<y.length(); i++){
        rainy+=y[i];
    }
    for (int i=0; i<z.length(); i++){
        cloudy+=z[i];
    }
    if (sum==sunny){
        cout << z ;
    }
    else if (sum==rainy){
        cout << x ;
    }
    else{
        cout << y ;
    }


    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MOD=1e9+7;
const int INF=1<<29;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m=MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
int modinv(int a){return powerexp(a,MOD-2,MOD);}
void solve(){
	int n,k;
	cin>>n>>k;
	if(k==1)cout<<"0"<<endl;
	else cout<<to_string(n-k)<<endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}



Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
for i in range(n):
  L.append(i+A[i])
  R.append(i-A[i])
from collections import Counter
zisyo=Counter(R)
ans=0
for i in L:
  ans=ans+zisyo.get(i,0)
print(ans)
  

Measured memory_bytes: 50908
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define MAX_V 100001
#define MOD 1000000007

int main(){
    double a,b,h,m;cin>>a>>b>>h>>m;
    double h_d=h*30+30*(m/60);
    double m_d=m*6;
    double d=abs(h_d-m_d);
    d=min(d,360-d);
    double PI=3.1415926535897932;
    double ans=sqrt(a*a+b*b-2*a*b*cos(PI*d/180));
    cout<<setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 4152
#include <iostream>
#include <algorithm>
using namespace std;
int MAX = 200;

int selectionSort(int *A, int n)
{
    int sw = 0;
    for (int i = 0; i < n - 1; i++)
    {
        int minj = i;
        for (int j = i; j < n; j++)
        {
            if (A[j] < A[minj])
            {
                minj = j;
            }
        }
        int temp = A[i];
        A[i] = A[minj];
        A[minj] = temp;
        if (i != minj)
            sw++;
    }
    return sw;
}
int main()
{
    int A[MAX];
    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> A[i];

    int sw = selectionSort(A, n);

    for (int k = 0; k < n; k++)
    {
        if (k > 0)
            cout << " ";
        cout << A[k];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3104
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	// var X = make([]string, N)
	// var U = make([]float64, N)

	var x string
	var ret, u float64
	for i := 0; i < N; i++ {
		fmt.Scan(&u, &x)
		if x == "BTC" {
			u *= 380000.0
		}
		ret += u
	}

	fmt.Println(ret)

}


Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if (N % 2 == 0) {
      System.out.println(N);
    } else {
      System.out.println(N * 2);
    }
  }
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const ll mod = 1e9 + 7;

int main(){
    ll N; cin >> N;

    string S; cin >> S;

    int len = S.length();

    if(S[0] == 'W' || S[len-1] =='W'){
        cout << 0 <<endl;
        return 0;
    }

    vector<int> SE;
    SE.push_back(0);
    for(int i = 1; i < len; i++){
        if(i%2 == 1 && S[i] == 'W') {
            SE.push_back(0);
        } else if(i%2 == 0 && S[i] == 'B') {
            SE.push_back(0);
        } else {
            SE.push_back(1);
        }
    }

    ll ans = 1;
    ll sum = 0;
    for(int i = 0; i < len; i++){
        // Start側ならsumを足す
        if(SE[i] == 0) sum++;
        // End側なら持っている選択肢の数をansにかけて、選択肢を一つ減らす
        else {
            ans *= sum;
            ans %= mod;
            sum--;
        }
    }

    if(sum != 0) {
        cout << 0 <<endl;
        return 0;
    }

    for(ll i = 1; i <=N; i++){
        ans *= i;
        ans %= mod;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1532
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n,m,ans=0;
	cin>>n>>m;
	vector<pair<lint,lint>>p(n);
	rep(i,n){
		lint a,b;
		cin>>a>>b;
		p.at(i)=(make_pair(a,b));
	}
	sort(all(p));
	reverse(all(p));
	while(m!=0){
		if(p.back().second==0)p.pop_back();
		ans+=p.back().first;
		p.back().second--;
		m--;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define maxn 500400
using namespace std;
inline void read(int &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}

inline void write(int x){
    static const int maxlen=100;
    static char s[maxlen];
        if (x<0) {   putchar('-'); x=-x;}
    if(!x){ putchar('0'); return; }
    int len=0; for(;x;x/=10) s[len++]=x % 10+'0';
    for(int i=len-1;i>=0;--i) putchar(s[i]);
}
long long n,l,r,c,d;
//int a[maxn];


int main(){
    scanf("%lld%lld%lld%lld%lld",&n,&l,&r,&c,&d);
    n--;
    long long len=1ll*n*(d-c);
    long long nowl=1ll*l-1ll*n*d,nowr=1ll*nowl+1ll*len;
    for (int i=1;i<=n;i++)
    {
        if ( (nowl<=r)&&( r<=nowr) )
            {
                //printf("%d %d\n",nowl ,nowr);
                puts("YES");
                return 0;
            }
        nowl=1ll*nowr+1ll*(n+1)*c-1ll*(n-1)*d;  nowr=1ll*nowl+1ll*len;
    }
    puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M,Q;
    cin >> N >> M >> Q;
    vector<ll> p(Q), q(Q);
    vector<vector<ll>> S(510,vector<ll>(510)), SS(510,vector<ll>(510));
    ll l,r;
    rep(i,M){
        cin >> l >> r;
        S[--l][--r]++;
    }
    rep(i,N){
        rep(j,N){
            SS[i+1][j+1] += SS[i+1][j] + S[i][j];
        }
    }
    rep(j,N){
        rep(i,N){
            SS[i+1][j+1] += SS[i][j+1];
        }
    }
    rep(i,Q){
        cin >> p[i] >> q[i];
    }
    rep(i,Q){
        l = p[i];
        r = q[i];
        cout << SS[r][r] - SS[l-1][r] - SS[r][l-1] + SS[l-1][l-1] << endl;
    }
}

Measured memory_bytes: 6656
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#define CO(a, b, c) ((a)?(b):(c))
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;

int main(void)
{
	
	int n;
	cin >>n;
	string s;
	if(n%10 == 3) s = "bon";
	else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) s = "pon";
	else s = "hon";

	cout << s;
	return 0;
	
}

Measured memory_bytes: 3624
N = int(input())
A = [int(a) for a in input().split()]

t4=0
t2=0
t=0
for a in A:
  if a%4==0:
    t4+=1
  elif a%2==0:
    t2+=1
  else:
    t+=1
if t4>=t or (t2==0 and t4+1==t):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// mint
template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) const { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) const { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) const { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};

int64_t const MOD = 1e9+7;
typedef mod_int<MOD> mint;

// fact
template<typename INT>
struct factorial {
  std::vector<INT> fact, ifact;
  void init(int64_t N) {
    fact.resize(N+1); ifact.resize(N+1);
    fact[0] = fact[1] = INT(1);
    for(int i = 2; i <= N; ++i) fact[i] = fact[i-1]*i;
    ifact[N] = fact[N].inv();
    for(int i = N-1; i >= 0; --i) ifact[i] = ifact[i+1]*(i+1);
  }
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  factorial<mint> F;
  F.init(N);
  mint coeff;
  for(int k = 1; k <= N; ++k) coeff += F.fact[N]*F.fact[k-1]*F.ifact[k];
  mint ans;
  for(int i = 0; i < N; ++i) {
    int A; std::cin >> A;
    ans += coeff*A;
    coeff += F.fact[N]*F.fact[i+1]*F.ifact[i+2];
    coeff -= F.fact[N]*F.fact[N-1-i]*F.ifact[N-i];
  }
  fin(ans.v_);
  return 0;
}


Measured memory_bytes: 1792
using System;

namespace AtCoder3
{
    class Program
    {
        static void Main(string[] args)
        {
            //125
            string[] x = Console.ReadLine().Split(' ');
            double A = int.Parse(x[0]);
            double B = int.Parse(x[1]);
            double T = int.Parse(x[2]);

            double val = Math.Floor(T / A);
            double c = val * B;
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 13140
#include <cstdio>

int parent[100001];

int find(int k)
{
  if (parent[k] == k) return k;
  return parent[k] = find(parent[k]);
}

void Union(int a, int b)
{
  int pa = find(a);
  int pb = find(b);
  parent[pa] = pb;
}

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
  {
    parent[i] = i;
  }
  while (m--)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    Union(a, b);
  }
  int q;
  scanf("%d", &q);
  while (q--)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    if (find(a) == find(b))
    {
      printf("yes\n");
    }
    else
    {
      printf("no\n");
    }
  }
}



Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>

using namespace std;

int n,m,prvi,kol,cvor1,cvor2;
bool naso=false;

vector<int> sus[100050];

bool bio[100050];
vector<int>posjet;
vector<int>sol2;
vector<int>sol1;
vector<int>sol3;

void input(){
	cin>>n>>m;
	int br1,br2;
	for(int i=0;i<m;i++){
		cin>>br1>>br2;
		sus[br1].push_back(br2);
		sus[br2].push_back(br1);
	}
}

void dfs2(int node, int br){
	while(1){
		bool uzo=false;
		bio[node]=true;
		if(br==1)sol2.push_back(node);
		else sol3.push_back(node);
		//cout<<node<<endl;
		for(int i=0;i<sus[node].size();i++){
			int x=sus[node][i];
			if(bio[x])continue;
			node=x;
			uzo=true;
			break;
		}
		if(!uzo)break;
	}
	
	
}


/*void dfs1(int node){
	if(sol1.size()>0)return;
	bio[node]=true;
	sol2.push_back(node);
	if(node==cvor2 && sol1.empty()){
		for(int i=0;i<sol2.size();i++)sol1.push_back(sol2[i]);
	}
	for(int i=0;i<sus[node].size();i++){
		int x=sus[node][i];
		if(bio[x])continue;
		dfs1(x);
	}
	if(sol1.size()>0)return;
	
	bio[node]=false;
	sol2.pop_back();
}*/

void solve(){
	/*int min_sus=9999999;
	for(int i=1;i<=n;i++){
		int br=sus[i].size();
		min_sus=min(min_sus,br);
	}
	for(int i=1;i<=n;i++){
		if(sus[i].size()==min_sus && sol.empty()){
			kol=sus[i].size();
			prv=i;
			dfs(i);
		}
	}
	cout<<sol.size()<<"\n";
	for(int i=0;i<sol.size();i++)cout<<sol[i]<<" ";*/
	
	cvor1=1,cvor2=sus[1][0];
	
	bio[cvor1]=true;
	bio[cvor2]=true;
	dfs2(cvor1,1);
	dfs2(cvor2,2);
	
	
	reverse(sol2.begin(),sol2.end());
	cout<<sol2.size()+sol3.size()<<endl;
	
	for(int i=0;i<sol2.size();i++)cout<<sol2[i]<<" ";
	//cout<<endl;
	for(int i=0;i<sol3.size();i++)cout<<sol3[i]<<" ";

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	input();
	/*cout<<endl<<endl;
	for(int i=1;i<=n;i++){
		cout<<i<<" -> ";
		for(int j=0;j<sus[i].size();j++)cout<<sus[i][j]<<" ";
		cout<<endl;
	}
	cout<<endl<<endl;*/
	solve();
	
	
	
	
	return 0;
}

Measured memory_bytes: 6904
#include <iostream>
#include <iomanip>

int main() {
    int a, b;
    std::cin >> a >> b;

    int d = a / b;
    int r = a % b;
    double f = (double)a / b;

    std::cout << d << " " << r << " ";
    std::cout << std::fixed << std::setprecision(5) << f << std::endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	//freopen(".inp","r",stdin);
	//freopen(".out","w",stdout);
	int n ;
	cin >> n ;
	int a[n+5] ;
	for( int i = 1 ; i <= n ; i++ ) cin >> a[i] ;
	sort(a + 1 , a + n + 1 ) ;
	for( int i = 1 ; i < n ; i++ ) 
	{
		if( a[i] == a[i+1] ) 
		{
			cout << "NO" ;
			return 0 ;
		}
	}
	cout << "YES" ;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007;



int main() {
    int A,B;
    cin>>A>>B;
    if(A%2 != B%2){cout<<"IMPOSSIBLE"<<endl;return 0;}
    cout<<(A+B)/2<<endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C) {
    string ans;
    (C>=A and C<=B)?ans = YES:ans=NO;
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  long long C;
  scanf("%lld", &C);
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256