akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

vector<vector<vector<ll>>> dp(110, vector<vector<ll>>(110,vector<ll>(410)));

int main(){
    ll a,b;
    cin >> a >> b;
    if(a + b == 15){
       cout << '+' << endl;
    }else if(a * b == 15){
       cout << '*' << endl;
    }else{
       cout << 'x' << endl;
    }
}


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

int dp[1005][1005];

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

int solve(int i, int j, int h, int w, vector <vector <char> > & field)
{
    if(dp[i][j] != -1)
    return dp[i][j];
    if(i > h || j > w || i < 1 || j < 1)
    return 0;
    if(field[i][j] == '#')
    {
        dp[i][j] = 0;
        return 0;
    }
    if(i == h && j == w)
    {
        dp[i][j] = 1;
        return dp[i][j];
    }
    else
    {
        dp[i][j] = (solve(i + 1, j, h, w, field)%1000000007 + solve(i, j + 1, h, w, field)%1000000007)%1000000007;
        return dp[i][j];
    }
}

int main()
{
    int h, w;
    cin>>h>>w;
    //cout<<h<<" "<<w<<"\n";
    vector <vector <char> > field(h + 1, vector <char> (w + 1));
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            cin>>field[i][j];
        }
    }
    initialise();
    cout<<solve(1, 1, h, w, field)<<"\n";
    return 0;
}

Measured memory_bytes: 5376
<?php
fscanf(STDIN, "%d %d", $x, $y);
$g1 = [1,3,5,7,8,10,12];
$g2 = [4,6,9,11];
$f = 0;
if (in_array($x, $g1)) {
	if (in_array($y, $g1)) $f = 1;
} elseif (in_array($x, $g2)) {
	if (in_array($y, $g2)) $f = 1;
}
echo $f ? 'Yes' : 'No';

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<int> fac, finv, inv;

void comb_init(int n) {
  fac  = vector<int>(n);
  finv = vector<int>(n);
  inv  = vector<int>(n);
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < n; 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;
  }
}
 
int comb(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;
}

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

  comb_init(2000000);

  chmin(K, N);

  int ans = 0;
  REP(i, K+1){
    (ans += comb(N, i)*comb(N-1, i)) %= MOD;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 47104
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

a, b, k = map(int, readline().split())

acc = min(a, k)
a -= acc
k -= acc

acc = min(b, k)
b -= acc

print(a, b)


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    int a[n + 1]{};
    for(int i = 0; i < k; i++) {
        int d;cin >> d;
        for(int j = 0; j < d; j++) {
            int y;
            cin >> y;
            a[y]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(a[i] == 0) {
            ans ++;
        }

    }
    cout << ans;


    return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	float h, w, n;
	cin >> h >> w >> n;
	if (h > w) {
		cout << ceil(n / h);
	}
	else {
		cout << ceil(n / w);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  char s[14]={};
  scanf("%s",s);
  printf("%.4s %s\n",s,&s[4]);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main()
{
	ll n, a[200005], b[200005], ans = 0;
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		b[a[i]] = i;
	}

	set<int> st;
	st.insert(-1), st.insert(n);
	for (int i = 1; i <= n; i++) {
		auto r = st.upper_bound(b[i]);
		auto l = r;
		l--;
		// cout << *l << " " << *r << ' ' << b[i] << endl;
		st.insert(b[i]);
		ans += 1LL * (*r - b[i]) * (b[i] - *l) * i;
		// cout << ans << endl;
	}

	cout << ans << endl;
}

Measured memory_bytes: 12800
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	
	string s;

	cin >> s;

	bool isgood = true;
	if (s[0] == s[1]) isgood = false;
	if (s[1] == s[2]) isgood = false;
	if (s[2] == s[3]) isgood = false;

	if (isgood == true) {
		cout << "Good" << endl;
	}
	else {
		cout << "Bad" << endl;
	}
}








int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
abc = [int(x) for x in input().split()]
abc = sorted(abc)

num = 0
while True:
#     print(abc)
    if (abc[0] == abc[1]) & (abc[1] == abc[2]):
        break

    if (abc[0] == abc[1]):
        abc[0] +=1
        abc[1] +=1
        abc = sorted(abc)
        num += 1
        continue

    if (abc[0] < abc[1]):
        abc[0] += 2
        abc =sorted(abc)
        num += 1
        continue

print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  string S;
  cin>>S;
  int X,Y;
  cin>>X>>Y;
  VI FX,FY;
  int F=0,E=0;
  rep(i,S.size()){
    if(S[i]=='T'){
      if(E==0) FX.push_back(F);
      else FY.push_back(F);
      F=0;
      E=(E+1)%2;
    }else F++;
  }
  if(E==0) FX.push_back(F);
  else FY.push_back(F);
  VI dpx(16001),dpy(16001);
  rep(i,16001) dpx[i]=-1;
  rep(i,16001) dpy[i]=-1;
  dpx[8000]=0;
  if(FX.size()) dpx[FX[0]+8000]=1;
  dpy[8000]=0;
  rep(i,FX.size()){
    if(i){
      VI XX;
      rep(j,16001) if(dpx[j]==i) XX.push_back(j);
      rep(j,XX.size()){
        dpx[XX[j]+FX[i]]=i+1;
        dpx[XX[j]-FX[i]]=i+1;
      }
    }
  }
  rep(i,FY.size()){
    VI YY;
    rep(j,16001) if(dpy[j]==i) YY.push_back(j);
    rep(j,YY.size()){
      dpy[YY[j]+FY[i]]=i+1;
      dpy[YY[j]-FY[i]]=i+1;
    }
  }
  if(dpx[X+8000]==FX.size()&&dpy[Y+8000]==FY.size()) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P, ll>;
using PP = pair<P ,P>;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll m, ans = 0, sum = 0;
    cin >> m;
    for(int i=0;i<m;i++){
        ll d, c;
        cin >> d >> c;
        ans += c;
        sum += d*c;
    }
    ans--;
    ans += (sum-1)/9;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool finished = false;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 15; j++) {
      if (N == 4 * i + 7 * j) {
        cout << "Yes" << endl;
        finished = true;
        break;
      }
      else {
        continue;
      }     
    }
    if (finished) {
      break;
    }  
  }
  if (!finished) {
      cout << "No" << endl;     
  }
}

      

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> pw(15);
	pw[0] = 1;
	int len = -1;
	ll add = 0;
	for (int i = 1; i < 15; i++) {
		pw[i] = pw[i - 1] * 26;
		if (pw[i] + add >= n && len == -1) {
			len = i;
		}
		add += pw[i];
	}
	for (int i = 0; i < len; i++) {
		n -= pw[i];
	}
	for (int i = 0; i < len; i++) {
		for (int j = 0; j < 26; j++) {
			if (pw[len - i - 1] > n) {
				cout << (char)(j + 'a');
				break;
			}
			else {
				n -= pw[len - i - 1];
			}
		}
	}
}

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main()
{
    int A, B;
    cin >> A >> B;

    if (A == 1 && B == 1) { cout << "Draw" << endl; }
    else if (A == 1 && B > 1) { cout << "Alice" << endl; }
    else if (A > 1 && B == 1) { cout << "Bob" << endl; }
    else {
        if(A>B) { cout << "Alice" << endl; }
        else if(A<B){ cout << "Bob" << endl; }
        else { cout << "Draw" << endl; }

    }
}

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

int main(){
  int N;cin>>N;
  vector<pair<int,int>> pairs(N);
  for(int i=0;i<N;i++){
    cin>>pairs[i].first>>pairs[i].second;
    swap(pairs[i].first,pairs[i].second);
  }
  sort(pairs.begin(),pairs.end());
  int time=0;
  int h=1;
  for(int i=0;i<N;i++){
    time+=pairs[i].second;
    if(time>pairs[i].first){
      h=0;
      break;
    }
  }
  if(h==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1792
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort{|x,y|y<=>x} end##
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
pr=(n/1.08).ceil
ori=(pr*1.08).floor

puts ori==n ? pr : ':('

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

int main() {
  string s, t;
  cin >> s >> t;
  int ns = s.size(), nt = t.size();
  vector<vector<int>> tbl(ns + 1, vector<int>(nt + 1, 0));

  for (int i = 0; i < ns; i++) {
    for (int j = 0; j < nt; j++) {
      if (s[i] == t[j])
        tbl[i + 1][j + 1] = tbl[i][j] + 1;
      else
        tbl[i + 1][j + 1] = max(tbl[i + 1][j], tbl[i][j + 1]);
    }
  }
  string ans = "";
  int i = ns, j = nt;
  while (i > 0 && j > 0) {
    if (tbl[i][j] == tbl[i][j - 1]) {
      j--;
    } else if (tbl[i - 1][j] == tbl[i][j]) {
      i--;
    } else if (tbl[i][j] == tbl[i - 1][j - 1] + 1) {
      ans += s[i - 1];
      i--;
      j--;
    }
  }
  reverse(begin(ans), end(ans));
  cout << ans << endl;
}

Measured memory_bytes: 35584
#include <stdio.h>

#define MAX 25

typedef struct {
	int parent;
	int left;
	int right;
} node;

void preorder(int);
void inorder(int);
void postorder(int);

node u[MAX];

int main(void)
{
	int i, n, id, left, right, rootId;
	
	scanf("%d",&n);
	for (id=0; id<n; id++) {
		u[id].parent = -1;
	}
	for (i=0; i<n; i++) {
		scanf("%d %d %d", &id, &left, &right);
		u[id].left = left;
		u[id].right = right;
		if(left != -1) {
			u[left].parent = id;
		}
		if(right != -1) {
			u[right].parent = id;
		}
	}
	
	rootId = 0;
	while (u[rootId].parent != -1) {
		rootId++;
	}
	
	printf("Preorder\n");
	preorder(rootId);
	printf("\nInorder\n");
	inorder(rootId);
	printf("\nPostorder\n");
	postorder(rootId);
	printf("\n");
	
	return 0;
}

void preorder(int id)
{
	printf(" %d", id);
	if(u[id].left != -1) preorder(u[id].left);
	if(u[id].right != -1) preorder(u[id].right);
}
void inorder(int id)
{
	if(u[id].left != -1) inorder(u[id].left);
	printf(" %d", id);
	if(u[id].right != -1) inorder(u[id].right);
}
void postorder(int id)
{
	if(u[id].left != -1) postorder(u[id].left);
	if(u[id].right != -1) postorder(u[id].right);
	printf(" %d", id);
}

Measured memory_bytes: 616
W = input()

T = []
x = 0

while True:
    
    Ti = input().split()
    
    if Ti == ["END_OF_TEXT"]:
        break
        
    T += Ti
    
for i in T:
    i = i.rstrip("." or ",")
    i = i.lower()
   
    if i == W:
        x += 1

print(x)


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N; cin>>N;
    V<int> a(N);
    ll s = 0;
    rep(i, N) {
        cin>>a[i];
        s += a[i];
    }
    ll ans = TEN(18);
    ll t = 0;
    rep(i, N-1) {
        t += a[i];
        chmin(ans, abs(s-t*2));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(100000)
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
dpv = [-1]*N

def dp(v):
    if dpv[v] != -1:
        return dpv[v]
    if len(edge[v])==0:
        dpv[v]=0
        return 0
    res = 0
    for w in edge[v]:
        res = max(dp(w),res)
    res += 1
    dpv[v] = res
    return res

def solve():
    for i in range(N):
        dp(i)
    ans = max(dpv)
    # print(dpv)
    return ans
print(solve())

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int cnt[1000010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      cnt[i + j]++;
    }
  }

  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += cnt[i] * cnt[n - i];
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3224
import sys

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


def is_ok(x):
    num = 0
    for j in range(N):
        num += (A[j] - 1) // x

    if num <= K:
        return True
    else:
        return False


def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(0, 10 ** 9+1))


Measured memory_bytes: 93800
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

let n = Int(readLine()!)!
var count = 0
var ans = "No"
for _ in 0..<n {
  let (dl, dr) = toTuple(readInts())
  if dl == dr {
    count += 1
  } else {
    count = 0
  }
  if count == 3 {
    ans = "Yes"
  }
}
print(ans)

Measured memory_bytes: 13592
#include<stdio.h>
#include <stdbool.h>

#define N 8
#define F -1
#define NF 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

bool X[N][N];

void initialize(){
  int i;  
  for(i=0;i<N;i++){
row[i]=F;
col[i]=F;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=F;
    dneg[i]=F;
  }
}

void printBoard(){
  int i,j;  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){      
	printf("Q");
      }else{
	printf(".");
      }
    }
        printf("\n");
  }
}
  void recursive(int i){
      int j;
      
    if(i==N){
      printBoard();
      return;
    }

    for(j=0;j<N;j++){
      if(NF==col[j] || NF==dpos[i+j] || NF==dneg[i-j+N-1]){
	continue;
      }

      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=NF;

      recursive(i+1);

      row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=F;
    }
  }


int main(){
  int i,j,k,c,r;
  initialize();

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)      X[i][j]=false;

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=true;
  }

  recursive(0);
  return 0;
}



Measured memory_bytes: 2112
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#include<bits/extc++.h>
using namespace __gnu_pbds;
using oset = tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>;

ll bp(ll a, ll p) {
	ll r = 1;
	while(p) {
		if(p&1) r = r*a%mod;
		a = a*a%mod, p >>= 1;
	}
	return r;
}

struct dsu {
	vi e, mn;
	vector<map<int, int>> cnt;
	dsu(int n = 0) : e(n, -1), cnt(n), mn(n) {}
	int par(int i) {
		return e[i] > 0 ? e[i] = par(e[i]) : i;
	}
	void unite(int i, int j) {
		i = par(i), j = par(j);
		if(i == j) return;
		if(e[i] > e[j]) swap(i, j);
		e[i] += e[j], e[j] = i;
		mn[i] = min(mn[i], mn[j]);
		for(auto &x : cnt[j]) cnt[i][x.first]+=x.second;
	}
	ll eval(int i) {
		if(par(i) != i) return 1;
		ll res = 1;
		for(int f = 1; f <= -e[i]; f++) res = res*f%mod;
		for(auto t : cnt[i]) {
			ll q = 1;
			for(int f = 1; f <= t.second; f++) q = q*f%mod;
			res = res*bp(q, mod-2)%mod;
		}
		return res;
	}
};
ll n, x, y, w[maxn], c[maxn];
dsu a;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> x >> y;
	a = dsu(n+1);
	
	map<int, vi> col;
	
	for(int i = 1; i <= n; i++) {
		cin >> c[i] >> w[i];
	}
	for(int i = 1; i <= n; i++) {
		a.cnt[i][c[i]]++;
		a.mn[i] = w[i];
		col[c[i]].pb(i);
	}
	
	oset st;
	
	for(auto _i : col) {
		vi t;
		
		sort(all(_i.second), [&](auto i, auto j) {
			return w[i] < w[j];
		});
		
		for(int i = 0; i < _i.second.size(); i++) {
			if(i && w[_i.second[0]] + w[_i.second[i]] <= x) a.unite(_i.second[0], _i.second[i]);
			else t.pb(_i.second[i]);
		}
		
		vi good, bad;
		int mx = 0;
		for(auto i : t) {
			int cur = st.order_of_key({y-w[i], 1<<30});
			mx = max(mx, cur);
			(cur ? good : bad).pb(i);
			//cout << _i.first << " has " << i << '\n';
		}
		
		//for(auto &i : st) cout << i.first << " " << i.second << '\n';cout << "::";
		//cout << _i.first << " " << mx << " " << good.size() << " " << bad.size() << '\n';
		
		for(int i = 1; i < good.size(); i++) a.unite(good[i], good[0]);
		
		for(int i = 0; i < mx; i++) {
			a.unite(st.begin()->second, good[0]);
			st.erase(st.begin());
		}
		if(mx) {
			good[0] = a.par(good[0]);
			st.insert({a.mn[good[0]], good[0]});
		}
		for(auto &i : bad) {
			i = a.par(i), st.insert({a.mn[i], i});
		}
	}
	ll ans = 1;
	for(int i = 1; i <= n; i++) {
		//cout << i << " " << a.e[i] << '\n';
		ans = ans * a.eval(i) % mod;
	}
	cout << ans;
}


Measured memory_bytes: 53120
#include<stdio.h>

int main(void) {
        int a,b,c;

        scanf("%d %d %d", &a, &b, &c);

        if(0 > a || a > 100 || 0 > b || b > 100 || 0 > c || c > 100) {
           printf("input error\n");
           return 1;
        }

        (a < b && b < c) ? printf("Yes\n") : printf("No\n");

        return 0;
}



Measured memory_bytes: 2056
#include<stdio.h>
//#include <stdlib.h>
//#include<string.h>
using namespace std;
int main()
{
    int N,R;
    scanf("%d %d", &N, &R);
    if(N<10){
        printf("%d", (10-N)*100+R);
    }
    else{
        printf("%d", R);
    }
    return 0;
}

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



int main() {
	string str;
	cin >> str;
	if(str.at(0) != str.at(1) && str.at(1) != str.at(2) && str.at(2) != str.at(3)){
		cout << "Good" << endl;
	}else{
		cout << "Bad" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
long long n,v[1000005],i,act,ant,nr,ok;
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i) cin>>v[i];
    sort(v+1,v+n+1);
    i=n;
    while(i>=1)
    {
        act=v[i];
        nr=1;
        while(v[i]==v[i-1]&&i>=1) {--i;++nr;}
        if(nr>=4&&!ok)
        {
            cout<<act*act;
            return 0;
        }
        if(nr>=2&&ok)
        {
            cout<<ant*act;
            return 0;
        }
        if(nr>=2&&!ok)
        {
            ++ok;
            ant=act;
        }
        --i;
    }
    cout<<0;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string S;
    cin >> S;

    int minv = 1000000000;

    for (int i = 0; i < S.length() - 2;i++)
    {
        minv = min(minv, abs(atoi(S.substr(i, 3).c_str())-753));
    }

    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int n,k,tot,id,a[N][N];
bool judge(int x)
{
    for(int i=2;i*i<=x;i++)
        if(x%i==0) return false;
    return true;
}
vector<int>v[N*N];
int vv[N*N];
int main()
{
    for(int i=2;;i++)
        if(i*(i-1)+1>=1000&&i*(i-1)+1<=2000&&judge(i-1))
        {
            k=i;break;
        }
    n=k*(k-1)+1;
    printf("%d %d\n",n,k);
    for(int j=1;j<=k;j++)
    {
        ++tot;
        v[n].push_back(tot);
        for(int i=1;i<k;i++)
        {
            a[i][j]=++id;v[id].push_back(tot);
        }
    }
    for(int i=1,d=0;i<k;i++,d++)
    {
        for(int j=1;j<k;j++)
        {
            tot++;
            v[a[i][k]].push_back(tot);
            int x=j,y=k-1;
            while(y)
            {
                v[a[x][y]].push_back(tot);
                x+=d;y--;
                if(x>=k) x-=k-1;
            }
        }
    }
    for(int i=1;i<=tot;i++)
    {
        bool vis[2005];
        memset(vis,false,sizeof(vis));
        for(int j=0;j<v[i].size();j++) vis[v[i][j]]=true;
        for(int j=i+1;j<=tot;j++)
        {
            int ans=0;
            for(int k=0;k<v[j].size();k++)
                if(vis[v[j][k]]) ans++;
            assert(ans==1);
        }
    }
    assert(tot==n);
    for(int i=1;i<=tot;i++)
        for(int j=0;j<k;j++)
        vv[v[i][j]]++,assert(v[i][j]>=1&&v[i][j]<=n);
    for(int i=1;i<=tot;i++)
        for(int j=1;j<k;j++)
        assert(v[i][j]!=v[i][j-1]&&v[i][j]>=v[i][j-1]);
    for(int i=1;i<=tot;i++) assert(vv[i]==k);
    for(int i=1;i<=tot;i++)
    {
        assert(v[i].size()==k);
        for(int j=0;j<k;j++)
            printf(j==k-1?"%d\n":"%d ",v[i][j]);
    }
}


Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, c = LI()
clock_pos = []
value = []
for pos, v in LIR(n):
    clock_pos += [pos]
    value += [v]

r1 = 0
r2 = 0
A1 = [0]
A2 = [0]
for i in range(n):
    r1 += value[i]
    r2 += value[-i - 1]
    A1 += [max(A1[i], r1 - clock_pos[i])]
    A2 += [max(A2[i], r2 - (c - clock_pos[-i-1]))]

ans = 0
for j in range(n-1):
    ans = max(ans, A1[j+1] + A2[n - j - 1] - clock_pos[j], A2[j+1] + A1[n - j - 1] - (c - clock_pos[-j-1]))

print(max(ans, A1[-1], A2[-1]))

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

int main() {
  int n, cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (to_string(i).length() % 2 != 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main(){
  int a,b,x;
  cin>>a>>b;
  x=0;
  for(int i=a; i<=b; ++i){
    if(i==0){
      cout<<"Zero"<<endl;
      return 0;
    }
    if(i<0) x++;
  }
  if(x%2==0){
    cout<<"Positive"<<endl;
  } else {
    cout<<"Negative"<<endl;
  }
  return 0;
}


Measured memory_bytes: 896
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
string S = "";

int main() {
	scanf("%lld", &N);
	cin >> S;
	if(S.size() % 2) {
		printf("No\n");
		return 0;
	}
	int sz = S.size() / 2;
	string T = S.substr(0, sz);
	string X = S.substr(sz);
	if(T == X) {
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> fru(n);
  for(int i=0; i<n; ++i) cin >> fru[i];
  sort(fru.begin(),fru.end());
  int ans = 0;
  for(int i=0; i<k; ++i){
    ans += fru[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n=I()
a=[]
for i in range(n):
    x,l=LI()
    a.append((x,l,x+l))

a.sort(key=lambda x:x[2])

R=-inf
for i in range(n):
    x,l,r=a[i]
    if x-l>=R:
        ans+=1
        R=r
    
    
    
print(ans)


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

using namespace std;

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

int n, m, k;

double solve(int sum, int n) {
  if (n == 0) {
    if (sum <= k) return 1;
    return sum - k;
  }
  double res = 0;
  rep(i, m) res += solve(sum + i + 1, n - 1);
  return res / m;
}

int main() {
  while (true) {
    cin >> n >> m >> k;
    if (n == 0 && m == 0 && k == 0) break;
    printf("%.12f\n", solve(0, n));
  }
  return 0;
}

Measured memory_bytes: 1188
def main():
    N = int(input())
    F = [list(map(int, input().split())) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]
    ans = -(10**15)
    for i in range(2**10):
        tmp = []
        for j in range(10):
            if ((i >> j) & 1):
                tmp.append(j)
        if not tmp:
            continue
        score = 0
        for k in range(N):
            cnt = 0
            for l in range(10):
                if F[k][l] == 1 and l in tmp:
                    cnt += 1
            score += P[k][cnt]

        ans = max(ans, score)

    print(ans)
if __name__ == "__main__":
    main()

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

bool eval(const std::string & S)
{
    if (S.size() % 2 == 1)
        return false;
    int len = S.size() / 2;
    for (int i=0; i<len; ++i) {
        if (S[i] != S[len + i])
            return false;
    }
    return true;
}

int main()
{
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;

    std::cout << (eval(S) ? "Yes" : "No") << std::endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
  else if(s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

char m[50][50];
ll a[50][50];
bool v[50][50];
ll qx[100000] = {};
ll qy[100000] = {};
ll p = 0;
ll s = 0, e = 0;
ll white = 0, b = 0;
int main() {
	ll h, w; cin >> h >> w;
	rep(i, 0, h) {
		cin >> m[i];
	}
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (m[i][j] == '.')white++;
			v[i][j] = false;
			a[i][j] = INF;
		}
	}

	ll sx = 0, sy = 0;
	ll gx = w - 1, gy = h - 1;
	a[sy][sx] = 0;

	ll x[4] = { 1,0,0,-1 };
	ll y[4] = { 0,1,-1,0 };

	qy[e] = sy;
	qx[e] = sx;
	e++;
	v[sy][sx] = true;

	while (s < e) {
		ll cy = qy[s];
		ll cx = qx[s];
		s++;

		rep(i, 0, 4) {
			ll ny = cy + y[i];
			ll nx = cx + x[i];

			if (ny >= 0 && nx >= 0 && ny < h && nx < w && m[ny][nx] == '.' && !v[ny][nx])
			{
				qy[e] = ny;
				qx[e] = nx;
				e++;
				a[ny][nx] = a[cy][cx] + 1;
				v[ny][nx] = true;
			}
		}
	}

	//rep(i, 0, h) {
	//	rep(j, 0, w) {
	//		if (a[i][j] == INF) a[i][j] = 0;
	//		printf("%02d ", a[i][j]);
	//		//cout << a[i][j];
	//	}
	//	cout << endl;
	//}
	if (a[h - 1][w - 1] == INF) {
		cout << -1 << endl;
		return 0;
	}

	cout << white - a[h - 1][w - 1] - 1 << endl;

	return 0;
}

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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a==b && b !=c || a==c && a!= b || b == c && b!= a) 
		cout << "Yes\n";
  	else
      	cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int N, M, Q;
int cnt[505][505];
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N >> M >> Q;
    rep(i, M) {
        int L, R; cin >> L >> R;
        cnt[L][R]++;
    }
    srep(L, 1, N + 1) srep(R, 2, N + 1) cnt[L][R] += cnt[L][R - 1];
    rep(_,Q) {
        int p, q; cin >> p >> q;
        int ans = 0;
        srep(L, p, q + 1) ans += cnt[L][q];
        printf("%d\n", ans);
    }
  return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll p[16], ans[16], dp[14400000], mn[16], nb[16], st[16], dist[16][16][2];
pll c[16];

int main()
{
    fast_io;
    ll n, i, j, t, s, m, nw;
    vector<ll> v;
    cin >> n;
    for (i = 1, st[0] = 1; i <= n; i++) cin >> c[i].first >> c[i].second >> p[i], st[i] = st[i - 1] * 3, ans[i] = inf;
    for (i = 1; i <= n; i++) mn[i] = p[i] * min(abs(c[i].first), abs(c[i].second)), dp[0] += mn[i];
    ans[0] = dp[0];
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
            for (t = 0; t <= 1; t++)
                dist[i][j][t] = p[i] * abs(t ? c[i].second - c[j].second : c[i].first - c[j].first);
    for (i = 1; i < st[n]; i++)
    {
        dp[i] = inf;
        t = i, nw = 0;
        v.clear();
        for (j = 1; t > 0 && j <= n; j++, t /= 3)
        {
            nb[j] = t % 3;
            if (nb[j]) nw++, v.pb(j), dp[i] = min(dp[i], dp[i - nb[j] * st[j - 1]]);
        }
        for (j = 1, s = 0; j <= n; j++)
        {
            m = mn[j];
            for (auto f: v) m = min(m, dist[j][f][nb[f] - 1]);
            s += m;
        }
        dp[i] = min(dp[i], s);
        ans[nw] = min(ans[nw], dp[i]);
    }
    for (i = 0; i <= n; i++) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 115620
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
using namespace std;
const int MN = 2e5+5;
int N,M,D[MN],C[MN],Q[MN],par[MN],cnt,num;
ppi E[MN];
bool ch[MN],tree[MN],col[MN];
vector<int> T[MN];

int fnd(int a)
{
    return par[a]==a ? a : par[a]=fnd(par[a]);
}

void join(int a, int b)
{
    a = fnd(a), b = fnd(b);
    par[b] = a;
}

void dfs(int s, int r)
{
    for(int e : T[s]){
        if(e==r) continue;
        col[e] = !col[s];
        dfs(e,s);
    }
}

bool cmp(ppi p, ppi q)
{
    return max(D[p.va.va],D[p.va.vb])<max(D[q.va.va],D[q.va.vb]);
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> N >> M;
    for(int i=1; i<=N; i++){
        par[i] = i;
        cin >> D[i];
    }
    for(int i=1; i<=N; i++){
        Q[i] = 1e9+7;
    }
    for(int i=0; i<M; i++){
        cin >> E[i].va.va >> E[i].va.vb;
        E[i].vb = i;
    }
    sort(E,E+M,cmp);
    for(int i=0; i<M; i++){
        int a = E[i].va.va;
        int b = E[i].va.vb;
        if(fnd(a)!=fnd(b)){
            join(a,b);
            T[a].push_back(b);
            T[b].push_back(a);
            C[E[i].vb] = max(D[a],D[b]);
            Q[a] = min(Q[a],C[E[i].vb]);
            Q[b] = min(Q[b],C[E[i].vb]);
            tree[E[i].vb] = 1;
            cnt++;
        }
    }
    if(cnt<N-1){
        cout << -1;
        return 0;
    }
    for(int i=1; i<=N; i++){
        if(Q[i]!=D[i]){
            cout << -1;
            return 0;
        }
    }
    dfs(1,1);
    for(int i=1; i<=N; i++){
        if(col[i]) cout << 'B';
        else cout << 'W';
    }
    cout << '\n';
    for(int i=0; i<M; i++){
        if(tree[i]) cout << C[i] << '\n';
        else cout << "1000000000\n";
    }
}


Measured memory_bytes: 18176
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void c_3_or_2(void) {
	int n;
	cin >> n;
	vector<long long> a(n + 1);
	for (int i = 1; i <= n; i++)cin >> a[i];

	int oddcnt = 0;
	bool use_div2 = false;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			cnt++;
		}
	}
  cout << cnt << endl;
}

int main()
{
    c_3_or_2();
    return 0;
}

Measured memory_bytes: 3700
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

bool isPrime(int x){
    for (int i = 2; i < x/2+1; i++)
        if(x%i==0)return false;


    return true;
}

int main(){
    int x;
    cin>>x;
    
    while (1)
    {
        if(isPrime(x))break;
        x++;
    }
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,k,sum=-1e18-1e9,a[10005],b[10005];
bool flag[10005];
vector<long long>v;
list<long long>q;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]--;
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
		sum=max(sum,b[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(flag[i])
			continue;
		int cnt=a[i];
		flag[i]=true;
		v.clear();
		v.push_back(0);
		v.push_back(b[a[i]]);
		long long t=b[a[i]];
		while(!flag[cnt])
		{
			flag[cnt]=true;
			cnt=a[cnt];
			t+=b[cnt];
			v.push_back(b[cnt]);
		}
		long long p=k,res=0;
		bool ok=false;
		if(t>0)
		{
			int vv=v.size()-1;
			if(p/vv-1>0)
				ok=true;
			res+=max(((p/vv)-1),0ll)*t;
			if(p>vv)
			{
				p%=vv;
				p+=vv;
			}
		}
		int pp=v.size();
		for(int j=1;j<pp;j++)
			v.push_back(v[j]);
		for(int j=1;j<pp;j++)
			v.push_back(v[j]);
		for(int j=2;j<v.size();j++)
			v[j]+=v[j-1];
		long long mx=-1e18-1e9;
		while(!q.empty())
			q.pop_back();
		q.push_front(0);
		for(int j=1;j<v.size();j++)
		{
			while(!q.empty()&&v[q.front()]>v[j])
				q.pop_front();
			q.push_front(j);
			while(!q.empty() && j-q.back()>p)
				q.pop_back();
			if(j!=q.back())
				mx=max(mx,v[j]-v[q.back()]);
		}
		res+=mx;
		sum=max(sum,res);
	}
	cout<<sum<<endl;

	return 0;
}

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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int dp[100005][13];

signed main() {
    string S;
    cin >> S;
    int N = S.size();

    dp[0][0] = 1;
    REP2(i, 1, N) {
        if (S[i-1] == '?') {
            REP(k, 10) {
                REP(j, 13) {
                    dp[i][(10 * j + k) % 13] += dp[i-1][j];
                    dp[i][(10 * j + k) % 13] %= MOD;
                }
            }
        } else {
            int k = S[i-1] - '0';
            REP(j, 13) {
                dp[i][(10 * j + k) % 13] += dp[i-1][j];
                dp[i][(10 * j + k) % 13] %= MOD;
            }
        }
    }
    cout << dp[N][5] << endl;

    return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    fast;
    ll n,x;
    cin>>n>>x;
    ll dp[n],count=1,i,a;
    dp[0]=0;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        dp[i]=a+dp[i-1];
    }
    for(i=1;i<=n;i++)
    {
        if(dp[i]<=x)
        {
            count++;
        }
        else
        {
            break;
        }
    }
    cout<<count<<endl;
    
}


Measured memory_bytes: 256
n = int(input())
minp, maxp = map(int, input().split())
scores = list(map(int, input().split()))
cnta, cntb, cntc = 0, 0, 0
for item in scores:
    if(item <= minp): cnta+=1
    elif(item <= maxp): cntb+=1
    else: cntc+=1
qnum = min([cnta, cntb, cntc])
print(qnum)

Measured memory_bytes: 3064