akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

// static const int N = 100100;

inline int division_round_up(const int a, const int b)
{
    return (a + b - 1) / b;
}

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

    int n, h;
    // array<int, N> a, b;
    vector<int> a, b;

    cin >> n >> h;
    a.resize(n + 10);
    b.resize(n + 10);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }

    const int a_max = *max_element(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<int>());

    int count = 0;

    for (int i = 0; i < n && b[i] >= a_max; i++)
    {
        h -= b[i];
        count++;

        if (h <= 0)
        {
            cout << count << endl;
            return 0;
        }
    }

    if (a_max != 0)
        count += division_round_up(h, a_max);

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
h = list(map(int,input().split()))
ans = 0
while True:
  water = False
  finish = True
  for i in range(n):
    if h[i] > 0:
      h[i] -= 1
      water = True
      finish = False
    elif water:
      ans += 1
      water = False
  if water:
    ans += 1
  if finish:
    break
print(ans)

Measured memory_bytes: 3064
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
from collections import deque, defaultdict, Counter
import heapq

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def main():
    N, M = MI()
    uf = UnionFind(N)
    for i in range(M):
        a, b = MI()
        a -= 1
        b -= 1
        uf.union(a, b)
    print(uf.group_count() - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74528
N=int(input())
S=[]
for i in range(N):
    s=input()
    S.append(s)
m=1
x=dict()
for i in range(N):
    if S[i] in x:
        x[S[i]]+=1
        m=max(m,x[S[i]])
    else:
        x[S[i]]=1
l=[]
for idx in x:
    if x[idx]==m:
        l.append(idx)
l.sort()
for i in range(len(l)):
    print(l[i])

Measured memory_bytes: 35216
let () = Scanf.scanf "%d %d" (fun n x ->
  if x <= 1 || 2 * n - 1 <= x then print_endline "No"
  else begin
    print_endline "Yes";
    for i = 2 to n - 1 do
      Printf.printf "%d\n"
        (if x <= i then i + 1 else i)
    done;
    Printf.printf "%d\n%d\n1\n" (2 * n - 1) x;
    for i = n + 1 to 2 * n - 2 do
      Printf.printf "%d\n"
        (if i <= x then i - 1 else i)
    done
  end)

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int input = int.Parse(Console.ReadLine());
            if (input >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

    }
}

Measured memory_bytes: 27364
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <ctime>
#include <utility>
#include <fstream>
#include <queue>
#include <deque>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("vpt")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:256000000")
#pragma warning(disable:4996)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
const ld pi = 3.14159265358979323846264;
const char el = '\n';
//const int inf = 1000'000'000;
 
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define all(v) v.begin(), v.end()
#define x first
#define y second
 
template<typename T> bool uin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T> bool uax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class iterator> void output(iterator begin, iterator end, char p = ' ', ostream &out = cout) { while (begin != end) { out << (*begin) << p; begin++; } out << el; }
template<class T> void output(T x, char p = ' ', ostream &out = cout) { output(all(x), p, out); }
 
mt19937 rnd(time(NULL));

#define int long long

const int N = 1000 * 10000 + 228;
const int MOD = 998244353;

int n;
int f[N], rf[N];

int mod(int x) {
    x %= MOD;
    if (x < 0) x += MOD;
    return x;
}

int fp(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mod(res * a);
        }
        a = mod(a * a);
        b >>= 1;
    }
    return res;
}

int C(int n, int k) {
    return mod(f[n] * mod(rf[k] * rf[n - k]));
}

int base[N];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> n;
    f[0] = 1;
    for (int i = 1; i <= n; ++i) {
        f[i] = mod(f[i - 1] * i);
    }
    rf[n] = fp(f[n], MOD - 2);
    for (int i = n - 1; i + 1; --i) {
        rf[i] = mod(rf[i + 1] * (i + 1));
    }
    base[0] = 1;
    for (int i = 1; i <= n; ++i) {
        base[i] = mod(base[i - 1] * 2);
    }
    int res = fp(3, n);
    for (int A = n / 2 + 1; A <= n; ++A) {
        res = mod(res - mod(2 * C(n, A) * base[n - A]));
    }
    cout << res << '\n';
    return 0;
}
/*
<>>><<><<<<<>>><
0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1
0 3 2 1 0 1 2 0 1 2 3 4 5 3 2 0 1 

*/

Measured memory_bytes: 234624
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if w >= v:
    print("NO")
else:
    dif = v - w
    x = dif * t
    if abs(a - b) <= x:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9180
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  double m[2][2],det,i[2][2],x[2];
  while(cin >>m[0][0]>>m[0][1]>>x[0]>>m[1][0]>>m[1][1]>>x[1]){
    det = m[0][0]*m[1][1]-m[0][1]*m[1][0];
    i[0][0] = m[1][1]/det;
    i[0][1] = -m[0][1]/det;
    i[1][0] = -m[1][0]/det;
    i[1][1] = m[0][0]/det;
    printf("%.3lf %.3lf\n",i[0][0]*x[0]+i[0][1]*x[1],i[1][0]*x[0]+i[1][1]*x[1]);
  }
 return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    ll n;
    cin >> n;

    vector<bool> a(n+1, false);
    ll cnt = 0;
    ll idx = 0;
    for (int i = 1; i <= n; i++) {
        cnt += i;
        a[i] = true;

        if(cnt>=n){
            a[cnt - n] = false;
            idx = i;
            break;
        }
    }

    for (int i = 1; i <= idx; i++){
        if(a[i]){
            cout << i << endl;
        }
    }
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

void solve(int w,int h) {
    int n;
    cin >> n;
    
    vector<pair<int,int> > x,y;

    for(int i=0; i<n; ++i) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        x.push_back(make_pair(a,i));
        x.push_back(make_pair(c,i));
        y.push_back(make_pair(b,i));
        y.push_back(make_pair(d,i));
    }

    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    int prev=0;
    int rnkx=0;
    bool lc;
    if(x[2*n-1].first==w) lc=true;
    else lc=false;
    for(int i=0; i<2*n; ++i) {
        if(prev!=x[i].first) rnkx+=2;
        prev=x[i].first; x[i].first=rnkx;
    }
    if(!lc) rnkx+=2;

    prev=0;
    int rnky=0;
    if(y[2*n-1].first==h) lc=true;
    else lc=false;
    for(int i=0; i<2*n; ++i) {
        if(prev!=y[i].first) rnky+=2;
        prev=y[i].first; y[i].first=rnky;
    }
    if(!lc) rnky+=2;

    sort(x.begin(),x.end(),[](pair<int,int>& lhs, pair<int,int>& rhs) {
        return (lhs.second==rhs.second?lhs.first<rhs.first:lhs.second<rhs.second);
    });
    sort(y.begin(),y.end(),[](pair<int,int>& lhs, pair<int,int>& rhs) {
        return (lhs.second==rhs.second?lhs.first<rhs.first:lhs.second<rhs.second);
    });

    vector<vector<int> > mp;
    vector<int> vtemp(rnkx+1,0);
    for(int i=0; i<rnky+1; ++i) mp.push_back(vtemp);

    for(int i=0; i<n; ++i) {
        for(int j=y[2*i].first; j<=y[2*i+1].first; ++j) {
            for(int k=x[2*i].first; k<=x[2*i+1].first; ++k) {
                mp[j][k]=-1;
            }
        }
    }

    int col=0;
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    queue<pair<int,int> > q;
    for(int i=0; i<rnky+1; ++i) {
        for(int j=0; j<rnkx+1; ++j) {
            if(mp[i][j]!=0) continue;
            mp[i][j]=++col;
            q.push(make_pair(i,j));
            while(!q.empty()) {
                pair<int,int> p=q.front(); q.pop();
                int pj=p.second;
                int pi=p.first;
                for(int k=0; k<4; ++k) {
                    if(pi+dy[k]>=0 && pi+dy[k]<rnky+1 && pj+dx[k]>=0 && pj+dx[k]<rnkx+1
                        && mp[pi+dy[k]][pj+dx[k]]==0) {
                            mp[pi+dy[k]][pj+dx[k]]=mp[pi][pj];
                            q.push(make_pair(pi+dy[k],pj+dx[k]));
                    }
                }
            }
        }
    }
    cout << col << endl;

    return;
}


int main() {
    int w,h;
    while(true) {
        cin >> w >> h;
        if(w==0 && h==0) break;
        solve(w,h);
    }
    return 0;
}


Measured memory_bytes: 7532
<?php
	fscanf(STDIN,'%d%d%d',$n,$a,$b);
	for(;$i++<$n;){
		$x=$i;
		$m=0;
		while($x){$m+=$x%10;$x=floor($x/10);}
		if($a<=$m&&$m<=$b)$s+=$i;
	}
	echo $s;


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

int main() {
	int cnt[130];
	fill_n(cnt, 130, 0);
	
	char temp[3];
	scanf("%s", temp);
	
	for (int i = 0; i < 3; i++) cnt[temp[i]]++;
	
	printf("%s", cnt[97] == cnt[98] && cnt[99] == cnt[98] ? "Yes" : "No");
	
	
	return 0;
}

Measured memory_bytes: 256
from operator import itemgetter

N= int(input())
lst = []
for i in range(N):
    s, p = input().split()
    lst.append([s, int(p), i])
lst = sorted(lst, key=itemgetter(1), reverse=True)
lst = sorted(lst, key=itemgetter(0))
for l in lst:
    print(l[2]+1)

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:
#define error(args...) { vector<string> _debug = split(#args, ',');err(begin(_debug), args);}

vector<string> split(const string& s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.emplace_back(x);
	return move(v);
}

void err(vector<string>::iterator it) {cerr << endl;}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) {
	cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << " ", err(++it, args...);
}


int n;
int a[200010], b[200010];

int main(void) {
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];


	int ans = 0;
	rep(j, 29) {
		const int tar = (1 << j);
		const int mod = 2 * tar;

		vector<int> ary;
		rep(i, n) ary.push_back(b[i] & (mod - 1));
		sort(begin(ary), end(ary));
		rep(i, n) ary.push_back(ary[i] + mod);

		ll total = 0LL;
		rep(i, n) {
			const int aval = a[i] & (mod - 1);
			const int l =  mod + tar - aval;
			const int r = 2 * mod - aval - 1;
			const ll num = upper_bound(begin(ary), end(ary), r) - lower_bound(begin(ary), end(ary), l);
			//error(i, l, r, num);
			total += num;
		}

		//error(j, total);

		//for (auto &elem : ary) error(elem);

		if (total % 2 == 1) ans ^= (1 << j);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6012
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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 int MOD = 1000000007;
const int MAX_N = 300000;

const ll INF = LONG_LONG_MAX / 2;

// auto mod int
// ref. https://github.com/atcoder-live/library/blob/master/mint.cpp
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

    mint ans = 0;
    // mint low = 0;
    // mint high = N;
    ll low = 0;
    ll high = 0;
    for (int i = 1; i < K; i++) {
        low += i - 1;
        high += N - i + 1;
    }
    for (int i = K; i <= N; i++) {
        low += i - 1;
        high += N - i + 1;
        ans += high - low + 1;
        // printf("low: %lld, high: %lld, ans: %lld\n", low, high, ans.x);
    }

    ans += 1;

    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 3636
n,x = map(int,input().split())
l =[]
l = [int(x) for x in input().split()]
d = 0
c = 0
if l[0] > x:
  print(1)
  exit()
for i in range(n):
  d = d + l[i]
  c += 1
  if d > x:
    print(c)
    exit()
print(c+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  long N, K;
  cin >> N >> K;
  if (N/K==0&&N%K==0){
    cout << 0 << endl;
  }
  else {
  cout <<   min( N%K,abs(N%K-K)) << endl;
  }
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int a, b, c;
    a = N/100;
    b = (N - a*100)/10;
    c = (N - a * 100 - b * 10);
    if (a == 7 || b == 7 || c == 7)  cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {

  int N, M;
  cin >> N >> M;

  vector<int> card(N+1);
  for (int i = 0; i < M; i++) {
    int L, R;
    cin >> L >> R;
    card[L]++;
    if (R != N) {
      card[R+1]--;
    }
  }

  for (int i = 1; i <= N; i++) {
    card[i] = card[i] + card[i-1];
  }

  int answer = 0;

  for (int i = 1; i <= N; i++) {
    if (card[i] == M) {
      answer++;
    }
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 640
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	let a = parseInt(input[0], 10);
	let b = parseInt(input[1], 10);

  let d = b%2
  let e = 2*a-b/2;
  let f = b/2-a;

  if ((d==0 && e>0 && f>0) || (d==0 && e==0 && f>0) || (d==0 && e>0 && f==0)) {
      console.log('Yes');
  } else {
    console.log('No');
  }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30236
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define inp(a) int a; cin>>a;
#define inpa(a,n) vector<int>a(n); FOR(i,0,n-1) cin>>a[i];
#define PI 3.141592653589793238
#define QUICK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vec(x) vector<x>
#define pii pair<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define FOR(i,j,n) for(int i= j; i<=n; i++)
#define srt(a); sort(a.begin(), a.end())
#define CASE int t; cin>>t; while(t--)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define print(x) for(auto c : x) cout << c << " ";
#define dbg(x) cerr << #x << " :: "<< x << endl;
#define dbg2(x,y) cerr << #x << " :: "<<x <<"\t" << #y << " :: "<<y <<endl;
#define upcase(s)  transform(s.begin(), s.end(), s.begin(), ::toupper)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define int ll
const int INF = 1e9 + 7;
const int SIZE = 150007;
const int MOD = 1e9 + 7; 
//////////// template ends here //////////////////////////

int bottomup(int num, int k, vec(int)h, vec(int)dp){

	FOR(i,1,num){
		FOR(j,1,k){
			if(i-j >= 0){
				dp[i] =  min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
			}else 
				break;
		}
	}

	return dp[num];
}


void solve(){	
	inp(n); inp(k);
	inpa(h,n);
	//print(h)
	vec(int)dp(n+1, INF);
	dp[0] = 0;
	cout << bottomup(n-1, k, h, dp);

	//print(dp)
	
}



int32_t main(){
	#ifndef ONLINE_JUDGE 
		freopen ("input.txt","r",stdin);
		freopen ("output.txt","w",stdout);
	#endif	
	QUICK;
	
	solve();
	printclock;
}

Measured memory_bytes: 6348
while True:
    n,m=map(int,input().split())
    if n==m==0:break
    alist = []
    for i in range (n):
        a=int(input())
        alist.append(a)
    s = sum(alist[0:m])   #a[i:j]→[a[i], a[i+1], a[i+2], ..., a[j-1]]
    max = s
    for i in range(m, n):
        s = s + alist[i] - alist[i - m]
        if s > max:
            max = s
    print(max)


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

using namespace std;

// 別解（隣接行列の利用）
int main() {
    int N, M;
    cin >> N >> M;

    vector<int> a;
    vector<int> b;
    vector<vector<int>> adjacencyMatrix(9, vector<int>(9, false));  // 隣接行列
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        adjacencyMatrix.at(a - 1).at(b - 1) = adjacencyMatrix.at(b - 1).at(a - 1) = true;
    }

    // 考え方メモ
    // 前提：グラフの経路は頂点の並びで全パターン洗い出せる

    vector<int> permutation;
    for (int i = 0; i < N; i++) {
        permutation.push_back(i);
    }

    // 考え方メモ
    // 具体例：
    // case1: (0, 1, 2) -> (0, 1) = (a0, b0) or (a1, b1) or (a2, b2)
    // case2: (0, 2, 1) -> (0, 2) = (a0, b0), (2, 1) = (a1, b1)
    int allPathClearCount = 0;
    do {
        if (permutation.at(0) != 0) break;  // 0始まり以外無視

        bool isOk = true;
        for (int i = 0; i < N - 1; i++) {
            int num = permutation.at(i);
            int nextNum = permutation.at(i + 1);
            if (!adjacencyMatrix.at(num).at(nextNum)) {
                isOk = false;
            }
        }
        if (isOk) {
            allPathClearCount++;
        }
    } while (next_permutation(permutation.begin(), permutation.end()));

    cout << allPathClearCount << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;

typedef long long ll;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main(int argc, char const *argv[])
{
    int n,m;scanf("%d %d",&n,&m);
    vector<ll> a(n);for(int i = 0;i < n;i++)scanf("%lld",&a[i]);
    vector<ll> b(m);for(int i = 0;i < m;i++)scanf("%lld",&b[i]);
    
    vector<int> eL(n*m+1,0),eC(n*m+1,0);

    for(int i = 0;i < n;i++){
        eL[a[i]]++;
        if(eL[a[i]] > 1){
            cout << 0 << endl;return 0;
        }
    }
    for (int i = 0; i < m; ++i)
    {
        eC[b[i]]++;
        if(eC[b[i]]>1){
            cout << 0 << endl;return 0;
        }
    }

    vector<int> C(n*m+1,0),L(n*m+1,0);
    int cl = 0,cc = 0;
    for(int i = n*m;i >= 1;i--){
        if(eL[i])L[i] = ++cl;else L[i] = cl;
        if(eC[i])C[i] = ++cc;else C[i] = cc;
    }

    mint ans = 1;
    for(int i = n*m;i >= 1;i--){
        if(eL[i] and eC[i]){
            ans *= 1;
        }else if(eL[i]){
            ans *= (mint)(C[i]);
        }else if(eC[i]){
            ans *= (mint)(L[i]);
        }else{
//            cout << m-C[i] << " " << n - L[i] << " " << n*m-i << " ";
//            cout << (m - C[i])*(n - L[i]) - (n*m - i) << " ";
            ans *= (mint)((C[i])*(L[i]) - (n*m - i));
        }
//        cout << ans.x << endl;
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
long long gcd(int a,int b);
#define rep(i,n) for(int i=1;i<=n;i++)

int main() {
  int N;
  int ans=0;
  cin>>N;
  rep(i,N){
    rep(j,N){
      rep(k,N){
       ans += gcd(gcd(i,j),k);
      }
    }
  }
  cout<<ans;
}
long long gcd(int a,int b){  
while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

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

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


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

    lli total = N * (N + 1) / 2;
    lli t3 = N / 3;
    lli t5 = N / 5;
    lli t15 = N / 15;
    lli s3 = 3 * (t3 * (t3 + 1)) / 2;
    lli s5 = 5 * (t5 * (t5 +1 )) /2;
    lli s15 = 15 * (t15 *(t15 +1)) /2;

    total -= (s3 + s5 - s15);
    cout << total << endl;

    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;


int main() {
    int n, x;
    cin >> n;
    vector <int> cnt(N, 0);
    long long ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> x;
        cnt[x]++;
        ans += x;
    }   
    int m, y;
    cin >> m;
    while(m--) {
        cin >> x >> y;
        ans -= 1LL * cnt[x] * x;
        ans += 1LL * cnt[x] * y;
        cnt[y] += cnt[x];
        cnt[x] = 0;
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 3740
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int a,b,ans;
int main(){
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(j<10) continue;
			int x = j/10, y = j%10;
			if(x>=2&&y>=2&&x*y==i) ans++;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;
const int maxn = 1e5 + 1000;
const int mod = 1e9 + 7;
int s[maxn],t[maxn];
char str[maxn];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie();
    int te;
    cin>>str;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]=='A') te=1;
        else te=2;
        s[i+1]=s[i]+te;
    }
    cin>>str;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]=='A') te=1;
        else te=2;
        t[i+1]=t[i]+te;
    }
    int n;
    int a,b,c,d;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>a>>b>>c>>d;
        if((s[b]-s[a-1])%3==(t[d]-t[c-1])%3){
            cout<<"YES"<<endl;
        }
        else {
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


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


int main(){
	int n,k;
	scanf("%d %d", &n, &k);
	
	int soma=0;
	vector<int> divisores;
	int l[n];
	int aux[n];
	long long acumulado1[n+1];
	long long acumulado2[n+1];
	acumulado1[0]=0;
	acumulado2[0]=0;
	int res=1;
	
	for (int i=0; i<n; i++){
		scanf("%d", &l[i]);
		
		soma+=l[i];
	}
	
	for (int i=1; i<=sqrt(soma); i++){
		if (soma%i==0){
			divisores.push_back(i);
			if (soma/i!=i) divisores.push_back(soma/i);
		}
	}
	
	sort(divisores.begin(), divisores.end());
	
	for (int i=0; i<divisores.size(); i++){
		for (int j=0; j<n; j++){
			aux[j]=l[j]%divisores[i];
		}
		
		sort (aux, aux+n);
		
		for (int j=0; j<n; j++){
			acumulado1[j+1]=acumulado1[j]+aux[j];
			acumulado2[j+1]=acumulado2[j]+(divisores[i]-aux[j]);
		}
		
		for (int j=0; j<=n; j++){
			if (acumulado1[j]==acumulado2[n]-acumulado2[j] and acumulado1[j]<=k)
				res=divisores[i];
		}
	}
	
	
	cout<<res<<endl;
}


Measured memory_bytes: 256
N = int(input())
L=list(map(int,input().split()))

ans=0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            A=[L[i],L[j],L[k]]
            A = sorted(A)
            if len(set(A))!=3:
                continue
            if A[0]+A[1]>A[2]:
                ans+=1
print(ans)


Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
int main(void){
    // Your code here!
    long long int c[5];
    long long int d[6]={0};
    long long int t =0 ;
    long long int n;
    long long int min_c;
    cin >> n;
    d[0] = n;
    for(int i =0 ; i < 5; i++){
        cin >> c[i];
    }
    min_c = *min_element(c,c+5);
    //cout << min_c << endl;
    t = (n-1) / min_c + 4;
    cout << t+1<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 2e5 + 7;
const int maxV = 20;
const int maxS = (1 << maxV);

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline void Min(int &x, int y) {if (y < x) x = y;}
inline void Max(int &x, int y) {if (y > x) x = y;}

int n, m, V;
int a[maxN], b[maxN];
int nx[maxV][maxN], pr[maxV][maxN];
int f[maxS], g[maxS];

struct dsu {
	int mn, mx, fa;
}fa[maxN];

inline int find(int x) {return (fa[x].fa != x) ? fa[x].fa = find(fa[x].fa) : x;}

void merge(int x, int y) {
	if (find(x) != find(y)) {
		Min(fa[find(y)].mn, fa[find(x)].mn);
		Max(fa[find(y)].mx, fa[find(x)].mx);
		fa[find(x)].fa = find(y);
	}
}

struct rec {
	int l, r;
	inline bool operator < (const rec &v) const {
		return r < v.r;
	}
}q[maxS]; int tt;

int main() {

	n = ri(), m = ri();
	rep (i, 1, n) a[i] = ri();
	for (int i = m; i > 0; i >>= 1) b[++V] = i; b[++V] = 0;
	reverse(b+1, b+V+1);
	
	rep (i, 1, n) fa[i] = (dsu){i, i, i};

	rep (j, 1, V) {
		rep (i, 2, n) if (a[i] - a[i - 1] <= b[j]) merge(i, i-1);
		rep (i, 1, n) nx[j][i] = fa[find(i)].mx, pr[j][i] = fa[find(i)].mn;
		nx[j][n+1] = n;
		pr[j][0] = 1;
	}

	int mask = (1 << V) - 1;
	f[0] = 0;
	rep (s, 1, mask) {
		f[s] = 0;
		rep (j, 1, V) if (s >> (j-1) & 1)
			Max(f[s], nx[j][f[s ^ (1 << (j-1))] + 1]);
	}
	g[0] = n+1;
	rep (s, 1, mask) {
		g[s] = n+1;
		rep (j, 1, V) if (s >> (j-1) & 1)
			Min(g[s], pr[j][g[s ^ (1 << (j-1))] - 1]);
	}

	rep (s, 0, mask = (1 << (V-1)) - 1)
		q[++tt] = (rec){f[s], g[mask ^ s]};
	sort(q+1, q+tt+1);

	for (int i = 1, j = 1, cl = -1; i <= n; ++ i) {
		int l = fa[find(i)].mn, r = fa[find(i)].mx;
		for (; j <= tt && q[j].r <= r+1; ++ j) cl = max(cl, q[j].l);
		puts(cl >= l - 1 ? "Possible" : "Impossible");
	}

	return 0;
}

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

int main() {
  
  int a,b,c;
  
  cin >> a >> b >> c;
  
  int w;
  
  w = a;
  a = b;
  b = w;
  
  w = a;
  a = c;
  c = w;
  
  cout << a << " " << b << " " << c << endl;
  
  
}


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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vl x(n);
  rep(i,n) cin >> x[i];

  vl y(n-1);
  rep(i,n-1) y[i] = x[i+1] - x[i];
  sort(y.begin(), y.end());
  reverse(y.begin(), y.end());
  
  vl z(n);
  z[0] = a*(x[n-1]-x[0]);
  rep(i,n-1) z[i+1] = z[i] - a*y[i] + b;
  
  ll ans = z[0];
  rep(i,n) ans = min(ans,z[i]);
  
  cout << ans << endl;
}

Measured memory_bytes: 5640
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

string s;

int main(){
	getline(cin,s);
	for(string::iterator i=s.begin();i!=s.end()-4;i++){
		if(*i=='a'&&*(i+1)=='p'&&*(i+2)=='p'&&*(i+3)=='l'&&*(i+4)=='e'){
			*i='p';
			*(i+1)='e';
			*(i+2)='a';
			*(i+3)='c';
			*(i+4)='h';
		}
		else if(*i=='p'&&*(i+1)=='e'&&*(i+2)=='a'&&*(i+3)=='c'&&*(i+4)=='h'){
			*i='a';
			*(i+1)='p';
			*(i+2)='p';
			*(i+3)='l';
			*(i+4)='e';
		}
	}
	cout<<s<<endl;
}

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

struct UnionFind{
    vector<long long> root;
    vector<long long> sizes;
    UnionFind(long long n): root(n + 1), sizes(n + 1,1){
        for(long long i = 0; i <= n; i++) root[i] = i;
    }
    long long find(long long x){
        if(x == root[x]) return x;
        return root[x] = find(root[x]);
    }
    void unite(long long x, long long y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x,y);
        root[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(long long x, long long y){
        return find(x) == find(y);
    }
};

int main(){
    long long n, q;
    cin >> n >> q;
    UnionFind uf(n);
    bool c;
    long long x,y;
    for(long long i=1; i<=q; i++){
        cin >> c >> x >> y;
        if(c==0){
            uf.unite(x,y);
        }else{
            cout << uf.same(x,y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3252
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll r=(n-1)/2;
    cout<<r<<endl;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}


void solve(){
  string s;
  cin >> s;
  int i = 1;
  bool res = true;
  for(char t : s){
    if(i % 2 == 0 && t == 'R'){
      res = false;
      break;
    }else if(i % 2 == 1 && t == 'L'){
      res = false;
      break;
    }
    i++;
  }
  if(res){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{   int y,n;
    scanf("%d%d",&n,&y);
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if((y-i*10000-j*5000)/1000==n-i-j&&y-i*10000-j*5000>=0){
                printf("%d %d %d",i,j,n-i-j);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");

    return 0;
}


Measured memory_bytes: 128
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		long sum = 0;
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		for(int i=0;i<n/2;i++) {
			sum = sum - a[i*2+1]*2;
		}
		int sum2 = (int)sum;
		int tmp = (int)sum;
		for(int i=0;i<n;i++) {
			System.out.print(sum2 + " ");
			sum2 = a[i]*2 - tmp;
			tmp = sum2;
		}
	}
}

Measured memory_bytes: 62052
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <ctype.h>

char buf[100001];
int buf2[100001];
int buf3[100001];

int main(void)
{
  char s[1000];
  int n,i,j,l,r,c,x;
  fgets(s,1000,stdin);
  sscanf(s,"%d",&n);
  memset(buf,0,sizeof(buf));
  memset(buf2,0,sizeof(buf2));
  memset(buf3,0,sizeof(buf3));
  for(i=3;i<=317;i+=2){
    if(buf[i]==1) continue;
    for(j=3*i;j<100001;j+=i*2){
      buf[j]= 1;
    }
  }
  
  buf2[3] = 1;
  buf2[1] = 0;
  
  int last_cnt=1;
  for(i=5;i<=100000;i+=2){
    buf2[i] = buf3[i] = last_cnt;
    x = (i+1)/2;
    if( (x&1)==1 ){
      if( buf[i] == 0 && buf[x]==0 ){
        last_cnt ++ ;
        buf2[i] = last_cnt;
      }
    }
  }
  
  for(i=0;i<n;i++){
    fgets(s,1000,stdin);
    sscanf(s,"%d %d",&l,&r);
    printf("%d\n",buf2[r] - buf3[l]);
  }
  return EXIT_SUCCESS; 
}



Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#define MAX 11
using namespace std;
bool o;
void rec(string s){
  if(!o) return;
  //cout << s << endl;
  while(1){
    bool f=false;
    int p;
    for(p=0;p<s.size();p++){
      f=false;
      //cout << s << endl;
      //if(s[p]==' ') continue;
      if(s[p]=='-'){
	
	if(s[p+1]=='0'){
	  s[p]='1';
	  s[p+1]=' ';
	  f=true;
	}
	
	if(s[p+1]=='1'){
	  s[p]='0';
	  s[p+1]=' ';
	  f=true;
	}
      }
      else if(s[p]=='('){
	if(s[p+1]!='0'&&s[p+1]!='1') continue;
	if(s[p+4]==')'){
	  if(s[p+2]=='+'){
	    if(s[p+1]=='0'&&s[p+3]=='0'){
	      s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	    if(s[p+1]=='1'&&s[p+3]=='0'){
	      s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	    if(s[p+1]=='0'&&s[p+3]=='1'){
	      s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	    if(s[p+1]=='1'&&s[p+3]=='1'){
	      s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	  }
	  if(s[p+2]=='*'){
	    if(s[p+1]=='0'&&s[p+3]=='0'){
	      s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	    if(s[p+1]=='1'&&s[p+3]=='0'){
	      s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	    if(s[p+1]=='0'&&s[p+3]=='1'){
	      s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	    if(s[p+1]=='1'&&s[p+3]=='1'){
	      s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
	    }
	  }
	  f=true;
	}else if(s[p+5]==')'&&s[p+2]=='-'&&s[p+3]=='>'){
	  if(s[p+1]=='0'&&s[p+4]=='0'){
	    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
	  }
	  if(s[p+1]=='1'&&s[p+4]=='0'){
	    s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
	  }
	  if(s[p+1]=='0'&&s[p+4]=='1'){
	    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
	  }
	  if(s[p+1]=='1'&&s[p+4]=='1'){
	    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
	  }
	  f=true;
	}
      }
      if(f){
	string b;
	for(int i=0;i<s.size();i++) if(s[i]!=' ') b+=s[i];
	s=b;
	p=-1;
      }
    }
    if(s[0]!=s[2]) o=false;
    return;
  }
}
bool fi;
vector<int> v[11];
void init(int n,string s){
  int i,j;
  if(fi){
    for(j=0;j<MAX;j++) v[j].clear();
    for(i=0;i<s.size();i++){
      for(j=0;j<MAX;j++){
	if(s[i]=='a'+j) {
	  s[i]='0'+(n>>j&1);
	  v[j].push_back(i);
	}
      }
    }
    fi=false;
  }else{
    for(i=0;i<MAX;i++){
      for(j=0;j<v[i].size();j++){
	s[v[i][j]]='0'+(n>>i&1);
      }
    }
  }
  //cout << s << endl;
  rec(s);
  if(!o) return;
}
int main(){
  string s;
  while(cin >> s,s!="#"){
    o=true;
    int i;
    fi=true;
    for(i=0;i<s.size();i++){
      if(s[i]=='T') s[i]='1';
      if(s[i]=='F') s[i]='0';
    }
    for(i=0;i<(1<<MAX);i++)
      if(o) init(i,s);
      else break;
    cout << (o?"YES":"NO") << endl;
  }
  return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a*n, b) << endl;

    return 0;
}

Measured memory_bytes: 3580
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ======================================================================
    public void solve() {
    	int N = ni();
    	int K = ni();
    	int ans = 1;
    	while(N >= K) {
			N = N / K;
			ans++;
//			out.println(" N = " + N + " ans = " + ans);
		}
    	out.println(ans);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 23252
class Integer
  def month?;
    1 <= self && self <= 12
  end
end

s = gets.to_s.to_i

t = s / 100
u = s % 100

if t.month? && u.month?
  puts "AMBIGUOUS"
elsif u.month?
  puts "YYMM"
elsif t.month?
  puts "MMYY"
else
  puts "NA"
end

Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int k[10005];
int i=0,a;
    while(scanf("%d",&a)==1)
{
k[i]=a;
i++;
}
sort(k,k+i+1);
printf("%d\n%d\n%d\n",k[i],k[i-1],k[i-2]);
return 0;
}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
 
#define TRACE(x) cerr << #x << " = " << x << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define SZ(x) (int)(x).size()
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
 
template<class Num>
Num mabs(Num A){
  if(A < 0) return -A;
  return A;
}

const int N = 2e5 + 10;

int n, q;
int lef_col[N];
int lef_row[N];

int main(){
  scanf("%d %d", &n, &q);
  
  ll ans = (ll)(n - 2) * (ll)(n - 2);
  for(int i = 1; i <= n; i++){
    lef_col[i] = lef_row[i] = n;
  }
  
  int W = n, H = n;
  
  while(q--){
    int f, x; scanf("%d %d", &f, &x);
    if(f == 1){
      if(x < W){
        for(int i = x; i < W; i++)
          lef_col[i] = H;
        W = x;
      }
      
      ans -= (ll)(lef_col[x] - 2);
    }
    else{
      if(H > x){
        for(int i = x; i < H; i++){
          lef_row[i] = W;
        }
        H = x;
      }
      
      ans -= (ll)(lef_row[x] - 2);    
    }
  } 
  
  printf("%lld\n", ans);
  
  return 0;
}


Measured memory_bytes: 5244
#include<stdio.h>
int main(void){
    int a,b,i,n;
    while(1){
        scanf("%d %d",&a,&b);
        if(a==0 && b==0)break;
        for(i=0;i<a;i++){
            for(n=0;n<b;n++){
                printf("#");
                }
            printf("\n");
            }
        printf("\n");
        }
    return 0;
}


Measured memory_bytes: 2040