akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
typedef long long ll;

int main(){
    char s[10];
    scanf("%s",s);
    int ans=0;
    switch (s[0]) {
            case 'M':ans=6;break;
            case 'W':ans=4;break;
            case 'T':ans=3;break;
            case 'F':ans=2;break;
            case 'S':ans=1;break;
        default:break;
    }
    if(s[1]=='U'){
        if(ans==1)ans=7;
        else ans=5;
    }
    printf("%d",ans);
}




Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	long N;
	cin >> N;
	vector<pair<long long, long> >A(N);
	long long MIN = 9999999999;
	long ans = 0;
	for (long i = 0; i < N; i++) {
		cin >> A.at(i).first;
		if (MIN > A.at(i).first) {
			MIN = A.at(i).first;
			ans = i + 1;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 4376
#include<stdio.h>
int main(){
  int N;
  scanf("%d\n",&N);
  int d[N];
  int i;
  int c[101]={};
  for(i=0;i<N;i++){
    scanf("%d",&d[i]);
  }
  for(i=0;i<N;i++){
    c[d[i]]++;
  }
  int count=0;
  for(i=1;i<=100;i++){
    if(c[i]!=0){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	string s;
	cin>>s;
	s.at(5)=' ';
	s.at(13)=' ';
	ce(s)
}

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

int main() {
    int all = 0, right_angle = 0, acute = 0, obtuse = 0;
    while (true) {
        int a, b, c; cin >> a >> b >> c;

        if ( !(a + b > c && b + c > a && c + a > b) ) {
            cout << all         << " "
                 << right_angle << " "
                 << acute       << " "
                 << obtuse      << endl;
            break;
        }

        all++;
        if (pow(a,2) + pow(b,2) == pow(c,2) ||
            pow(b,2) + pow(c,2) == pow(a,2) ||
            pow(c,2) + pow(a,2) == pow(b,2)) right_angle++;
        else if (pow(a,2) + pow(b,2) > pow(c,2) &&
                 pow(b,2) + pow(c,2) > pow(a,2) &&
                 pow(c,2) + pow(a,2) > pow(b,2)) acute++;
        else obtuse++;
    }
}


Measured memory_bytes: 3112
import fractions 
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)


Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define IOS                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long

using namespace std;

double maxHeadProbab(vector<double> &p, int cur, int tc, vector<vector<double>> &dp)
{

    if (cur == p.size())
    {
        return 1;
    }

    if (dp[cur][tc] != -1.0)
    {
        return dp[cur][tc];
    }

    double t = 0.0, h = 0.0;
    if (tc < p.size() / 2)
    {
        t = (1.0 - p[cur]) * maxHeadProbab(p, cur + 1, tc + 1, dp);
    }
    h = p[cur] * maxHeadProbab(p, cur + 1, tc, dp);
    dp[cur][tc] = h + t;
    return h + t;
}

void solve()
{
    int n;
    cin >> n;
    cout << setprecision(10);
    vector<double> pro;
    vector<vector<double>> dp(n + 1, vector<double>((n + 1 / 2), -1.0));
    for (int i = 0; i < n; i++)
    {
        double prob1;
        cin >> prob1;
        pro.push_back(prob1);
    }

    cout << maxHeadProbab(pro, 0, 0, dp);
}
int main()
{
    IOS;
    // int t;
    // cin>>t;
    // while(t>0)
    // {
    solve();
    //     t--;
    // }
    return 0;
}

Measured memory_bytes: 71040
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
const int N = 100005;
int n, a[N], c[10*N], s[N];
long long query(int x){
    long long ans = 0;
    for(int i = x; i; i -= lowbit(i)) ans += c[i];
    return ans;
}
void add(int x){
    for(int i = x; i <= 2*N; i += lowbit(i)) c[i] += 1;
}
bool check(int x){
    for(int i = 1; i <= 2*N; ++i) c[i] = 0;
    s[0] = 0;
    for(int i = 1; i <= n; ++i){
        s[i] = s[i-1] + (a[i] >= x ? 1 : -1);
    }
    long long sum = 0;
    for(int i = 0; i <= n; ++i){
        sum += query(s[i] + N);
        add(s[i] + N);
    }
    return sum >= 1ll*n*(n+1)/4;
}
int main(){
    int l = 0, r = 0, ans;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d", a+i);
        r = max(a[i], r);
    }
    while(l <= r){
        int mid = (l + r) >> 1;
        if(check(mid)){
            l = mid + 1;
        }else r = mid - 1;
    }
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

ll N, K;
vl A, F;

bool check(const ll imid) {
    ll tmp = 0;
    FOR(i, 0, N) {
        if (A[i] * F[i] > imid) {
            tmp += (A[i] * F[i] - imid + F[i] - 1) / F[i];
        }
    }
    return K >= tmp;
}

signed main() {
    cin >> N >> K;
    A.resize(N);
    F.resize(N);
    for (auto &x : A) cin >> x;
    for (auto &x : F) cin >> x;
    sort(ALL(A));
    sort(ALL(F));
    reverse(ALL(F));
    ll imin = -1;
    ll imax = LINF;
    while (imax - imin > 1) {
        ll imid = (imax + imin) / 2;
        if (check(imid)) {
            imax = imid;
        } else {
            imin = imid;
        }
    }
    cout << imax << endl;
}


Measured memory_bytes: 3456
def resolve():
    D = int(input())
    C = [int(x) for x in input().split()]
    S = []
    for i in range(D):
        S.append(list(map(int, input().split())))
    last_d = []
    score = 0

    # 各日で満足度が最も増加するコンテストを開催していく(減少は計算しても考慮せず)
    for d in range(D):
        contest = 0
        for i in range(len(C)):  # d日目の最大増加満足度を示すiを探索
            contest = max(contest, S[d][i])
        score += contest
        last_d.append(S[d].index(contest))  # 開催したiを記録
        for i in range(len(C)):
            if i in last_d:
                score -= C[i] * last_d[::-1].index(i)
            else:
                score -= C[i] * (d + 1)
        print(S[d].index(contest) + 1)

    
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9292
n, k, q = map(int, input().split())

a = [int(input()) for _ in range(q)]

b = [int(0) for _ in range(n)]

for i in a:
    b[i-1] += 1
for i in range(n):
    if b[i] > q-k:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 8644
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

const int Nmax = 40, ABmax = 10;

int a[Nmax], b[Nmax], c[Nmax];
int dp[Nmax + 1][Nmax * ABmax + 1][Nmax * ABmax + 1];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	rep(i, 0, N) cin >> a[i] >> b[i] >> c[i];


	rep(i, 0, N + 1) rep(j, 0, N * 10 + 1) rep(k, 0, N * 10 + 1) dp[i][j][k] = 1e9;

	
	dp[0][0][0] = 0;

	rep(i, 0, N) {
		rep(j, 0, N * 10 + 1) {
			rep(k, 0, N * 10 + 1) {
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				if(j - a[i] >= 0 && k - b[i] >= 0) {
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
				}
			}
		}
	}
	
	int ans = 1e9;
	rep(i, 1, N * 10 + 1) rep(j, 1, N * 10 + 1) if(i * Mb == j * Ma) ans = min(ans, dp[N][i][j]);

	if(ans == 1e9) cout << -1 << endl;
	else cout << ans << endl;

}


Measured memory_bytes: 25984
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int odd = 0;
	int num4 = 0;
	int even = 0;
	bool ok = true;
	int N;
	cin >> N;
	REP(i, N) {
		int a;
		cin >> a;
		if (a % 4 == 0)num4++;
		else if (a % 2 == 0)even++;
		else odd++;
	}
	if (even == 0 && N / 2 > num4)ok = false;

	if (even != 0 && odd  > num4)ok = false;

	YesNo(ok)






	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int a, b; cin >> a >> b;
	cout << 6 - a - b << endl;
	return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

	bool can = true;
	for (int i = 0; i < S.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; j++) {
			string d = divide[j];
			if (S.substr(i, d.size()) == d) {
				can2 = true;
				i += d.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}

	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    for (int tc = input<int>(); tc != 0; --tc) {
        int64_t n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;

        std::unordered_map<int64_t, int64_t> cst;
        std::function<int64_t(int64_t)> get_cost = [&](int64_t num) {
            if (num == 0)
                return (int64_t)0;
            
            auto it = cst.find(num);
            if (it != cst.end())
                return it->second;

            int64_t res = min(__int128_t(TYPEMAX(int64_t) / 2), d * __int128_t(num));

            for (int fact: {2,3,5}) {
                int64_t cost_this = (fact == 2 ? a : (fact == 3 ? b : c));
                if (num % fact == 0)
                    res = min(res, get_cost(num / fact) + cost_this);
                else {
                    res = min(res, get_cost(num / fact) + cost_this + d * (num % fact));

                    if (num / fact + 1 < num)
                        res = min(res, get_cost(num / fact + 1) + cost_this + d * (fact - num % fact));
                }
            }
            
            return cst[num] = res;
        };

        cout << get_cost(n) << "\n";
    }

    return 0;
}


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

#define ll long long
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); (i)++)
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define line() cerr << "---------------" << endl;

int INF = 1e7;
int N, M;
int G[111][111];
int W[111][111];

int main() {
   cin >> N >> M;
   rep (i, 1, N+1) {
      rep (j, 1, N+1) {
         if (i == j) continue;
         G[i][j] = G[j][i] = INF;
         W[i][j] = W[j][i] = INF;
      }
   }
   rep (i, 0, M) {
      int a, b, c;
      cin >> a >> b >> c;
      G[a][b] = G[b][a] = c;
      W[a][b] = W[b][a] = c;
   }

   rep (k, 1, N+1) {
      rep (i, 1, N+1) {
         rep (j, 1, N+1) {
            W[i][j] = W[j][i] = min(W[i][j], W[i][k] + W[k][j]);
         }
      }
   }
   
   int ans = 0;
   rep (i, 1, N+1) {
      rep (j, 1, N+1) {
         if (i == j) continue;
         if (G[i][j] != INF && G[i][j] > W[i][j]) {
            ans++;
            G[i][j] = G[j][i] = INF;
         }
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr);

    string a, b; cin >> a >> b;
    
    int r = 0;
    rep(i, 3) r += a[i] == b[i];

    cout << r << endl;
}






Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    if K % 2 == 1:
        p = N // K
        ans = p ** 3
    else:
        p = N // K
        ans = p ** 3
        p = (N + K//2) // K
        ans += p ** 3

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
        if (t * s >= d) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 35832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll m = 1000;
    ll s = 0;
    FOR(i, 1, n){
        if(a[i] <= a[i-1]) continue;
        s = m / a[i-1];
        m -= s*a[i-1];
        m += a[i]*s;
    }
    pr(m);
    return 0;}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
template <typename T> void read(T &x) {
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9') x =(x<<1)+(x<<3)+c-'0',c=getchar();x *= f;
}
int n,a[N],ans;
int main() {
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);if(a[i]&1)ans++;
	}
	if(ans&1)return puts("NO")*0;
	else return puts("YES")*0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		sc = new Scanner(System.in);
		new Main();
		sc.close();
	}
	
	Main()
	{
		while(sc.hasNext()){
			String inp = sc.next();
			StringBuilder b = new StringBuilder();
			
			for(int i = 0; i < inp.length(); ++i){
				if(inp.charAt(i) == '@'){
					char c = inp.charAt(i+2);
					for(int j =  inp.charAt(i+1) - '0'; j > 0; --j)
						b.append(c);
					i += 2;
				}
				else b.append(inp.charAt(i));
			}
			
			System.out.println(b);
		}
	}
	
	
	boolean isPrime(int n){
		if(n == 2) return true;
		if(n % 2 == 0) return false;
		
		for(int i = 3; i * i <= n; i += 2)
			if(n % i == 0) return false;
		
		return true;
	}

	static Scanner sc;
}

Measured memory_bytes: 17132
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var d = o.l();
  var ans = 0;
  for(var i = 0; i < n; i++)for(var j = i+1;j < n; j++){
    ans += d[i]*d[j];
  }
  return ans;
}

Measured memory_bytes: 21192
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

constexpr int D = 365;

int score(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& t) {
	int S = 0;

	vector<int> last(26, 0);
	for (size_t i = 0; i < D; i++) {
		S += s[i][t[i]-1];
		
		last[t[i] - 1] = i+1;
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i+1 - last[j]);
		}
	}

	return S;
}

vector<int> solve(const vector<int>& c, const vector<vector<int>>& s) {
	vector<int> t(D);
	for (size_t i = 0; i < D; i++) {
		t[i] = distance(s[i].begin(), max_element(s[i].begin(), s[i].end())) + 1;
	}

	return t;
}

int main() {
	int ig;
	cin >> ig;

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		//c[i] = rand() % 100;
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
			//s[i][j] = rand() % 20000;
		}
	}

	auto t = solve(c, s);

	for (size_t i = 0; i < D; i++) cout << t[i] << endl;

	return 0;
}

Measured memory_bytes: 3672
#include<stdio.h>

int main()
{
int a,b,c,cost=0;
int max,min,mid;
scanf("%d%d%d",&a,&b,&c);
min = (a<b)?a:b;
min=(min<c)?min:c;

max = (a>b)?a:b;
max=(max>c)?max:c;

if(a!=max && a!= min) mid =a;
else if(b!=max && b!= min) mid =b;
else mid = c;

//printf("%d %d %d\n",max,mid,min);

printf ("%d\n",((mid-min)+(max-mid)));




    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

dp = [K] * N


def calc_dp(n):
    return n - Q


for i in A:
    # dp = list(map(calc_dp, dp))
    dp[i - 1] += 1

dp = list(map(calc_dp, dp))

for j in dp:
    if j > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 57944
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)
using namespace std;

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

    ll N, A, B, C, D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    A--; B--; C--; D--;

    string S2 = S;

    // まず岩の2連続を調べる
    bool ans = true;
    for (ll i = B; i < D; i++) {
        if ((S[i] == '#') && (S[i+1] == '#')) ans = false;
    }
    for (ll i = A; i < C; i++) {
        if ((S[i] == '#') && (S[i+1] == '#')) ans = false; 
    }

    // C < Dのとき、Bが行ったあとAが行くことで達成可能
    // D < Cのとき、BかDが岩と隣り合っていなければYes
    // D < CでDと岩が隣り合っているとき、BとDの間に3連続の○があれば、退避させて達成可能
    if (D < C) {
        ans = false;
        for (ll i = B; i < D-1; i++) {
            if (S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') {
                ans = true;
            }
        }
        if ((S[B-1] == '.' && S[B+1] == '.') || (S[D-1] == '.' && S[D+1] == '.')) {
            ans = true;
        }

    }

    if (ans) cout << "Yes\n";
    else cout << "No\n";

    // // first: B to D, second : A to C
    // bool ans1 = true;
    // for (ll i = B; i < D; i++) {
    //     if ((S[i] == '#') && (S[i+1] == '#')) {
    //         ans1 = false;
    //     }
    // }
    // if (ans1) {
    //     S[B] = '.';
    //     S[D] = '#';
    // }

    // for (ll i = A; i < C; i++) {
    //     if ((S[i] == '#') && (S[i+1] == '#')) {
    //         ans1 = false;
    //     }
    // }
    // if (ans1) {
    //     S[C] = '#';
    //     S[A] = '.';
    // }

    // // first: A to C, second: B to D
    // S = S2;
    // bool ans2 = true;
    // S[B] = '#';
    // for (ll i = A; i < C; i++) {
    //     if ((S[i] == '#') && (S[i+1] == '#')) {
    //         ans2 = false;
    //     }
    // }
    // if (ans2) {
    //     S[C] = '#';
    //     S[A] = '.';
    // }

    // S[B] = '.';

    // for (ll i = B; i < D; i++) {
    //     if ((S[i] == '#') && (S[i+1] == '#')) {
    //         ans2 = false;
    //     }
    // }
    // if (ans2) {
    //     S[B] = '.';
    //     S[D] = '#';
    // }

    // cout << ans1 << " " << ans2 << "\n";

    // if (ans1 || ans2) cout << "Yes\n";
    // else cout << "No\n";
}

Measured memory_bytes: 720
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
string a[100];
int main() {
	string A, B, C;
	cin >> A >> B >> C;
	if (A.back() == B[0] && B.back() == C[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int h=2,w;
    cin>>w;
    
    vector<vector<int>> v(h,vector<int>(w));
    rep(i,h){
        rep(j,w)cin>>v[i][j];
    }
    
    int sum = 0;
    int maxi = 0;
    
    rep(i,v[0].size()){
        sum+=v[0][i];
    }
    
    sum+=v[1][w-1];
    
    maxi = sum;
    for(int i=w-1;i>=1;i--){
        sum-=v[0][i];
        sum+=v[1][i-1];
        maxi = max(maxi,sum);
    }
    cout<<maxi<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    cout << (n + m - 1) / m << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a - b + 1);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int n;
ll k;
vp num;
ll sum = 0;

int main()
{
  cin >> n >> k;
  int a, b;
  rep(i,n){
    cin >> a >> b;
    num.push_back(make_pair(a, b));
  }
  sort(num.begin(), num.end());
  rep(i, n){
    sum += num[i].se;
    if (sum >= k){
      cout << num[i].fi << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n, m;
pp h[200010];

int main()
{
	read(n, m);
	for(int i=1; i<=n; ++i) read(h[i].x, h[i].y);
	sort(h+1, h+n+1);
	multiset<int> rs;
	multiset<int> down;
	for(int i=1; i<=n; ++i){
		int x = h[i].x;
		rs.insert(h[i].y);
		while(int(rs.size()) > x){
			down.insert(*rs.begin());
			rs.erase(rs.begin());
		}
	}
	int ans = 0;
	int ind = m;
	int rss = rs.size();
	for(auto it=down.end(); it!=down.begin();){
		int x=*--it;
		if(ind > rss && x <= ind) --ind;
		else ++ans;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 11136
object Main {
  def main(args: Array[String]): Unit = {
    val scanner = new java.util.Scanner(System.in)

    val n = scanner.nextInt
    var st, sh = 0
    for(_ <- 1 to n) {
      val ct, ch = scanner.next
      val c = ct.compareTo(ch)
      if(c > 0) st = st + 3 else if(c < 0) sh = sh + 3 else { st = st + 1; sh = sh + 1 }
    }
    println(s"$st $sh")
  }
}



Measured memory_bytes: 47908
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string upper = Console.ReadLine();
        string bottom = Console.ReadLine();
        Console.WriteLine(
            upper[0] == bottom[2] &&
            upper[1] == bottom[1] &&
            upper[2] == bottom[0] ?
            "YES" : "NO");
    }
}


Measured memory_bytes: 13140
// ABC 085

// inputに入力データ全体が入る
function Main(input) {
  input = input.split(" ");
  const N = parseInt(input[0],10); //枚数
  const Y = parseInt(input[1],10); //金額
  var result = "-1 -1 -1";

  for(var a=0;a<=N;a++) {
    for (var b=0;b<=N;b++) {
      var c = N - b - a;
      if(c<0)c = 0;
      var sum_money = a*10000 + b*5000 + c*1000;
      var sum_count = a + b + c;
      if(Y == sum_money && N == sum_count) {
        result = a + " " + b + " " + c + " ";
      }
    }
  }
  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7628
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int n;
	cin >> n;

	int a, sum = 0;

	for (int i = 0; i < n; i++)
	{
		cin >> a;
		sum += a;
	}

	cout << sum - n << endl;


	return 0;
}

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

int main(){
  int N, K, c;
  int x[110];
  int res = 0;
  cin >> N >> K;
  for(int i = 0; i < N; ++i){
    cin >> x[i];
    c = 0;
    if(x[i] <= std::abs(K - x[i]))
      c = x[i] * 2;
    else
      c = std::abs(K - x[i]) * 2;
    res += c;
  }
  cout << res << endl;
}

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

int main()
{
  string S;
  cin >> S;
  int N = S.size();
  vector<int> A(N, 0);
  for (int i = 0; i < 2; i++)
  {
    int cnt = 0;
    for (int j = 0; j < N; j++)
    {
      if (S[j] == 'R')
      {
        cnt++;
      }
      else
      {
        A[j] += cnt / 2;
        A[j - 1] += (cnt + 1) / 2;
        cnt = 0;
      }
    }
    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());
    for (int j = 0; j < N; j++)
    {
      S[j] = (S[j] == 'R' ? 'L' : 'R');
    }
  }
  for (int i = 0; i < N; i++)
  {
    if (i)
      cout << ' ';
    cout << A[i];
  }
  cout << endl;
}

Measured memory_bytes: 3828
from fractions import gcd #直して
n = int(input())
a = list(map(int, input().split()))

mod = 10**9+7
l = 1
for i in range(n):
    l = a[i] // gcd(l, a[i]) * l
    

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

d = 0
for i in range(n):
    d += modinv(a[i])

print((l*d) % mod)


Measured memory_bytes: 67304
#include<stdio.h>
int main(){
  int A,B,N,i,k,j;
  scanf("%d",&A);
  scanf("%d",&B);
  if(A!=2){
    if(B!=2){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
map$q[$_]+=$q[$N]/@$N,@{/ /,push@
$`,$' for<>;++$N}for++$q[1]..<>;${$b=1;$e[$N]=$b+=$_/@@for@@=sort@e[@$N];a}<($~=$q[$N]*($b-1-$@[-1])/($#@||1))or$a=$~while--$N;print$a+$b

Measured memory_bytes: 42368
#include <iostream> // import 標準入出力
using namespace std; // as *
int main() {
    int r, g, b;
    cin >> r >> g >>  b; // cin: キーボード入力
    int c = r *100 +  g * 10 + b;
    if (c % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b , c , d ;
  cin >> a >> b >> c >> d ;
 
  if (a+b>c+d) {
    cout << "Left" << endl;
  }
  else if (a+b<c+d){
    cout << "Right" << endl;
  }
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define ma 100000000
#define mod 1000000007
#define Nmax 1000000000000
using namespace std;
ll a[200000];
int k;
void add(ll arr[], int n, int lo, int hi, int val)
{
    arr[lo] += val;
    if (hi != n - 1)
       arr[hi + 1] -= val;
}
void updateArray(ll arr[], int n)
{

    for (int i = 1; i < n; i++)
        arr[i] += arr[i - 1];
}
void printArr(ll arr[], int n)
{
    updateArray(arr, n);
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
int segmt[800000];
void build(int p,int l,int r){
    if(l==r) {
        if(a[l]>=k) segmt[p]=1;
        else segmt[p]=0;
        return ;
    }
    int mid=(l+r)/2;
    build(2*p+1,l,mid);
    build(2*p+2,mid+1,r);
    segmt[p]=segmt[2*p+1]+segmt[2*p+2];
}
int query(int p,int ql,int qr,int l,int r){
    if(ql<=l && r<=qr) return segmt[p];//Total overlap
    if(r<ql || l>qr) return 0; //no overlap
    int mid=(l+r)/2;
    return query(2*p+1,ql,qr,l,mid)+query(2*p+2,ql,qr,mid+1,r);
}
int main()
{
    IOS;
	int n,k;cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++) cin>>h[i];
	ll dp[n];
	for(int i=0;i<n;i++) dp[i]=Nmax;
	dp[0]=0;
	for(int i=1;i<n;i++){
        for(int j=max(i-k,0);j<i;j++) dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
	}
   cout<<dp[n-1];
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;
int sum=0;

int32_t main() {
IOS
int n,k;
cin>>n>>k;
vector<int> v;
    for (int i = 0; i < n; ++i) {
       int a;
       cin>>a;
       v.push_back(a);
    }
    sort(v.begin(),v.end());
reverse(v.begin(),v.end());
    for (int i = 0; i < k; ++i) {
        sum+=v[i];
    }
    cout<<sum;
}

Measured memory_bytes: 256
Q = int(input())

MAX = 10**5
is_primes = [True for _ in range(MAX+1)]
is_primes[0] = False
is_primes[1] = False

for i in range(2, MAX):
    if is_primes[i]:
        for j in range(2*i, MAX, i):
            is_primes[j] = False

count = 0
count_2017 = [0, 0]
for i in range(3, MAX, 2):
    if is_primes[i]:
        if is_primes[(i+1)//2]:
            count += 1
    count_2017.append(count)

for _ in range(Q):
    l, r = list(map(int, input().split()))
    print(count_2017[r//2+1] - count_2017[l//2])

Measured memory_bytes: 4656
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(), a.end());
    vector<bool> cnt(1001000);
    vector<bool> b(1001000);

    int ans = 0;
    rep(i,n) {
        if (b[a[i]]) continue;
        if (!cnt[a[i]]) {
            ans++;
            if (i+1 < n) {
                if (a[i] == a[i+1]) ans--;
            }
        }
        for (int j = a[i]; j < 1001000; j+=a[i]) cnt[j] = true;
        b[a[i]] = true;
    }


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

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

int main() {
    int N;
    cin >> N;
    map<string, int> S;
    string s;
    for(int i=0; i<N; i++){
        cin >> s;
        S[s]++;
    }

    vector<string> ress = {
        "AC", "WA", "TLE", "RE"
    };
    for(string res : ress){
        cout << res << " x " << S[res] << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,m;
    cin>>n>>m;
    vi s(m),c(m);
    FOR(i,0,m){
        cin>>s[i]>>c[i];
        s[i]--;
    }
    FOR(i,0,1000){
        string st=to_string(i);
        if (st.length()!=n){
            continue;
        }
        //cerr<<st<<endl;
        int f=1;
        FOR(j,0,m){
            if(st[s[j]]==c[j]+'0'){

            }else{
                f=0;
            }
        }
        if(f){
            cout<<i<<endl;
            return 0;
        }

    }
    cout<<-1<<endl;

}


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;
using ll_i = pair<ll, int>;

struct edge { int v, w; };
ll INF = LLONG_MAX / 3;

vector<ll> dijkstra(int N, vector<vector<edge> >& G, int s) {
	vector<ll> d(N, INF); d[s] = 0;
	priority_queue<ll_i, vector<ll_i>, greater<ll_i> > pq;
	pq.push(ll_i(0, s));
	while (pq.size()) {
		ll_i p = pq.top(); pq.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (edge e: G[u])
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				pq.push(ll_i(d[e.v], e.v));
			}
	}
	return d;
}

int N;
int n = 0;
vector<vector<edge>> G;
int s, t;

struct Node {
    int l, r, v, w;
    Node *lch, *rch;
    
    Node(int l, int r) {
        this->l = l;
        this->r = r;
        v = n++;
        G.pb({});
        w = n++;
        G.pb({});
        if (r - l == 1) {
            if (l == 0) s = v;
            if (l == N - 1) t = w;
            G[v].pb(edge{w, 0});
            return;
        }
        int m = (l + r) / 2;
        lch = new Node(l, m);
        rch = new Node(m, r);
        G[v].pb(edge{lch->v, 0});
        G[v].pb(edge{rch->v, 0});
        G[lch->w].pb(edge{w, 0});
        G[rch->w].pb(edge{w, 0});
    }
};

void dfs(int v0, int v1, int l, int r, Node* z) {
    if (z->r <= l || r <= z->l) return;
    if (l <= z->l && z->r <= r) {
        G[z->w].pb(edge{v0, 0});
        G[v1].pb(edge{z->v, 0});
        return;
    }
    dfs(v0, v1, l, r, z->lch);
    dfs(v0, v1, l, r, z->rch);
}

int main() {
    int M;
    cin >> N >> M;
    Node* z = new Node(0, N);
    while (M--) {
        int l, r, w;
        scanf("%d%d%d", &l, &r, &w);
        l--;
        int v0 = n++;
        G.pb({});
        int v1 = n++;
        G.pb({});
        G[v0].pb(edge{v1, w});
        dfs(v0, v1, l, r, z);
    }
    vector<ll> d = dijkstra(n, G, s);
    ll ans = d[t];
    if (ans == INF) ans = -1;
    cout << ans << endl;
    // cerr << n << ' ' << s << ' ' << t << endl;
    // rep(v, n) for (edge e: G[v]) {
    //     cerr << v << ' ' << e.v << endl;
    // }
}


Measured memory_bytes: 75556
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<int,pll> P;
int main(){
  int i,n,k,t=0;
  string s;
  scanf("%d %d\n",&n,&k);
  cin >> s;
  for(i=1;i<n;i++){
    if(s[i-1]!=s[i]){
      t++;
    }
  }
  t++;
  t=t-k*2;
  if(t<1){
    t=1;
  }
  printf("%d\n",n-t);
  return 0;
}

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

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second


typedef long long LL;

const int N = 1e3 + 5;

int a[N], b[N];
int n, m, c, fg;
char s[45];


int main(){

	scanf("%d", &n);
	c = 0;

	rep(i, 1, n){
		scanf("%d%d", a + i, b + i);
		if ((a[i] + b[i]) & 1) ++c;
		else --c;
	}

	if (abs(c) != n) return 0 * puts("-1");

	m = 31 + (c < 0);

	printf("%d\n", m);
	rep(i, 0, 30) printf("%d ", 1 << i);
	if (c < 0) putchar(49);
	putchar(10);

	rep(i, 1, n){
		int x = a[i], y = b[i];
		if (c < 0) s[31] = 'R', --x;
		fg = 0;
		dec(j, 30, 0){
			if (abs(x) < abs(y)) swap(x, y), fg ^= 1;
			if (x > 0) x -= 1 << j, s[j] = fg ? 'U' : 'R';
			else x += 1 << j, s[j] = fg ? 'D' : 'L';
		}

		puts(s);
	}

	return 0;
}
 

Measured memory_bytes: 256
#include<stdio.h>

int solve(int, int);

int a[20];
int n;

int main(){
  int i,q,m;


  scanf("%d",&n);

  for(i = 0 ; i < n; i++){

    scanf("%d",&a[i]);
  }

  scanf("%d",&q);

 

    for(i = 0; i < q; i++){

      scanf("%d",&m);
      
      if(solve(0,m)) printf("yes\n");

      else printf("no\n");
    }

    return 0;
}


int solve(int i, int m)
{
  int res;

  
  if(m == 0)return 1;

  if(i >= n)return 0;

  res = solve(i+1,m) || solve(i+1,m-a[i]);

  return res;
}
  



Measured memory_bytes: 2108