akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

int N, M, s, g1, g2;
using pii = pair<int, int>;
using Graph = vector< vector<pii> >;
using Matrix = vector< vector<int> >;
const int INF = 1 << 25;

void warshall(Matrix &mat) {
    int P = mat.size();
    for(int k=0; k<P; k++) {
        for(int i=0; i<P; i++) {
            for(int j=0; j<P; j++) {
                mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
            }
        }
    }
}

int main() {
    while(cin >> N >> M >> s >> g1 >> g2, N) {
        s--; g1--; g2--;

        Graph G(N);
        Matrix gst(N, vector<int>(N, INF));
        Matrix rev(N, vector<int>(N, INF));

        for(int i=0; i<N; i++) {
            gst[i][i] = rev[i][i] = 0;
        }

        for(int i=0; i<M; i++) {
            int u, v, cost; cin >> u >> v >> cost;
            u--; v--;
            gst[u][v] = cost;
            rev[v][u] = cost;
        }

        warshall(gst);
        warshall(rev);

        int ans = INF;
        for(int i=0; i<N; i++) {
            ans = min(ans, gst[i][g1] + gst[i][g2] + rev[i][s]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a[13] = { 3,0,2,0,1,0,1,0,0,1,0,1,0 };
	int x, y;
	cin >> x >> y;
	cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int A,B,C;
    string ans;
    cin >> A>>B>>C;
    cout << max({A,B,C})-min({A,B,C}) << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  char a='\0',b='\0';

  cin >> a >> b;
  cout << (a==b?"H":"D") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<'\n';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    int sm=n*(n+1)/2;
    int cnt,s;
    if(n%2){
        REPR(i,n+1){
            if(!(sm%i)){
                s=i;
                break;
            }
        }
        cnt=sm/s;
    }else{
        s=n+1;
        cnt=sm/s;
    }
    cerr<<s<<','<<cnt<<endl;

    set<int> a[cnt];
    vector<bool> check(n+1);
    REP(i,1,n+1){
        //cerr<<(i-1)%cnt<<'\t'<<i<<'\t'<<s-i<<endl;
        if(check[i])continue;
        if(!(n%2) || i!=s){
            a[(i-1)%cnt].insert(  i);check[i]=true;
            a[(i-1)%cnt].insert(s-i);check[s-i]=true;
        }else{
            a[cnt-1].insert(  i);check[i]=true;
        }

    }
    REP(i,cnt)cerr<<a[i]<<endl;
    vp edges;
    REP(i,cnt==2?1:cnt){
        for(int x:a[(i+cnt-1)%cnt]){
            for(int y:a[i]){
                edges.push_back({x,y});
            }
        }
    }
    cout<<edges.size()<<endl;
    cout<<edges<<endl;
    return 0;
}


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

int main(){

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


	int ans = 0,min;
	min = p[0];

	for (int i = 0;i < n;i++) {
		if (min < p[i]) continue;
		min = p[i];
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
class Integer
  def divisor
    res = []
    1.upto((self**0.5)) do |i|
      if self % i == 0
        res.push i
        res.push self / i if i != self / i
      end
    end
    res.sort
  end
end

def answer_if_valid(x, a, d)
  b = a - d
  if x == a ** 5 - b ** 5
    puts "#{a} #{b}"
    exit
  end
end

x = gets.to_s.to_i

r = x % 5
x.divisor.select{|t| r == t % 5}.each do |d|
  
  left = (( x / d - d ** 4 ) / 5).abs
  
  if left == 0
    answer_if_valid(x,0,d)
    (d ** 3).abs.divisor.each do |a|
      answer_if_valid(x, a, d)
      answer_if_valid(x,-a, d)
    end
  end
  
  left.divisor.each do |a|
    answer_if_valid(x,  a, d)
    answer_if_valid(x, -a, d)
  end
end


Measured memory_bytes: 14828
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

#define MOD 1000000007

int main()
{
    int n = get<int>();
    int m = get<int>();
    vector<int> s(n);
    for (int i = 0; i < n; i++)
        s[i] = get<int>();
    vector<int> t(m);
    for (int i = 0; i < m; i++)
        t[i] = get<int>();

    vector<vector<long>> sum(n+1);
    for (int i = 0; i < n+1; i++)
        sum[i].resize(m+1, 0L);

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 || j == 0) {
                sum[i][j] = 1;
            } else {
                sum[i][j] += sum[i-1][j];
                sum[i][j] += sum[i][j-1];
                sum[i][j] += MOD - sum[i-1][j-1];
                if (s[i-1] == t[j-1])
                    sum[i][j] += sum[i-1][j-1];
                sum[i][j] %= MOD;
            }
        }
    }
    cout << sum[n][m] << endl;
    return 0;
}

Measured memory_bytes: 31616
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

char buffer[51];

bool IsPalindromic(const int32_t num) {
  snprintf(buffer, sizeof(buffer), "%d", num);
  const string str = string(buffer);
  const int32_t length = static_cast<int32_t>(str.length());
  int32_t start = 0;
  int32_t end = length - 1;
  bool is_palindromic = true;
  while (start < end) {
    if (str.c_str()[start] != str.c_str()[end]) {
      is_palindromic = false;
    }
    ++start;
    --end;
  }
  return is_palindromic;
}

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

  int64_t N;
  cin >> N;
  vector<int64_t> array(N + 1);
  array[0] = 2;
  array[1] = 1;
  for (int64_t i = 2; i <= N; ++i) {
    array[i] = array[i - 1] + array[i - 2];
  }
  cout << array[N] << endl;

  return 0;
}


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

using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	c_p_c();
	FIO;
	int n;
	cin >> n;
	int a[n];
	int i;
	for (i = 0; i < n; i++)
		cin >> a[i];
	bool ok = true;
	for (i = 0; i < n; i++)
	{
		if (a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0)
		{
			ok = false;
			break;
		}
	}
	if (ok)
		cout << "APPROVED";
	else
		cout << "DENIED";

}









Measured memory_bytes: 3656
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <stdbool.h>


//using ll = long long;
int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {	//最大公約数
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int min(int a, int b ) {
	if (a < b) {
		return a;
	}
	else
		return b;
}
int max(int a, int b) {
	if (a < b)
		return b;
	else
		return a;
}
int main(void)
{
	int n;
	char s[100];
	scanf("%d",&n);
	scanf("%s",s);
	int len = strlen(s);
	if (len <= n)
		printf("%s",s);
	else {
		for (int i = 0; i < n; i++) {
			printf("%c", s[i]);
		}
		printf("...");
	}
	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
int main(){
  int a,b,tmp,r;
scanf("%d%d",&a,&b);
 if(a>b){
   tmp = a;
   a=b;
   b=tmp;
 }
 r=a%b;
 while(r!=0){
   a=b;
   b=r;
   r=a%b;
 }
 printf("%d\n",b);
 return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V< P<ll, ll> > a = {{0, 0}};
    REP(i, n) {
        ll _a; cin >> _a;
        a.push_back(make_pair(_a, i));
    }
    sort(a.begin(), a.end(), greater<P<ll, ll> >());
    vll ans(n, 0);
    ll mini=a[0].second;
    REP(i, n) {
        chmin(mini, a[i].second);
        ans[mini] += (i+1) * (a[i].first - a[i+1].first);
    }
    REP(i, n) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3440
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
X = list(input())

pc = X.count("1")

# X == 0 の時
if pc == 0:
    for i in range(N):
        print(1)
    exit()

sml = pc - 1
big = pc + 1

b = 0
mod_s = 0
mod_b = 0
for x in X[::-1]:
    if x == "1":
        if sml:
            mod_s += pow(2, b, sml)
            mod_s %= sml

        mod_b += pow(2, b, big)
        mod_b %= big

    b += 1

# print(mod_s, mod_b, sml, big)


ELE = []

b = 0
for x in X[::-1]:
    if x == "0":
        t = (mod_b + pow(2, b, big)) % big
        ELE.append((t, 1))
    else:
        t = (mod_s - pow(2, b, sml)) % sml if sml else 0

        if sml:
            ELE.append((t, 1))
        else:
            ELE.append((0, 0))
    b += 1


def solve(x, c):
    if x == 0:
        return c

    b = 0
    nx = x
    while nx > 0:
        b += nx & 1
        nx >>= 1

    ret = solve(x % b, c + 1)
    return ret


ANS = []
for x, pc in ELE:
    ANS.append(solve(x, pc))

print("\n".join(map(str, ANS[::-1])))



Measured memory_bytes: 49848
#include<stdio.h>
int main(void)
{
  int a,b,max,min;
  scanf("%d %d",&a,&b);
  if(a>b) {
    max=a;
    min=b;
  }else{
    max=b;
    min=a;
  }

  if(max-min<=16-max-min){
    puts("Yay!");
  }else{
    puts(":(");
  }

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = 0;
  rep(i,n-2){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n],i,cnt=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    
  }
  for(i=0;i<n;i++){
    if(a[i]%2==1){
      break;
    }
    a[i]/=2;
    if(i==n-1){
      i=-1;
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


class edge_t {
public:
  edge_t(int ii, int jj, int cc) : i(ii), j(jj), c(cc) {};

public:
  int i;
  int j;
  int c;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, a, b, c;
  
  std::cin >> N >> M;

  std::vector<edge_t> E;

  for (int i = 0; i < M; i ++) {
    std::cin >> a >> b >> c;

    a --;
    b --;

    E.emplace_back(a, b, - c);
  }

  long long C[1111];

  std::fill(C, C + 1111, INF);

  C[0] = 0;

  for (int t = 0; t < N; t ++) {
    bool update = false;

    for (int i = 0; i < M; i ++) {
      auto e = E[i];

      if (C[e.i] != INF && C[e.j] > C[e.i] + e.c) {
        C[e.j] = C[e.i] + e.c;

        update = true;
      }
    }

    if (! update)
      break;
  }

  bool f[1111] = {0};

  for (int t = 0; t < N; t ++) {
    bool update = false;

    for (int i = 0; i < M; i ++) {
      auto e = E[i];

      if (C[e.i] != INF && C[e.j] > C[e.i] + e.c) {
        C[e.j] = C[e.i] + e.c;

        f[e.j] = update = true;
      }
    }

    if (! update)
      break;
  }

  if (f[N - 1]) {
    std::cout << "inf" << std::endl;
  }
  else {
    std::cout << - C[N - 1] << std::endl;
  }
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<set<ll>> e(N);
    vector<bool> v(N);
    rep(i,M) {
        ll a,b;
        cin >> a >> b;
        --a;--b;
        e[a].insert(b);
        e[b].insert(a);
    }
    int ans = 1;
    queue<ll> q;
    rep(i,N) {
        if (v[i])
            continue;
        v[i] = true;
        q.push(i);
        int n=1;
        while (q.size()) {
            ll x = q.front(); q.pop();
            for (ll t : e[x]) {
                if (!v[t]) {
                    v[t] = true;
                    q.push(t);
                    ++n;
                }
            }
        }
        ans = max(ans, n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 31840
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char **argv){
    int n;
    scanf("%d",&n);
    int a;
    a=n;
    int sum=0;
    
    for(int i=0;i<9;i++){
        sum+=a%10;
        a=a/10;
    }
    if(n%sum==0){ 
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int N;

int main() {
    cin >> N;
    long long t = 1, a = 1;
    for (int i = 0; i < N; i++) {
        long long T, A;
        cin >> T >> A;
        long long n = max((t + T - 1) / T, (a + A - 1) / A);
        t = n * T;
        a = n * A;
    }
    cout << a + t << endl;
    return 0;
}

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

int main()
{
  vector<unsigned long long> v(87);
  v.at(0) = 2;
  v.at(1) = 1;
  int n;
  cin >> n;
  for(int i = 2; i <= n; ++i)
  {
    v.at(i) = v.at(i-1) + v.at(i-2);
  }
  cout << v.at(n);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    string num; cin>>num;
    ll sum=0;
    REP(i,SIZE(num)){
        char c=num[i];
        int j=c-'0';
        sum+=j;
    }
    cout<<((sum%9==0)?"Yes":"No")<<endl;
    return 0;
}


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

typedef pair<long long int, long long int> P;

int N; // 必要な数よりも大きい2^nよりも大きい数を入れるとよい
int BIT[310000];

void add(int a, int w){
	
	// a番目の要素にwを足す O(log N)
	
	for(int x = a; x <= N; x += x & -x){
		BIT[x] += w;
	}
}

int sum(int a){
	
	// 1からaまでの要素の合計を返す O(log N)
	
	int ret = 0;
	for(int x = a; x > 0; x -= x & -x){
		ret += BIT[x];
	}
	return ret;
}

void init(){
	for(int i = 0; i < N; i++){
		BIT[i] = 0;
	}
}

P p[300000];

int main() {
	
	N = 300000;
	long long int NN, K;
	cin >> NN >> K;
	
	long long int Sum = 0;
	
	for(int i = 1; i <= NN; i++){
		long long int num;
		cin >> num;
		Sum += num;
		p[i].first = Sum - i * K;
		p[i].second = i;
	}
	NN++;
	p[0].first = 0;
	p[0].second = 0;
	
	sort(p, p + NN, greater<P>());
	
	init();
	
	long long int ans = 0;
	
	for(int i = 0; i < NN; i++){
		ans += sum(NN) - sum(p[i].second + 1);
		add(p[i].second + 1, 1);
		/*
		for(int i = 1; i <= NN; i++){
			cout << sum(i) << " ";
		}
		cout << endl;
		*/
	}
	
	cout << ans << endl;
	
	return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

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

template<typename T>
istream& operator>> (istream& in, vector<T>& vec) {
    for (auto it = vec.begin(); it != vec.end(); ++it) {
        in >> *it;
    }
    return in;
}

int main() {
    ll N;
    cin >> N;
    string name;
    unordered_map<char, ll> hashMap;
    for (int i = 0; i < N; ++i) {
        cin >> name;
        if (name[0] == 'M' || name[0] == 'A' || name[0] == 'R' || name[0] == 'C' || name[0] == 'H') {
            ++hashMap[name[0]];
        }
    }
    if (hashMap.size() < 3) {
        cout << 0 << endl;
        return 0;
    }
    vector<pair<char, ll>> nums;
    for (auto& it : hashMap) {
        nums.push_back(it);
    }
    ll ans = 0;
    for (int i = 0; i < nums.size() - 2; ++i) {
        for (int j = i + 1; j < nums.size() - 1; ++j) {
            for (int k = j + 1; k < nums.size(); ++k) {
                ans += nums[i].second * nums[j].second * nums[k].second;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = [int(h) for h in input().split()]

cost = [0, abs(H[1]-H[0])]

for i in range(2,N):
    cost.append(min(cost[i-2]+abs(H[i]-H[i-2]), cost[i-1]+abs(H[i]-H[i-1])))

print(cost[-1])

Measured memory_bytes: 13980
import numpy as np
NM = list(map(int,input().split()))
N = NM[0]
M = NM[1]
A = list(map(int,input().split()))
listBC =[]
while True:
    try:
        listBC.append(list(map(int,input().split())))
    except:
        break;
BC = np.array(listBC)
BCnum = np.argsort(BC[:,1])[::-1]
BC = BC[BCnum,:]

A.sort()
j=0
for i in range(len(A)):
    times = BC[j,0]
    if BC[j,0]==0:
        j+=1
        if j == BC.shape[0]:
            break
        times = BC[j,0]
    if A[i]<BC[j,1]:
        A[i]=BC[j,1]
        BC[j,0] += -1
output = sum(A)
print(output)

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

//長方形のマス目について左上から右下へ行く生き方
// -> (縦に移動する回数＋横に移動する回数)から(縦または横に移動する回数の選び方)

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){

    ll H,W,A,B;
    cin >> H >> W >> A >> B;
    COMinit();
    ll res = 0;
    res = COM(H-A-1+B,B) * COM(A+W-1-B,A) % MOD;
    res %= MOD;
    for(int i = B+1; i < W; i++){
        ll n;
        n = (COM(H-A-1+i,i) - COM(H-A-1+i-1,i-1) + MOD)%MOD;
        res += n * COM(A+W-1-i,A)%MOD;
        res %= MOD;
    }   
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 12160
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
ans = 0
sc = list(set(s.copy()))
from collections import Counter
sn = Counter(s)
tn = Counter(t)
for i in range(len(sc)):
  ans = max(sn[sc[i]]-tn[sc[i]],ans)
print(ans)

Measured memory_bytes: 9416
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

def frog(n, k, h):
    d = [float('inf')] * n
    d[0] = 0

    for i in range(1, n):
        d[i] = min(
            d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)
        )
    return d[n - 1]


print(frog(n, k, h))


Measured memory_bytes: 13976
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(a, b);
	cout << a*b;
}



















Measured memory_bytes: 3664
n = gets.to_i
result =[]
N = n
loop do
  if n > 26
    result << n % 26
    if n % 26 == 0
      n = n / 26
      n = n-1
    else
      n = n / 26
    end
  else
    result << n
    break
  end
end
answer = ""
a = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z)
result.reverse_each{|i| answer.concat(a[i-1])}
puts answer


Measured memory_bytes: 14328
import java.util.Scanner;

public class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String S;
    S = sc.next();
    sc.close();
    if (S.equals("AAA") || S.equals("BBB"))
    {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    } 
  }
}

Measured memory_bytes: 21716
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#include <bitset>
using namespace std;
const int INF=1<<30;

int d[11][7];
int x=2,y=1;
int k=0;

typedef pair<int,int> P;

int main(){
	
	int n,l;
	cin>>n>>l;
	vector<string> s(n);
	
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	
	sort(s.begin(),s.end());
	
	string ans="";
	
	for(int i=0;i<s.size();i++){
		ans+=s[i];
	}
	
	cout<<ans<<endl;

}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  int ans = 0;
  rep(i,n){
    int x = i+1;
    if((x&1)&&(a[i]&1))ans++;
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define mt make_tuple
#define ll long long
#define eb emplace_back
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a) 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) 
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;




//----------------------------------------------------------------------------------------------------------------------

void swap(int &a,int &b){
    int temp = a;
    a = b;
    b = temp;
}

long long binpow(unsigned long long a, unsigned long long b,
                 unsigned long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

const int MOD = 1e9 + 7;

int main(){
   // std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin >> n >> m;
    set<int> cant;
    for(int i = 0;i < m;i++) {
      int a;
      cin >> a;
      cant.insert(a);
    }
    vi ans (n+1);
    ans[0] = 1;
    for(int i = 0;i <n;i++){
      if(cant.count(i)) continue;
      if(i != 0 && ans[i] == 0) continue;
      if(!cant.count(i+1)){
        ans[i+1] += (ans[i] );
        ans[i+1]%=MOD;
      }
      if(!cant.count(i+2) && i+2 <= n){
        ans[i+2] += (ans[i] );
        ans[i+2]%=MOD;
      }
    }
    
    cout << ans[n] << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[201];
int dp1[1000001],dp2[1000001];
int main(){
    FOR(i,1,201){
        a[i-1]=i*(i+1)*(i+2)/6;
    }
    int n;
    while(cin>>n,n){
        rep(i,n+1) dp1[i]=dp2[i]=1000100010;
        dp1[n]=0,dp2[n]=0;
        rep(i,200)for(int j=n;j>=a[199-i];--j){
            dp1[j-a[199-i]]=min(dp1[j-a[199-i]],dp1[j]+1);
            if(a[199-i]%2==1) dp2[j-a[199-i]]=min(dp2[j-a[199-i]],dp2[j]+1);
        }
        cout<<dp1[0]<<" "<<dp2[0]<<endl;
    }
    return 0;
}


Measured memory_bytes: 10568
#include<stdio.h>

int solve(int,int);
int n,A[2000];
int main() {
	int i,q,m[2000];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		scanf("%d",&A[i]);
		}
		scanf("%d",&q);
		
		for(i=0;i<q;i++) {
		scanf("%d",&m[i]);
		}
		for(i=0;i<q;i++) {
			if(solve(0,m[i])==1)
			printf("yes\n");
			else printf("no\n");
		}
			return 0;
			}
			
		int solve(i, m) {
			int res;
   if (m == 0)
     return 1;
   if (i >= n)
   return 0;
   res = solve(i + 1, m) || solve(i + 1, m - A[i]);
   return res;
   }


Measured memory_bytes: 2044
n,m = gets.split.map(&:to_i)
s = []
x = 0
m.times do
  a,b = gets.split.map(&:to_i)
  if n != 1 && a == 1 && b == 0
    x = 1
  else
    s << [a,b]
  end
end

ar = Array.new(n)
s.each do |i|
  if ar[(i[0])-1] == nil
    ar[(i[0])-1] = i[1]
  elsif ar[(i[0])-1] != i[1]
    x = 1
  end
end
if x == 1
  puts "-1"
else
  ans = ""
  for f in 0..(n-1)
    if ar[f] == nil
      if f == 0 && n != 1
        ar[f] = 1
      else
        ar[f] = 0
      end
    end
  end
  ar.each do |j|
    ans += "#{j}"
  end
  puts ans
end


Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int N, A[2000];

int dp[2][2001][2001];

int rec(int turn, int l, int r)
{
    if (turn == N - 1) {
        return 0;
    }

    bool is_joi = turn % 2;

    if (~dp[is_joi][l][r]) return dp[is_joi][l][r];

    int nxl = l - 1 < 0 ? N - 1 : l - 1;
    int nxr = r + 1 >= N ? 0 : r + 1;

    if (is_joi) {
        int res = 0;

        chmax(res, rec(turn + 1, nxl, r) + A[nxl]);
        chmax(res, rec(turn + 1, l, nxr) + A[nxr]);
        
        return dp[is_joi][l][r] = res;
    } else { // IOI
        int res = 0;

        if (A[nxl] > A[nxr]) {
            chmax(res, rec(turn + 1, nxl, r));
        } else {
            chmax(res, rec(turn + 1, l, nxr));
        }

        return dp[is_joi][l][r] = res;
    }
}

signed main()
{
    omajinai;

    cin >> N;

    rep(i, N) {
        cin >> A[i];
    }

    memset(dp, -1, sizeof(dp));

    int ma = 0;

    rep(i, N) {
        chmax(ma, rec(0, i, i) + A[i]);
    }

    cout << ma << endl;
}

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

par = [i + 1 for i in range(n)]
rank = [1] * n
size = [1] * n

def find(x):
    if par[x - 1] == x:
        return x
    else:
        return find(par[x - 1])

def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x - 1] < rank[y - 1]:
        par[x - 1] = y
        size[y - 1] += size[x - 1]
    else:
        par[y - 1] = x
        size[x - 1] += size[y - 1]
        if rank[x - 1] == rank[y - 1]:
            rank[x - 1] += 1

for i in range(m):
    a, b = map(int, input().split())
    union(a, b)

print(max(size))

Measured memory_bytes: 20136
S = input()

counter = {"a":0,"b":0,"c":0}
for x in S:
    if x == "a":
        counter["a"] +=1
    if x == "b":
        counter["b"] +=1
    if x == "c":
        counter["c"] +=1

if counter["a"]==1 and counter["b"]==1 and counter["c"]==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
correct = []
def dfs(i, s, stack):
	if i == 4:

		if eval(''.join(stack)) == 7:
			correct.append(''.join(stack) + '=7')
			return True
		else:
			return False

	if dfs(i+1, s,stack + ['+', s[i]]): return True
	if dfs(i+1, s,stack + ['-', s[i]]): return True
	return False
s = raw_input()
dfs(1, s, [s[0]])
print correct[0]

Measured memory_bytes: 85444
def check(m, f, r)
  return 'F' if m == -1 || f == -1
  return 'A' if m + f >= 80
  return 'B' if m + f >= 65
  return 'C' if m + f >= 50 || m + f >= 30 && r >= 50
  return 'D' if m + f >= 30
  return 'F'
end

while (n = gets.split(' ').map(&:to_i)) != [-1, -1, -1]
  m, f, r = n
  puts check(m, f, r)
end

Measured memory_bytes: 8660
#include<stdio.h>

int main()

{
    int x[3000],y[3000],i = 0;
    while(1){
        scanf("%d %d",&x[i],&y[i]);
        if(x[i]==0&&y[i]==0){break;}
        i++;
    }
    int k = i;
    for(i = 0;i<k;i++){
        if(x[i]>y[i]){
            printf("%d %d\n",y[i],x[i]);
        }
        else {
            printf("%d %d\n",x[i],y[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 2048
N = input()
data = input().split()
bef = -1
count = 0
result = 0

for i in range(len(data)):
	t = int(data[i])
	if bef != t:
		if count > 1:
			result += int(count / 2)
		count = 1
		bef = t
	else:
		count += 1

if count > 1:
	result += int(count / 2)
print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
//Optimizations
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//save time
#define endl '\n'
#define db(x) cerr << "> " << #x << ": " << x << endl
typedef long long ll;
 
//for sorting
#define all(a) a.begin(),a.end()
 
//Constants
#define PI   3.141592653593
#define MOD  1000000007LL
#define EPS  0.000000001
#define INF  0X3f3f3f3f
 
//loops
#define REP(i,n) 	    for(int i=0;i<(n);++i)
#define FOR(i,a,b)      for(int i=(a);i<(b);++i)
#define DFOR(i,a,b)     for(int i=(a);i>=(b);--i)
 
//vectors
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int,int>>
#define vlll vector<pair<ll,ll>>
#define pb 	push_back
 
//pairs
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define F first
#define S second
 
//fast I/O
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
#define gc getchar
#define pc putchar
 
//If using cin and cout
#define IOS ios::sync_with_stdio(false)
#define TIE cin.tie(NULL);cout.tie(NULL)
 
//queue
#define di deque<int>
#define dll deque<ll>
#define qi queue<int>
#define PQ priority_queue
 
//general
#define E empty()
 
//Declare all variables and methods needed between this comment and the next one(OCD lol)
const int MAXN=0;
int main(){
    int l , r , d ; cin >> l >> r >> d ;
    int res = 0;
    int n  = d;
    while(n <= r){
        if(n >=l)
        res++;
        n+=d;
       // cout << d << endl;
    }
    cout << res << endl;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int park[10][10],n;
int dx[]={2,2,1,0,-1,-2,-2,-2,-1,0,1,2},dy[]={0,-1,-2,-2,-2,-1,0,1,2,2,2,1};

bool dfs(int px,int py,int t)
{
	if(t==n)	return true;
	if(!(park[py][px]&(1<<t)))	return false;

	for(int i=0;i<12;i++){
		int xx=px+dx[i],yy=py+dy[i];
		if(0<=yy && yy<10 && 0<=xx && xx<10){
			if(dfs(xx,yy,t+1))	return true;
		}
	}
	return false;
}

int main()
{
	for(int px,py;cin>>px>>py,px||py;){
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)park[i][j]=0;
		cin>>n;
		for(int k=0;k<n;k++){
			int sx,sy;	cin>>sx>>sy;
			for(int y=sy-1;y<=sy+1;y++)for(int x=sx-1;x<=sx+1;x++)
				if(0<=y && y<10 && 0<=x && x<10)
					park[y][x]|=1<<k;
		}

		bool ok=false;
		for(int i=0;i<12;i++){
			int xx=px+dx[i],yy=py+dy[i];
			if(0<=yy && yy<10 && 0<=xx && xx<10){
				if(dfs(xx,yy,0)){
					ok=true;
					break;
				}
			}
		}
		cout<<(ok?"OK":"NA")<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n; cin >> n;

	n = 1000 - (n % 1000);

	if (n == 1000)
		n = 0;

	cout << n << '\n';
	return 0;
}

Measured memory_bytes: 3640
def solve(string):
    n, k = map(int, string.split())
    if k > (n - 1) * (n - 2) // 2:
        return "-1"
    ans = []
    c = (n - 1) * (n - 2) // 2
    for i in range(1, n):
        ans.append("{} {}".format(i, n))
    for i in range(1, n):
        for j in range(i + 1, n):
            if c - k == 0:
                break
            c -= 1
            ans.append("{} {}".format(i, j))
    return "{}\n".format(len(ans)) + "\n".join(ans)


if __name__ == '__main__':
    print(solve(input()))


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

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

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
int M,D;
int main(){
  int ans = 0;
  M = getint(), D = getint();
  for(int m = 1;m <= M;m++){
    for(int d = 1;d <= D;d++){
      int d10 = d / 10, d1 = d % 10;
      if(d10 >= 2 && d1 >= 2 && d10 * d1 == m) ans++;
    }
  }
  putint(ans,'\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int R;
    cin >> R;
    if (R >= 0 && R < 1200) {
        cout << "ABC";
    }
    if (R >= 1200 &&R < 2800) {
        cout << "ARC";
    }
    if (R >= 2800) {
        cout << "AGC";
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        Console.ReadLine();
        int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        bool isUP = true;
        int before = 0;
        int result = 0;

        foreach (int n in input)
        {
            if (n == before)
            {
                continue;
            }

            bool difIsUP = before < n;
            if (isUP & difIsUP == false)
            {
                result += before;
            }
            else if (!isUP && difIsUP == true)
            {
                result -= before;
            }
            before = n;
            isUP = difIsUP;
        }
        result += isUP ? before : 0;
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main(){
int a;
int b;
cin>>a>>b;
if(a==b){
    cout<<"Draw";
}
else if(a==1){
    cout<<"Alice";
}
else if (b==1){
    cout<<"Bob";
}
else if (b>a){
    cout<<"Bob";
}

else if (b<a){
    cout<<"Alice";
}

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define LLINF 100000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
string s,t;
int latest[30];
int nxt[100100][30];
int fs[30];
P check(int l){
	int id = l+1;
	int pos = fs[t[l]-'a'];
	if(pos==-1)return P(-1,-1);
  // cout << pos << ' ' << id << endl;
	while(id<t.size()&&pos!=-1){
		pos = nxt[pos][t[id]-'a'];
		if(pos!=-1)id++;
		// cout << pos << ' ' << id << endl;
	}
	// cout << endl;
	return P(pos,id);
}
int main(){
	cin >> s >> t;
	memset(latest,-1,sizeof(latest));
	for(int i=s.size()-1;i>=0;i--){
		for(int j=0;j<26;j++){
			nxt[i][j] = latest[j];
		}
		latest[s[i]-'a']=i;
	}
	for(int i=0;i<26;i++){
		fs[i] = latest[i];
	}
	int now = 0;
	ll ans = 0ll;
	ll prev = 0ll;
	while(now<t.size()){
		P res = check(now);
		if(res.sec<0){
			cout << -1 << endl;
			return 0;
		}
		// cout << res.fi << ' ' << res.sec << endl;
		ans += s.size();
		prev = res.fi+1;
		now = res.sec;
	}
	ans -= s.size();
	ans += prev;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    string s;cin>>s;
    co(s=="ABC"?"ARC":"ABC");
}


Measured memory_bytes: 3588