akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef pair<int, pair<int, int>> PII;
typedef pair<ll, pair<ll, ll>> PLL;
#define endl '\n'
#define INF 2e9
#define LINF 2e15
#define MOD 1000000007

int n, x, t, ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin >> n >> x >> t;
	while (n) {
		n -= x;
		ans += t;
		if (n < 0)n = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind G(n), B(2*n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        G.unite(a, b);
        B.unite(a, b+n);
        B.unite(a+n, b);
    }
    ll a = 0, b = 0, c = 0;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        if(G.root(i) == i){
            if(G.size(i) == 1) c++;
            else if(B.same(i, i+n)) b++;
            else a++;
        }
    }
    for (int i = 0; i < n; ++i) {
        if(G.root(i) == i){
            if(G.size(i) == 1) {
                ans += n;
            }else if(B.same(i, i+n)){
                ans += c*G.size(i)+a+b;
            }else {
                ans += c*G.size(i)+2*a+b;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int cnta[200005];
int cntb[200005];
int a[200005];
int b[200005];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        cin >> a[i];
        cnta[a[i]] ++;
    }
    rep(i,n){
        cin >> b[i];
        cntb[b[i]] ++;
    }
    
    bool ok = true;
    rep(i,200005){
        if(cnta[i]+cntb[i]>n) ok = false;
    }

    if(!ok){
        cout << "No" << endl;
        return 0;
    }
    priority_queue<pll> pq;

    rep(i,200005){
        if(cntb[i]>0) pq.push(pll{i,cntb[i]});
    }
    vector<int> c(n);

    int id = 0;
    rep(i,n){
        if(a[i]!=pq.top().first){
            c[i] = pq.top().first;
            pll now = pq.top();
            pq.pop();
            now.second --;
            if(now.second==0) continue;
            else pq.push(now);
        }else{
            pll before = pq.top();
            pq.pop();

            if(!pq.empty()){
                c[i] = pq.top().first;
                pll now = pq.top();
                pq.pop();
                now.second --;
                if(now.second==0);
                else pq.push(now);
            }else{
                ok = false;
                id = i;
                pq.push(before);
                break;
            }

            pq.push(before);
        }
    }

    if(!ok){
        vector<int> idx;
        for(int i=id;i<n;i++){
            if(a[i]==pq.top().first) idx.push_back(i);
            c[i] = pq.top().first;
        }
        int p = 0;
        for(int i=0;i<id;i++){
            if(a[i]==pq.top().first) continue;
            if(c[i]==pq.top().first) continue;

            swap(c[i],c[idx[p]]);
            ++p;
            if(p==(int)idx.size()) break;
        }
    }

    cout << "Yes" << endl;
    rep(i,n){
        cout << c[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 10404
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,k;

int main() {
    cin >> n >> k;
    vector<int> x(n);
    vector<int> a;
    vector<int> b;
    REP(i,n){
        cin >> x[i];
    }
    //a.push_back(0);
    //b.push_back(0);
    REP(i,n){
        if(x[i]<0){
            a.push_back(x[i]);
        }else{
            b.push_back(x[i]);
        }
    }
    reverse(a.begin(), a.end());
    /*vector<int> sa(a.size()+1);
    vector<int> sb(b.size()+1);
    sb[0] = 0;
    REP(i,sa.size()){
        sb[i+1] = sb[i]+b[i+1];
    }
    sa[0] = 0;
    REP(i,sa.size()){
        sa[i+1] = sa[i]+a[a.size()-1-i];
    }
    REP(i,sa.size()){
        put(sa[i]);
    }*/
    int res = INT_MAX;
    if(!a.size()){
        res = b[k-1];
    }else if(!b.size()){
        res = -1*a[k-1];
    }else{
        REP(i,n){
            if(i<a.size()&&(k-i-2)<b.size()){
                res = min(res,-1*a[i]*2+b[k-i-2]);
                res = min(res,-1*a[i]+b[k-i-2]*2);
            }
        }
    }
    put(res);
    /*s[0] = 0;
    REP(i,n){
        s[i+1] = s[i]+x[i+1];
    }
    int res = INT_MAX;
    REP(i,n-k+1){
        int mi = s[k+i]-s[i];
        res = min(res,mi);
    }
    put(res);*/
    return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 


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

int N, M; cin >> N >> M;
VVI G(N+1);
rep(i, 0, M){
    int x, y, z; cin >> x >> y >>  z;
    G[x].push_back(y);
    G[y].push_back(x);
}

int magic = 0;
vector<bool> seen(N+1, false);
rep(i, 1, N+1){
    if (seen[i]) continue;
    ++magic;
    stack<int> st;
    st.push(i); 
    while (!st.empty()) {
        int v = st.top(); 
        st.pop();
        for (int nv : G[v]) {
            if (seen[nv]) continue;
            seen[nv] = true;
            st.push(nv);
        }
    }   
}
cout << magic << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 6900
#include <iostream>
using namespace std;
 
int main(){
	const int NUM = 2000000;
	char S[NUM],T[NUM];
	cin >> S >> T;
	int a = 0;
	for(int i = 0; S[i] != '\0'; i++){
		if(S[i] != T[i]){
			a = a + 1;
        }
    }
  	cout << a;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Zp {
	const int p = 998244353;
	ll r;
	void set(ll x) {
		while (x < 0) x += p;
		r = x % p;
	}

public:
	Zp(ll x) { set(x); }
	Zp() { set(0); }

	Zp operator-() const { return Zp(-r); }
	Zp &operator=(ll y) {
		set(y);
		return *this;
	}
	Zp &operator=(const Zp &y) { return *this = y.r; }

	Zp &operator+=(ll y) {
		set(r + y);
		return *this;
	}
	Zp &operator-=(ll y) { return *this += -y; }
	Zp &operator*=(ll y) {
		set(r * y);
		return *this;
	}
	Zp &operator/=(ll y) { return *this *= inv(y); }
	Zp operator+(ll y) const { return Zp(r + y); }
	Zp operator-(ll y) const { return *this + (-y); }
	Zp operator*(ll y) const { return Zp(r * y); }
	Zp operator/(ll y) const { return *this * inv(y); }

	Zp &operator+=(const Zp &y) { return *this += y.r; }
	Zp &operator-=(const Zp &y) { return *this -= y.r; }
	Zp &operator*=(const Zp &y) { return *this *= y.r; }
	Zp &operator/=(const Zp &y) { return *this /= y.r; }
	Zp operator+(const Zp &y) const { return *this + y.r; }
	Zp operator-(const Zp &y) const { return *this - y.r; }
	Zp operator*(const Zp &y) const { return *this * y.r; }
	Zp operator/(const Zp &y) const { return *this / y.r; }

	Zp pow(int n) const {
		if (n == 0) return 1;
		if (n % 2) return *this * pow(n - 1);
		Zp tmp = pow(n / 2);
		return tmp * tmp;
	}
	Zp inv(int x) const { return Zp(x).pow(p - 2); }
	Zp inv() const { return inv(r); }

	ll get() const { return r; }

	friend istream &operator>>(istream &istr, Zp &x) {
		istr >> x.r;
		x.set(x.r);
		return istr;
	}
	friend ostream &operator<<(ostream &ostr, const Zp &x) {
		ostr << x.r;
		return ostr;
	}
};
class Comb {
	vector<Zp> fact, ifact;

public:
	Comb(int N) : fact(N + 1), ifact(N + 1) {
		fact[0] = 1;
		REP(i, N)
		fact[i + 1] = fact[i] * (i + 1);
		ifact[N] = fact[N].inv();
		REPR(i, N)
		ifact[i] = ifact[i + 1] * (i + 1);
	}
	Zp operator()(int n, int k) const {
		return fact[n] * ifact[n - k] * ifact[k];
	}
	Zp f(int k) const { return fact[k]; }
	Zp invf(int k) const { return ifact[k]; }
};

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

	int N, K;
	Zp M;
	cin >> N >> M >> K;
	Comb comb(N);
	Zp res = 0;
	REP(i, K + 1) {
		Zp p = comb(N - 1, i);
		res += M * (M - 1).pow(N - 1 - i) * p;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 9528
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] d = new int[n];
		for(int i=0; i<n; i++){
			d[i] = scn.nextInt();
		}
      	int sum = 0;
      	for(int i=0; i<n-1; i++){
          for(int j=i+1; j<n; j++){
            sum += d[i]*d[j];
          }
        }
      	System.out.println(sum);
	}
}


Measured memory_bytes: 35572
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

// a と b の最大公約数を返す
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    // 再帰的に解く (x, y を入れ替えておく)
    ll d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

/**
 * ax + by = gcd(a, b)を満たすx, yを求める
 * @param a
 * @param b
 * @return P_res(gcd(a, b), P(x, y))
 */
pair<ll, pair<ll, ll>> extGCD(ll a, ll b){
    using P_xy = pair<ll, ll>;
    using P_res = pair<ll, pair<ll, ll>>;

    ll x, y;
    ll d = extGCD(a, b, x, y);
    P_res res = P_res(d, P_xy(x, y));
    return res;
}


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



// 素数判定
bool is_prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}


// 約数列挙
vector<ll> enum_divisors(ll N) {
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            if (N/i != i) res.push_back(N/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}


// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll N){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= N; i++){
        if(N % i != 0)  continue;
        ll ex = 0;

        while(N % i == 0){
            ex++;
            N /= i;
        }

        res.push_back({i, ex});
    }

    if(N != 1)  res.push_back({N, 1});
    return res;
};



int main(){
    ll a, b, c; cin >> a >> b >> c;
    if(c % gcd(a, b) == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

typedef ll Weight;
struct Edge {
  ll src, dst;
  Weight weight;
  Edge(ll src, ll dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
             e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  bool ok = true;
  cin >> N;
  vvl A = VVL(N, N, 0);
  vvl B = VVL(N, N, llINF);
  REP(i, N) REP(j, N) {
    cin >> A[i][j];
    if (i == j && A[i][j] != 0)
      ok = false;
  }
  ll ans = 0;
  // あるかチェック
  REP(k, N) REP(i, N) REP(j, N) {
    if (A[i][j] > A[i][k] + A[k][j]) {
      A[i][j] = A[i][k] + A[k][j];
      ok = false;
      break;
    } else if (i != k && j != k && B[i][j] > A[i][k] + A[k][j]) {
      B[i][j] = A[i][k] + A[k][j];
    }
  }
  REP(i, N) REP(j, N) {
    if (i != j && A[i][j] != B[i][j])
      ans += A[i][j];
  }

  if (ok)
    cout << ans / 2 << endl;
  else
    cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  vi A;
  A.pb(K);
  bitset<60> b(K);
  rep(i,1,60){
    if(b.test(i)){
      int X=K|((1ll<<i)-1);
      X-=(1ll<<i);
      A.pb(X);
    }
  }
  int M=A.size();
  vi B(M);
  rep(i,0,N){
    int X,Y; cin>>X>>Y;
    rep(j,0,M){
      if((A[j]|X)==A[j]) B[j]+=Y;
    }
  }
  int ans=0;
  rep(i,0,M) ans=max(ans,B[i]);
  cout<<ans<<endl;
  }


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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)
#define c2i(c) {i-48;}
#define i2c(n) {n+48;}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

string next3(string s){
    int tmp=1;
    forN(i,s.size()&&tmp==1){
        s[i]+=tmp;
        if(s[i]>'2') s[i]='0';
        else if(s[i]<='2') tmp=0;
    }
    if(tmp==1) s.push_back('0');
    return s;
}
bool is753(string s){
    int tmp=0;
    forN(i,s.size()){
        tmp|=(1<<(s[i]-48));
    }
    return tmp==7;
}
string d2t753(int n){
    char data[]="0001122333";
    char dt[]="00010101000";
    int log10n = log10(n)+1;
    string s(log10n,'0');
    int t=0;
    forN(i,log10n){
        int tmp=n/(int)pow(10,i)%10;
        if(tmp==0) t++;
        else{
            for(;t>0&&dt[tmp]=='0';t--){
                n-=(int)pow(10,t-1);
            }
            break;
        }
    }
    forN(i,log10n){
        s[i]=data[n/(int)pow(10,i)%10];
    }
    forN(i,log10n-1){
        if(s[i]<='0'){
            s[i+1]--;
            s[i]='2';
        }else s[i]--;
    }
    s[s.size()-1]--;
    return s;
}
bool leftBig(string a,string b){
    if(a.size()>b.size()) return true;
    else if(a.size()<b.size()) return false;
    else{
        reverse(b.begin(),b.end());
        if(a.compare(b)>=0) return true;
        else return false;
    }
}

int main(){
    int m,n,cnt=0;
    string s;

    vector<string> db,db2;
    cin>>n;
    string res=d2t753(n);
    reverse(res.begin(),res.end());
    string i = "210";
    if(!leftBig(res,i)){
        cout<<0<<endl;
    }else{
        do{
            db2.push_back(i);
            if(is753(i)) { cnt++; db.push_back(i); }
        }while(leftBig(res,i=next3(i)));
        cout << cnt << endl;
    }
}


Measured memory_bytes: 5732
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    // int t;
    // cin>>t;
    // while(t--){
        int n;
        cin>>n;
        int a,b;
        int count=0;
        bool flg=0;
        fo(i,0,n){
            cin>>a>>b;
            if(a==b){
                count++;
            }
            else{
                count=0;
            }
            if(count==3){
                flg=1;
            }
        }

        if(flg){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }


    // }
    return 0;
}

Measured memory_bytes: 3632
n=int(input())
perm=[list(range(1,n+1))]
fact=1
from copy import copy
for i in range(1,n+1):
  fact*=i 
for i in range(1,fact):
  cur=perm[-1].copy()
  for j in range(n-1,-1,-1):
    if cur[j]<max(cur[j:]):
      aux=cur[j:].copy()
      aux.sort()
      for k in range(len(aux)):
        if aux[k]>cur[j]:
          cur[j]=aux[k]
          aux.remove(aux[k])
          break
      cur[j+1:]=aux
      break
  perm.append(cur)
x=input().split()
y=input().split()
p=[]
q=[]
for k in range(n):
  p.append(int(x[k]))
  q.append(int(y[k]))

a=[]
for i in range(fact):
  if perm[i] in [p,q]:
    a.append(i)
if len(a)==1:
  print(0)
else:
  print(abs(a[0]-a[1]))
  
    

Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,t;cin>>n>>t;
  ll a[n];
  for(ll i=0;i<n;i++)cin>>a[i];
  ll sam=0;
  ll kam=0;
  map<ll,ll>mp;
  for(ll i=n-1;i>=0;i--){
    if(a[i]>kam){
      kam=a[i];
      continue;
    }
    mp[kam-a[i]]++;
    sam=max(sam,kam-a[i]);
  }
  cout<<mp[sam]<<endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

namespace std {
	#define u(x, a, b) for(ll x = a; x < b; x++)
	#define d(x, a, b) for(ll x = a; x > b; x--)
}

typedef long long ll;
typedef long double ld;

#define MAXI 100010
#define MOD 1000000007

ll modpow(ll a, ll b){
    if(b == 0){
        return 1;
    }
    else if(b%2 == 1){
        b--;
        b/=2;
        ll x = modpow(a, b);
        x = x*x;
        x = x%MOD;
        x = x*a;
        x = x%MOD;
        return x;
    }
    else{
        ll x = modpow(a, b/2);
        x = x*x;
        x = x%MOD;
        return x;
    }
}

int main(){
	ll k;
	string s;
	
	cin >> k >> s;
	ll sz = s.size();
	
	ll ans = 0;
	
	sz+=k;
	
	ll fact[sz+1];
	ll inv[sz+1];
	fact[1] = 1;
	inv[1] = 1;
	fact[0] = 1;
	inv[0] = 1;
	u(one, 2, sz+1){fact[one] = fact[one-1]*one; fact[one]%=MOD; inv[one] = modpow(fact[one], MOD-2);}
	
	sz-=k;
	
	u(one, 0, k+1){
		//calculating value of dp[sz-1+one];
		
		//need to find (sz+one) choose (sz);
		
		//multiply by 25^one
		
		//and 26^k-one
		ll x = fact[sz+one-1];
		x*=inv[sz-1];
		x%=MOD;
		x*=inv[one];
		x%=MOD;
		x*=modpow(25, one);
		x%=MOD;
		x*=modpow(26, k-one);
		x%=MOD;
		
		ans += x;
		ans%=MOD;
	}
	
	cout << ans;
}


Measured memory_bytes: 35516
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>

using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

using namespace std;

// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> void inputVec(std::vector<T>& vec) {
	for (typename std::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

void Main() {
	const int N = inputVal<int>();
	std::vector<int> vec(N);
	inputVec(vec);

	std::vector<size_t> indices(N);
	std::iota(indices.begin(), indices.end(), 0);

	std::sort(indices.begin(), indices.end(), [&vec](size_t i1, size_t i2) {
		return vec[i1] < vec[i2];
	});

	for (int i = 0; i < N; ++i) {
		++indices[i];
	}
	outputVec(indices);

}

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

	return 0;
}


Measured memory_bytes: 2048
#include <cstdio>
#include <algorithm>
#include <iostream>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
using namespace std;

int d, n;
int dp[200][200];
int t[200], a[200], b[200], c[200];

int sa(int x, int y){
	if(x > y) return x-y;
	else return y-x;
}

int main(){
	scanf("%d%d", &d, &n);
	rep(i,d) scanf("%d", &t[i]);
	rep(i,n) scanf("%d%d%d", &a[i], &b[i], &c[i]);
	for(int i = 0; i < n; i++){
		if(a[i] > t[0] || t[0] > b[i]) dp[0][i] = -1*INF;
	}
	for(int i = 1; i < d; i++){
		for(int j = 0; j < n; j++){
			if(a[j] <= t[i] && t[i] <= b[j]){
				for(int k = 0; k < n; k++){
					dp[i][j] = max(dp[i][j],dp[i-1][k]+sa(c[k],c[j]));
				}
			} else{
				dp[i][j] = -1*INF;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans = max(ans,dp[d-1][i]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1348
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>

using namespace std;

int main() {
    int n;

    scanf("%d", &n);

    vector<int> a(n);

    multiset<int> s;

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

        if (s.empty()) {
            s.insert(a[i]);
        } else {
            auto it = s.lower_bound(a[i]);

            if (it == s.begin()) {
                s.insert(a[i]);
            } else {
                it--;
                s.erase(it);
                s.insert(a[i]);
            }
        }
    }

    printf("%d\n", s.size());

    return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) (v.begin(),v.end())
#define ll long long
const int N=35;
const int inf=2e9;

map<long long,int>p;
int main(){
    ios::sync_with_stdio(0);
    int n;
    ll sum=0,ans=0;
    p[sum]=1;
    cin>>n;
    rep(i,0,n){
        int t;
        cin>>t;
        sum+=t;
        if(p[sum]){
            ans+=p[sum];
        }
        ++p[sum];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 12800
n = int(input())
nums0 = list(map(int, input().split()))
nums1 = list(map(int, input().split()))

acc0 = [nums0[0]]
acc1 = [nums1[-1]]
for i in range(1, n):
    acc0.append(acc0[-1] + nums0[i])
    acc1.append(acc1[-1] + nums1[n - i - 1])
acc1 = acc1[::-1]

counts = []
for i in range(n):
    counts.append(acc0[i] + acc1[i])
print(max(counts))

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    string s;
    cin >> s;
    if(s == "keyence"){
        print("YES");
        return 0;
    }
    rep(i, s.size() - 1){
        for(int j = i + 1; j < s.size(); j++){
            string temp;
            temp = s;
            temp.erase(temp.begin() + i, temp.begin() + j);
            if(temp == "keyence"){
                print("YES");
                return 0;
            }
        }
    }
    print("NO");
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    vector<vector<int>> is(26);
    rep(i, n) is[s[i] - 'a'].push_back(i);
    rep(i, n) is[s[i] - 'a'].push_back(i + n);

    ll ans = 0;
    int p = 0;

    rep(i, m)
    {
        int c = t[i] - 'a';
        if (is[c].size() == 0)
        {
            OP("-1");
            return 0;
        }

        p = *lower_bound(ALL(is[c]), p) + 1;
        if (p >= n)
        {
            p -= n;
            ans += n;
        }
    }
    ans += p;
    OP(ans);

    return 0;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,i;
    cin>>a>>b;
    int a1[7]= {1,3,5,7,8,10,12},a2[4]= {4,6,9,11};

    for(i=0; i<4; i++)
    {
        if(a2[i]==a)
            c++;
        if(a2[i]==b)
            c++;
    }
    if(a==2||b==2)
        c=1;
    if(c==0||c==2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w;
    scan(h, w);
    auto field = new string[](h);
    foreach (ref e; field)
        e = sread();

    auto box = new long[][](h, w);
    auto x_move = [-1, 0, 1];
    auto y_move = [-1, 0, 1];
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            foreach (k; y_move)
            {
                if (i + k < 0 || i + k >= h)
                    continue;

                foreach (l; x_move)
                {
                    if (j + l < 0 || j + l >= w)
                        continue;

                    // writefln("%s %s, %s %s", i, j, k, l);
                    box[i][j] += (field[i + k][j + l] == '#').to!long;
                }
            }
        }
    }
    foreach (i, e; field)
    {
        foreach (j, f; e)
        {
            if (f == '#')
                write("#");
            else
                write(box[i][j]);
        }
        writeln();
    }

}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2720
#include <iostream>
using namespace std;
 
int main() {

  int n,a,b,c,d;
  cin >> n;

  a = n % 10;
  n /= 10;
  b = n % 10;
  n /= 10;
  c = n % 10;
  n /= 10;
  d = n;

  if(a==b&&b==c) cout << "Yes";
  else if (b==c&&c==d) cout << "Yes";
  else cout << "No";

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <cmath>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

bool cal(vector<int> &da, int k, int now){
    int co=now,gg=1;
    rip(i,da.size(),0){
        if(now<da[i]){
            return false;
        }
        if(co>=da[i]){
            co-=da[i];
        }else{
            gg++;
            co=now-da[i];
        }
    }
    return gg<=k;
}

int bia_search(int k,vector<int> &da,int r,int l){
    if(r-l==1){
        return r;
    }
    int mi = (r + l) >> 1;
    if(cal(da,k,mi)){
        bia_search(k,da,mi,l);
    }else{
        bia_search(k,da,r,mi);
    }
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> w(n);
    rip(i,n,0){
        cin >> w[i];
    }
    cout << bia_search(k,w,1000000001,0) << endl;
}



Measured memory_bytes: 3108
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    ll N, ans=2; cin>>N;
    if(N==2){
        cout<<1<<endl;
        return 0;
    }
    ll M=(ll)sqrt(N);
    FOR(i,2,M+1){
        if(N%i!=0) continue;
        ll res=N;
        while(res%(ll)i==0) res/=(ll)i;
        if((res-1)%(ll)i==0) ans++;
    }
    M=(ll) sqrt(N-1);
    FOR(i,2,M+1){
        if((N-1)%(ll)i==0){
            ans+=2;
            if((ll)i*(ll)i==N-1) ans--;
        }
    }
    cout<<ans<<endl;
}

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

int dp[200001];
int a[100];
int n;
int k;
int level = 100000;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        level = min(a[i], level);
    }
    for (int i = 0; i < 200001; i++)
    {
        dp[i] = -1;
    }

    for (int i = 0; i < level; i++)
        dp[i] = 0;

    for (int i = 0; i <= k; i++)
    {
        if (dp[i] == 0)
        {
            for (int j = 0; j < n; j++)
                dp[i + a[j]] = 1;
        }
        else if (dp[i] == -1)
        {
            int temp = 1;
            for (int j = 0; j < n; j++)
            {
                if (a[j] <= i)
                    temp &= dp[i - a[j]];
            }
            if (temp)
                dp[i] = 0;
            else
                dp[i] = 1;
            i--;
        }
    }
    if (dp[k])
        cout << "First" << endl;
    else
        cout << "Second" << endl;

    return 0;
}


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

ll mod = 998244353;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

int main(){
    ll N;
    string S;
    cin >> S;
    N = S.size();
    vector<ll> blue(N+1, 0), red(N+1, 0);
    for (int i = 1; i <= N; i++) {
        blue[i] = blue[i-1] + (S[i-1] - '0');
        red[i] = 2*i - blue[i];
    }
    
    vector<ll> fact(2*N+1, 1), invfact(2*N+1, 1);
    for (int i = 2; i <= 2*N; i++) fact[i] = fact[i-1]*i%mod;
    invfact[2*N] = modinv(fact[2*N]);
    for (int i = 2*N-1; i >= 2; i--) invfact[i] = invfact[i+1]*(i+1)%mod;
    
    vector<vector<ll>> dp(N+1, vector<ll>(N+1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= i-1; j++) {
            if (blue[i] >= j+1) dp[i][j+1] = (dp[i][j+1]+dp[i-1][j])%mod;
            if (red[i] >= i-j) dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
        }
    }
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        if (i > blue[N] || N-i > red[N]) continue;
        ll c = fact[N] * invfact[blue[N]-i] % mod * invfact[N - blue[N] + i] % mod;
        ans = (ans + dp[N][i] * c %mod)%mod;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	int s;
  	cin>>s;
  
	int mae=s/100;
    int usiro=s%100;
  
  	bool mmyy=true;
  	bool yymm=true;
  
  if(mae<1||12<mae){
  	mmyy=false;
  }
  
  if(usiro<1||12<usiro){
  	yymm=false;
  }
  


if(yymm&&mmyy){cout<<"AMBIGUOUS"<<endl;}
else if(yymm){cout<<"YYMM"<<endl;}
else if(mmyy){cout<<"MMYY"<<endl;}
else {cout<<"NA"<<endl;}
}

Measured memory_bytes: 3636
var
s,t,u:string;
a,b:longint;
begin
readln(s);
if pos('+',s)>0 then
begin
t:=copy(s,1,pos('+',s)-2);
u:=copy(s,pos('+',s)+2,length(s)-pos('+',s)-1);
val(t,a);
val(u,b);
writeln(a+b);
end;
if pos('-',s)>0 then
begin
t:=copy(s,1,pos('-',s)-2);
u:=copy(s,pos('-',s)+2,length(s)-pos('-',s)-1);
val(t,a);
val(u,b);
writeln(a-b);
end;
end.


Measured memory_bytes: 128
N,K = gets.split.map &:to_i
as = gets.split.map &:to_i
surp=Array.new(N,0)
surp_re=Array.new(N,0)

(0..N-1).to_a.repeated_permutation(2) do |i,j|
    surp[i]+=1 if as[i]>as[j]
    surp_re[i]+=1 if as[i]>as[j] && i<j
end
puts (0..N-1).to_a.map{|i|surp_re[i]*K+surp[i]*(K*(K-1)/2)}.inject(:+) % 1000000007


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  long long a[n+1],b[n];
  for(int i=0;i<n+1;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  
  long long ans=0;
  for(int i=0;i<n;i++){
    if(i==0){
      if(a[0]<=b[0]){
      ans+=a[0];
      b[0]-=a[0];
      }
      else{
      ans+=b[0];
      b[0]=0;
      }
    }
    
    else{
      if(a[i]>=b[i]+b[i-1]){
        ans=ans+b[i]+b[i-1];
        b[i]=0;
      }
      else if(a[i]<b[i-1]){
        ans+=a[i];
      }
      else{
        ans+=a[i];
        b[i]-=(a[i]-b[i-1]);
      }
    }
    
  }
  cout<<ans+min(a[n],b[n-1])<<endl;
 
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"5 7 5
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main() {
	vector<PP> A[16];
	cin >> n;
	rep(i, n) {
		cin >> x;
		rep(j, x) {
			cin >> a >> b;
			A[i].push_back({ a-1,b });
		}
	}
	a = 1 << n;
	rep(i, a) {
		vl B(n, 0);
		t = 0;
		rep(j, n) {
			if (((1 << j) & i) > 0) {
				B[j] = 1;
				t++;
			}
		}

		rep(j, n) {
			for (PP k : A[j]) {
				x = k.first;
				y = k.second;
				if (B[j] == 1 && B[x] != y)goto next;
			}
		}
		//cout << i << " " << t << endl;
		ans = max(ans, t);
	next:
		q = 1;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    print(180*(N-2))

if __name__ == '__main__':
    main()


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

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

  int ans=0;
  if (2*c < (a+b) )
  {
    if ( x>y)
    {
        ans=y*2*c+(x-y)*a;
    }
    else
    {
        ans=x*2*c+(y-x)*b;
    }
  }
  
  else
  {
      ans=a*x+b*y;
  }
  
  if (x>y)
  {
      int temp=x*c*2;
      if (temp<ans) ans=temp;
  }
  else
  {
      int temp=y*c*2;
      if (temp<ans) ans=temp;
  }
  
  cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}



vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  
  return prime;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int q;
  cin>>q;
  int s[110000]={};
  vector<bool> prime = prime_table(110000);
  
  
  rep(i,110000){
    if(prime[i]&&prime[(i+1)/2]) s[i]++;
  }

  rep(i,110000){
    if(i) s[i]+=s[i-1];
  }

  while(q--){
    int l,r;
    cin>>l>>r;
    //cout<<s[r]<<' '<<s[l-1]<<endl;
    cout<<s[r]-s[l-1]<<endl;
  }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> v(n);
  for (auto &e : v)
    cin >> e.first >> e.second;

  sort(v.begin(), v.end());

  ll itr = 0, ans = 0;
  for (ll i = 0; i < n; ++i)
  {
    itr += v[i].second;
    if (itr >= k)
    {
      ans = v[i].first;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

enum Direction {
  UP,
  DOWN,
  UNKNOWN
}

public class Main {
  private static int solve(int[] as) {
    int prev = as[0];
    int count = 1;
    Direction direction = Direction.UNKNOWN;
    for (int i = 1; i < as.length; i++) {
      if (as[i] > prev) {
        if (direction == Direction.DOWN) {
          count++;
          direction = Direction.UNKNOWN;
        } else {
          direction = Direction.UP;
        }
      } else if (as[i] < prev) {
        if (direction == Direction.UP) {
          count++;
          direction = Direction.UNKNOWN;
        } else {
          direction = Direction.DOWN;
        }
      }
      prev = as[i];
    }
    return count;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] as = reader.nextIntArray(n);
    out.println(solve(as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
}

class Algorithm {
  private static void swap(Object[] list, int a, int b) {
    Object tmp = list[a];
    list[a] = list[b];
    list[b] = tmp;
  }
  
  public static <T extends Comparable<? super T>> boolean nextPermutation(T[] ts) {
    int rightMostAscendingOrderIndex = ts.length - 2;
    while (rightMostAscendingOrderIndex >= 0 &&
        ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostAscendingOrderIndex + 1]) >= 0) {
      rightMostAscendingOrderIndex--;
    }
    if (rightMostAscendingOrderIndex < 0) {
      return false;
    }
    
    int rightMostGreatorIndex = ts.length - 1;
    while (ts[rightMostAscendingOrderIndex].compareTo(ts[rightMostGreatorIndex]) >= 0) {
      rightMostGreatorIndex--;
    }
    
    swap(ts, rightMostAscendingOrderIndex, rightMostGreatorIndex);
    for (int i = 0; i < (ts.length - rightMostAscendingOrderIndex - 1) / 2; i++) {
      swap(ts, rightMostAscendingOrderIndex + 1 + i, ts.length - 1 - i);
    }
    return true;
  }
}



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

	const int NN = 3001;
	int matrix[NN+1][NN+1];
	int visited[NN+1][NN+1];
	int arr[5002];
	int n,m;
	int dx[]={1,-1,0,0};
	int dy[]={0,0,-1,1};

	bool check(int x,int y){
		return x>=0 && y>=0 && x<n&& y<m;
	}

	int main() {

		#ifndef ONLINE_JUDGE
	        freopen("input.txt","r",stdin);
	        // freopen("output.txt","w",stdout);
	    #endif
	    ios::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);

	    cin>>n>>m;

	    int sx,sy,ex,ey;
	    cin>>sx>>sy>>ex>>ey;
	    sx--; sy--; ex--; ey--;
	    for(int i=0;i<n;i++){
	    	for(int j=0;j<m;j++){
	    		char x;
	    		cin>>x;
	    		matrix[i][j]=(x=='.');
	    	}
	    }

	    // 0-1 BFS
	    deque< pair<int,pair<int,int> > > q;
	    int cost=-1;
	    q.push_back({0,{sx,sy}});
	    while(!q.empty()){
	    	pair<int,pair<int,int> > cur=q.front();
	    	q.pop_front();

	    	int y=cur.second.second;
	    	int x=cur.second.first;
	    	int val=cur.first;
	    	if(visited[x][y]){
	    		continue;
	    	}
	    	if(y==ey && x== ex){
	    		// cout<<val<<endl;
	    		cost = val;
	    		break;
	    	}
	    	
	    	visited[x][y]=1;
	    	for(int i=0;i<4;i++){
	    		int vx=x+dx[i];
	    		int vy=y+dy[i];
	    		if( check(vx,vy) && matrix[vx][vy] && !visited[vx][vy]){
	    			q.push_front({val,{vx,vy}});
	    		}
	    	}

	    	for(int i=x-2;i<=x+2;i++){
	    		for(int j=y-2;j<=y+2;j++){
	    			if(check(i,j)&& matrix[i][j] &&!visited[i][j]){
	    				q.push_back({1+val,{i,j}});
	    			}
	    		}
	    	}
	    }
	    cout<<cost<<endl;


	   
	    
	    
	}



	


Measured memory_bytes: 19500
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int[] N = cin.ArrayInt(2,0);
        Console.WriteLine(N[0]*N[1]+" "+(N[0]+N[1])*2);
    }

}
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 15860