akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n, m; cin >> n >> m;
  vector<int> a(n); REP (i, n) cin >> a[i];
  vector<ii> p(m); REP (i, m) cin >> p[i].se >> p[i].fi;
  sort(ALL(a));
  sort(RALL(p));
  bool con = true;
  int pt = 0;
  REP (x, m) {
    REP (i, p[x].se) {
      if (pt < n && a[pt] < p[x].fi) {
        a[pt] = p[x].fi;
        pt++;
      } else {
        con = false;
        break;
      }
    }
    if (!con) break;
  }
  cout << accumulate(ALL(a), 0LL) << endl;
}


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d; cin>>a>>b>>c>>d;
	int x=a*b, y=c*d;
	if (x>y) cout<<x;
	else cout<<y;
	return 0;
}


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

public class Main{
	public static void main(String[] args)  throws IOException,NumberFormatException{
		try {
			FastScanner sc=new FastScanner();
			char a[]=sc.next().toCharArray();
			char b[]=sc.next().toCharArray();
			char c[]=sc.next().toCharArray();
			if(a[a.length-1]==b[0]&&b[b.length-1]==c[0]) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
		catch(Exception e) {
			return ;
		}
		
	}
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;
		for(int i=0;i<n;i++) {
			int oi=random.nextInt(n),temp=oi;
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	public static int GCD(int a,int b) {
		if(b==0)
			return a;
		return GCD(b,a%b);
	}
	
	
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for(int i=0; i<n ; i++) a[i]=nextLong();
			return a;
		}
		
		String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
	}

}


Measured memory_bytes: 32996
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	t.pop_back();
	cout<<(t==s?"Yes":"No")<<endl;
}


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

int main(){
  
  int N;
  string str="", tmp="";
  
  cin>>N;

  char s[N];
  
  for(int  i=0;i<N;i++){
    cin>>s[i];
    
    tmp=s[i];
    
    if(i==0)str=s[i];
    if(i>0 && s[i-1]!=s[i]){
      str+=tmp;
    }
  }
 
  cout<<str.length()<<endl;
  
 return 0; 
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func check(e error) {
	if e != nil {
		log.Fatalf("error: %v", e)
	}
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	sage := stdin.Text()

	switch sage {
	case "1":
		fmt.Println("Hello World")
	case "2":
		var sum int
		for i := 0; i < 2; i++ {
			stdin.Scan()
			num, err := strconv.Atoi(stdin.Text())
			check(err)
			sum += num
		}
		fmt.Println(sum)
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
using namespace std;

char S[60];

int main() {
  int N=0, K=0;
  scanf("%d%d", &N, &K);
  scanf("%s", S);
  S[K-1] += 32;
  printf("%s", S);
  // cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define eps 1e-6
using namespace std;
typedef long long ll;
const ll mod = 998244353;
//const double pi = acos(-1);
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,p;
int main(){
    int i,j;
    n=read();
    n%=1000;
    if(n==0) n=1000;
    cout<<1000-n;
    return 0;
}

Measured memory_bytes: 3632
def prime_factors(n: int) -> list:
    tmp = n
    i = 2
    res = []
    while i*i <= n:
        if tmp%i==0:
            res.append(i)
            while tmp%i==0:
                tmp //= i
        i += 1
    # add remaining factor
    if tmp > 1:
        res.append(tmp)
    return res


def main():
    from fractions import gcd
    A, B = [int(x) for x in input().split()]

    g = gcd(A, B)
    factors = prime_factors(g)
    print(len(factors)+1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5052
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>

#define mod 1000000007
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG

using namespace std;
using ll = long long;
using lli = long long int;
using pii = pair<int, int>;
 
 int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for(int i = a; i <= b; i++){
		if(i % 10 == i / 10000 && i /1000 % 10 == i / 10 % 10) ans++;
	}
	cout << ans;
	return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int listt[n],ans[n];
    for(int i=0; i<n; i++)
        {scanf("%d",&listt[i]); ans[i]=listt[i];}
    sort(listt,listt+n);
    for(int i=0; i<n; i++)
    {
        if(ans[i]<=listt[n/2-1])
            printf("%d\n",listt[n/2]);
        else
            printf("%d\n",listt[n/2-1]);

    }

}

Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  long long n;
  cin>>n;
  string res="";
  while(n){
   --n;
   res+=(char)('a'+(n%26));
   n/=26;
  }
reverse(res.begin(),res.end());
cout<<res<<endl;
return 0;
}


Measured memory_bytes: 3628
//ABC163 A

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint n;
lint a[300000];


int main() {
  cin >> n;

/*   rep(i,n){
    scanf("%lld",&a[i]);
  } */

  
  printf("%lf\n",2*n*M_PI);
}


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

int main()
{
  int N, M;
  int result = 0;

  cin >> N >> M;

  vector<int> s(M);
  vector<int> c(M);

  for (int i = 0; i < M; i++)
  {
    cin >> s.at(i) >> c.at(i);
  }

  vector<int> resultNum(N, -1);

  if (M == 0)
  {
    if (N == 1)
    {
      result = 0;
      goto lastPoint;
    }
    if (N == 2)
    {
      result = 10;
      goto lastPoint;
    }
    if (N == 3)
    {
      result = 100;
      goto lastPoint;
    }
  }

  for (int i = 0; i < M; i++)
  {
    if (resultNum.at((s.at(i)) - 1) == -1 || resultNum.at((s.at(i)) - 1) == c.at(i))
    {
      resultNum.at((s.at(i)) - 1) = c.at(i);
    }
    else
    {
      result = -1;
    }
  }

  if (resultNum.at(0) == 0 && N != 1)
  {
    result = -1;
  }

  if ((resultNum.at(0) == -1) && result != -1)
  {
    for (int i = 1; i < N; i++)
    {
      if (resultNum.at(i) != -1)
      {
        resultNum.at(0) = 1;
        break;
      }
    }
    if (resultNum.at(0) == -1)
    {
      result = -1;
    }
  }

  if (result != -1)
  {
    for (int i = 0; i < N; i++)
    {
      if (resultNum.at(N - 1 - i) == -1)
      {
        resultNum.at(N - 1 - i) = 0;
      }
      result += resultNum.at(N - 1 - i) * pow(10, i);
    }
  }

lastPoint:;
  cout << result << endl;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    G=[[] for _ in range(n+1)]
    for i in range(m):
        l,r,d=map(int,readline().split())
        G[l].append((r,d))
        G[r].append((l,-d))

    flags=[False]*(n+1)
    flags[0]=True
    inf=10**10
    x=[-inf]*(n+1)
    q=deque([])
    ans=True
    for i in range(1,n+1):
        if ans==False: break
        if flags[i]==False:
            x[i]=0
            flags[i]=True
            q.append(i)
            while len(q)>0:
                now=q.popleft()
                for t in G[now]:
                    nex=t[0]
                    cost=t[1]
                    if x[nex]==-inf:
                        x[nex]=x[now]+cost
                    else:
                        if x[nex]!=x[now]+cost:
                            ans=False
                            break
                    if flags[nex]==False:
                        flags[nex]=True
                        q.append(nex)

    print("Yes" if ans else "No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 75168
#include <bits/stdc++.h>
using namespace std;
int H, W, totalPass = 0;
bool possible = false;
vector<vector<bool>> Passed(8, vector<bool>(8, false));

void search(int x, int y, int cnt)
{
  if (x < 0 || x >= W || y < 0 || y >= H)
    return;
  if (Passed.at(y).at(x) = false)
    return;
  if (x == W - 1 && y == H - 1 && cnt == totalPass - 1)
  {
    possible = true;
    return;
  }
  search(x + 1, y, cnt + 1); // 右へ
  search(x, y + 1, cnt + 1); // 下へ
}

int main()
{
  char c;
  cin >> H >> W;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> c;
      if (c == '#')
      {
        Passed.at(i).at(j) = true;
        totalPass++;
      }
    }
  }
  search(0, 0, 0);
  cout << (possible ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <chrono>
#include <random>

using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

const int nKind = 26;
const int actualD = 365;
mt19937 rnd(12345);

int D;
int C[nKind], S[actualD][nKind];

int urand(int lo, int hi)
{
	return uniform_int_distribution<int>(lo, hi)(rnd);
}

int emulate(const vector<int>& ans)
{
	int last[nKind];
	for (int i = 0; i < nKind; ++i) last[i] = -1;
	int score = 0;
	for (int i = 0; i < D; ++i) {
		score += S[i][ans[i]];
		last[ans[i]] = i;
		for (int j = 0; j < nKind; ++j) {
			score -= C[j] * (i - last[j]);
		}
	}
	return score;
}

vector<int> greedy()
{
	int last[nKind];
	for (int i = 0; i < nKind; ++i) last[i] = -1;

	vector<int> ans;
	for (int i = 0; i < D; ++i) {
		int profit[nKind];
		for (int j = 0; j < nKind; ++j) {
			profit[j] = C[j] * (i - last[j]) + S[i][j];
		}
		int best = 0;
		for (int j = 0; j < nKind; ++j) {
			if (profit[best] < profit[j]) best = j;
		}
		last[best] = i;
		ans.push_back(best);
	}
	return ans;
}

vector<int> SA(vector<int> initial)
{
	uniform_real_distribution<double> ureal(0.0, 1.0);

	auto start = chrono::system_clock::now();
	vector<int> best = initial;
	int best_score = emulate(best);

	vector<int> current = initial;
	int current_score = best_score;

	double temp = 100.0;
	for (;;) {
		for (int i = 0; i < 100; ++i) {
			int t = urand(0, D - 1);
			int v = urand(0, nKind - 1);

			int current_v = current[t];
			if (v == current_v) continue;

			current[t] = v;
			int updated_score = emulate(current);

			bool updated = false;

			if (current_score < updated_score || ureal(rnd) < exp((updated_score - current_score) / temp)) {
				updated = true;
			}

			if (updated) {
				current_score = updated_score;
				if (best_score < updated_score) best = current;
			} else {
				current[t] = current_v;
			}
		}
		temp *= 0.999;

		double elapsed = chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now() - start).count() / 1e9;
		if (elapsed > 1.8) break;
	}
	return best;
}

int main()
{
	scanf("%d", &D);
	for (int i = 0; i < nKind; ++i) scanf("%d", C + i);
	for (int i = 0; i < D; ++i) {
		for (int j = 0; j < nKind; ++j) scanf("%d", &(S[i][j]));
	}
	auto ans = greedy();
	ans = SA(ans);
	for (int i = 0; i < D; ++i) printf("%d\n", ans[i] + 1);
	fprintf(stderr, "score: %d\n", emulate(ans));
	return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ll H,W;
  cin >> H >> W;
  string board[H];
  rep(i,H) cin >> board[i];

  int x = 0;
  int y = 0;
  while(true){
    board[y][x] = 'x';
    if(x == W-1 && y == H-1) break;
    if(board[y][x+1] == '#' && board[y+1][x] == '#'){
      cout << "Impossible" << endl;
      return 0;
    }else if(x+1 < W && board[y][x+1] == '#'){
      x++;
    }else if(y+1 < H && board[y+1][x] == '#'){
      y++;
    }else{
      cout << "Impossible" << endl;
      return 0;
    }
  }

  rep(i,H)rep(j,W){
    if(board[i][j] == '#'){
      cout << "Impossible" << endl;
      return 0;
    }
  }
  cout << "Possible" << endl;
  return 0;
}


Measured memory_bytes: 256
def I(): return int(input())
n = I()
ans = 0
if n>=105:
    for i in range(105,n+1,2):
        cnt=0
        for j in range(1,int(i**0.5)+1):
            if i % j ==0:
                if j*j==i:
                    cnt+=1
                else:
                    cnt+=2
        if cnt==8:
            ans+=1
print(ans)


Measured memory_bytes: 9436
import java.util.Scanner;
public class Main{

	public void solve(){
        Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
	    System.out.println(x*x*x);
		
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}	

Measured memory_bytes: 17156
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
#pragma endregion


// Effective std
#pragma region ESTD

template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }

template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }

template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }

template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }

template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }

template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }

#pragma endregion


// ??°?????????????????¬??????
#pragma region GRAPH

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int 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 :
    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;

#pragma endregion

// ?´???°
#pragma region PRIME
bool is_prime(unsigned n) {
  switch(n) {
    case 0:
    case 1: return false;
    case 2: return true;
  }
  if (n%2==0) return false;
  for (unsigned i=3; i*i<=n; i+=2)
    if (n%i==0) return false;
  return true;
}
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#pragma endregion

int main() {
  int n;
  cin >> n;
  int count = 0;
  rep(i, n) {
    int a;
    cin >> a;
    if (is_prime(a)) count++;
  }
  cout << count << endl;
  return 0;
}

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

const int MAX_N=100000;

bool is_prime[MAX_N+1];
bool is_2017[MAX_N+1];
int P[MAX_N+1];

void sieve() {
  for (int i=0; i<=MAX_N; i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for (int i=2; i<=MAX_N; i++) {
    if (is_prime[i]) {
      for (int j=2*i; j<=MAX_N; j+=i) is_prime[j]=false;
    }
  }
}

void ok2017() {
  for (int i=0; i<=MAX_N; i++) is_2017[i]=false;
  for (int i=2; i<=MAX_N; i++) {
    int j=(i+1)/2;
    if (is_prime[i]&&is_prime[j]) is_2017[i]=true;
  }
}

int main() {
  int Q; cin>>Q;
  sieve();
  ok2017();
  rep(i, MAX_N+1) {
    if (is_2017[i]) P[i]++;
  }
  rep(i, MAX_N) P[i+1]+=P[i];

  vector<int> res;
  rep(query, Q) {
    int l,r; cin>>l>>r;
    int tmp=P[r]-P[l-1];
    res.push_back(tmp);
  }
  rep(i, Q) cout<<res[i]<<endl;
}


Measured memory_bytes: 1784
def countng_sort(a):
  MAX = 10000
  n = len(a)
  b = [None] * n
  c = [0] * MAX
  
  for i in range(n):
      c[a[i]] += 1
  
  for i in range(1, MAX):
      c[i] += c[i - 1]
  
  for i in reversed(range(0, n)):
      b[c[a[i]] - 1] = a[i]
      c[a[i]] -= 1

  return b

n = int(input())
a = [int(i) for i in input().split()]
print(*countng_sort(a))



Measured memory_bytes: 224148
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
// using namespace atcoder;
using ll = long long;
const int mod = 1e9 + 7;

void solve()
{
    vector<vector<int>> bingo(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> bingo[i][j];
    int n;
    cin >> n;
    vector<vector<bool>> chk(3, vector<bool>(3));
    rep(i, n)
    {
        int b;
        cin >> b;
        rep(j, 3) rep(k, 3)
        {
            if (bingo[j][k] == b)
                chk[j][k] = true;
        }
    }
    bool ok = false;
    if (chk[0][0] && chk[0][1] && chk[0][2])
        ok = true;
    if (chk[1][0] && chk[1][1] && chk[1][2])
        ok = true;
    if (chk[2][0] && chk[2][1] && chk[2][2])
        ok = true;
    if (chk[0][0] && chk[1][0] && chk[2][0])
        ok = true;
    if (chk[0][1] && chk[1][1] && chk[2][1])
        ok = true;
    if (chk[0][2] && chk[1][2] && chk[2][2])
        ok = true;
    if (chk[0][0] && chk[1][1] && chk[2][2])
        ok = true;
    if (chk[0][2] && chk[1][1] && chk[2][0])
        ok = true;
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    // srand((unsigned)time(NULL));
    // int t = clock();
    solve();
    // double et = 1.0 * (clock() - t) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

Measured memory_bytes: 3596
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
char da[4] = { 'R', 'L', 'D', 'U' };
char dad[4] = { 'L', 'R', 'U', 'D' };
ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }

ll N;



ll kaijou(int a) {

	if (a == 0 || a == 1)
		return 1;

	else
		return a * kaijou(a - 1);

}


int main() {
	ll N, K;

	cin >> N >> K;
	

	cout << N - K + 1 << endl;




	
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int v[]=new int[N];
		int max=0,smax=0;
		v[0]=sc.nextInt();
		max=v[0];
		for(int i=1;i<N;i++) {
			v[i]=sc.nextInt();
			if(v[i]>=max) {
				smax=max;
				max=v[i];
			}else if(v[i]>=smax) {
				smax=v[i];
			}
		}
		
		for(int i=0;i<N;i++) {
			if(v[i]==max)p(smax);
			else p(max);
		}
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 93776
x,y = map(int,input().split())
flag = True
for j in range(0,x//2+2):
    nup = j*2
    nright = (x-nup)
    if( j+2*nright == y)&(nright >= 0):
        flag = False
        break
        
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

    
if flag == False:
    a = cmb((j+nright),j ,mod)
    print(a)
    
else:
    print(0)



Measured memory_bytes: 122064
# coding: utf-8
# Your code here!

while True:
   q = int(input())
   if q == -1: break
   
   x = q / 2
   while abs(x ** 3 - q) >= 0.00001 * q:
      x = x - (x ** 3 - q) / (3 * x ** 2)
   print(x)


Measured memory_bytes: 5668
#include <stdio.h>

int g[102], m;
int cnt;

void shell_sort(int n, int *a)
{
	int i, j, h, lim;
	int key;

	lim = n / 9;		// 要素数/9
	if (lim < 40) lim = 40;
	
	g[0] = 1;
	m = 0; do m++, g[m] = 3*g[m-1]+1;
	while (g[m] < n && g[m] <= lim);

	cnt = 0, h = g[m-1];
	while (h > 0) {
		for (i = h; i < n; i++) {
			key = a[i];
			j = i-h; while (j >= 0 && a[j] > key) {
				cnt++;
				a[j+h] = a[j];
				j -= h;
			}
			a[j+h] = key;
		}
		h /= 3;
	}
}

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i;
	if (n == 0) { pc('0'); return; }
	i = 0; while (n) buf[i++] = n%10 +'0', n /= 10;
	while (i) pc(buf[--i]);
}

int a[1000002];

int main()
{
	int N, i;

	N = in(); for (i = 0; i < N; i++) a[i] = in();

	shell_sort(N, a);
	
	mypr(m), pc('\n');
	mypr(g[m-1]); for (i = m-2; i >= 0; i--) pc(' '), mypr(g[i]); pc('\n');
	mypr(cnt), pc('\n');
	for (i = 0; i < N; i++) mypr(a[i]), pc('\n');

	return 0;
}



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

using namespace std;

int gcd(int a, int b) {return b? gcd(b,a%b) : a;}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    int ans = a[0];
    for (int i=0; i<n; i++) {
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
'use strict'

const INF = 900719925474099 // Number.MAX_SAFE_INTEGER / 10;

function Main(input){
	let temp = input.trim().split('\n');
	let n = parseInt(temp[0]);
	let abc = new Array(n);

	for(let i=0;i<n;i++){
		abc[i] = temp[i+1].split(' ').map((v)=>parseInt(v));
	}

	let step = [...new Array(n+10)].map(()=>(new Array(3).fill(0)));
	//console.log(step);
	step[0][0]=abc[0][0];
	step[0][1]=abc[0][1];
	step[0][2]=abc[0][2];
	
	for(let i=1;i<n;i++){
		step[i][0] = abc[i][0] + Math.max( step[i-1][1] , step[i-1][2] );
		step[i][1] = abc[i][1] + Math.max( step[i-1][0] , step[i-1][2] );
		step[i][2] = abc[i][2] + Math.max( step[i-1][0] , step[i-1][1] );
	}
	console.log(Math.max(...step[n-1]));
}

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


Measured memory_bytes: 52452
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, r;
    cin >> h >> r;
    if (h == -r) {
        cout << 0 << endl;
    } else if (h > -r) {
        cout << 1 << endl;
    } else {
        cout << -1 << endl;
    }
}



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

int main(){
    int A,B;
    cin >> A >> B;
    int money = 0;
    if (A <= 5) {
        money = 0;
    }else if(6 <= A && A <= 12){
        money = B / 2;
    }else{
        money = B;
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  
  rep(i, k) {
    vector<int> sum(n + 1);
    rep(i, n) {
      int low = max(0, i - a[i]);
      int high = min(n , i + a[i] + 1);
      sum[low]++;
      sum[high]--;
    }

    int cur = 0;
    bool ok = true;
    rep(i, n) {
      cur += sum[i];
      a[i] = cur;
      if (cur != n) ok = false;
    }

    if (ok) break;
  }

  rep(i, n) printf("%d%c", a[i], (i == n - 1) ? '\n' : ' ');
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a==b){
    cout << "Draw" << endl;
    return 0;
  }
  else if(b!=1&&(b<a||a==1)){
    cout << "Alice" << endl;
  }
  else
    cout << "Bob" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
#define rush             ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll               long long int
#define FOR(a,x,n)       for(ll a=x;a<n;a++)
#define ROF(a,x,n)       for(ll a=x;a>=n;a--)
#define pb               push_back
#define lb               lower_bound
#define ub               upper_bound
#define MOD              1000000007

ll a[100005];
ll dp[100005];

ll n, k;

ll ans(ll index) {
       if(index == n-1) return 0;

       ll minn = LLONG_MAX;

       if(dp[index] != -1) return dp[index];
       
       for(ll i=index+1; i<=min(n-1, index+k); i++) {
           minn = min(minn, min(minn, abs(a[i] - a[index])) + ans(i)); 
       }

       return dp[index] = minn;  
}

void solve() {
     cin >> n >> k;

     memset(dp, -1, sizeof dp);

     FOR(i,0,n) cin >> a[i];

     cout << ans(0);
}
 
int main() {
        rush
        solve();
}

Measured memory_bytes: 11340
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vec vector
#define vi vec<int>
#define vvi vec<vec<int>>
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define SORT(a) stable_sort(ALL(a))
#define RSORT(a) stable_sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNIQUE(a) a.erase(unique(ALL(a)), end(a))
#define lambda(i) [](auto& i)
#define compare(i, j) [](auto& i, auto& j)
#define min_of(a) *min_element(ALL(a))
#define max_of(a) *max_element(ALL(a))
#define sum(a) accumulate(ALL(a), 0)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(a) (int)(a).size()
#define REP(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = n - 1; i != static_cast<decltype(i)>(-1); i--)
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = b - 1; i != a; i--)
#define EACH(i, a) for (auto&& i: (a))
using namespace std;

const int INF = 1e18;
const int MOD = 1e9 + 7;

struct union_find {
  vi data;
  union_find(int size) : data(size, -1) { }
  bool union_set(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find_set(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

vi cum(vi V) {
  vi U(SZ(V));
  partial_sum(ALL(V), begin(U));
  return U;
}

void solve() {
  int n;
  int ans = 0;

  cin >> n;
  vi v(10e5 + 1);
  REP(i, n) {
    int a;
    cin >> a;
    if(a > 0)v[a - 1]++;
    v[a]++;
    if(a < n - 1)v[a + 1]++;
  }

  cout << max_of(v) << endl;
  // REP(i, n) {
  //   cout << v[i];
  // }
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(15);
  solve();
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=5005,P=1e9+7;
int n,a[N],f[N][N],t[N],sz[N];
vector<int>g[N]; 
void dfs(int x,int p)
{
	f[x][1]=1;sz[x]=1;
	for(int i=0;i<g[x].size();i++)if(g[x][i]!=p)
	{
		int y=g[x][i];dfs(y,x);
		for(int j=1;j<=sz[x];j++)t[j]=f[x][j],f[x][j]=0;
		for(int j=1;j<=sz[x];j++)for(int k=0;k<=sz[y];k++)f[x][j+k]=(f[x][j+k]+1ll*t[j]*f[y][k])%P;
		sz[x]+=sz[y];
	}
	for(int i=1;i<=sz[x];i++)f[x][0]=(f[x][0]+P-1ll*f[x][i]*a[i]%P)%P;
}
int main()
{
	scanf("%d",&n);a[0]=1;
	for(int i=2;i<=n;i+=2)a[i]=1ll*a[i-2]*(i-1)%P;
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),g[u].pb(v),g[v].pb(u);
	dfs(1,0);printf("%d\n",P-f[1][0]);return 0;
}

Measured memory_bytes: 97536
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const long long MOD = 1000000007;
ll sort_cnt(vector<ll> &a,ll l,ll r){
  if(l+1==r){
    return 0;
  }
  if(l+2==r){
    if(a[l]>a[l+1]){
      swap(a[l],a[l+1]);
      return 1;
    }else{
      return 0;
    }
  }
  ll mid=(l+r)/2;
  ll ret=0;
  ret+=sort_cnt(a,l,mid);
  ret+=sort_cnt(a,mid,r);
  vector<ll> tmp;
  ll i=l,j=mid;
  while(i<mid||j<r){
    if(i==mid){
      tmp.push_back(a[j]);
      ++j;
      continue;
    }
    if(j==r){
      tmp.push_back(a[i]);
      ++i;
      continue;
    }
    if(a[i]>a[j]){
      ret+=mid-i;
      tmp.push_back(a[j]);
      ++j;
    }else{
      tmp.push_back(a[i]);
      ++i;
    }
  }
  REP(r-l){
    a[i+l]=tmp[i];
  }
  return ret;
}
void solve(long long N, long long K, std::vector<long long> A){
  ll cnt=sort_cnt(A,0,N);
  dump(A);
  ll ans=cnt*K;
  REP(N){
    ll j=lower_bound(A.begin(),A.end(),A[i])-A.begin();
    ans+=(j)*(K*(K-1)/2%MOD)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


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

int main() {
 string b;
  cin >> b;
  for (int i = 1; i < 4; i++){
  if(b.size() == i){
    if (b.at(i-1) == '2' || b.at(i-1) == '4' || b.at(i-1) == '5' || b.at(i-1) == '7' || b.at(i-1) == '9'){
      cout << "hon" << endl;
    }
    else if (b.at(i-1) == '0' || b.at(i-1) == '1' || b.at(i-1) == '6' || b.at(i-1) == '8'){
      cout << "pon" << endl;
    }
    else if (b.at(i-1) == '3'){
      cout << "bon" << endl;
    }
  }
}
}

Measured memory_bytes: 3580
N=input()

dp=[ float("inf") for i in range(N+1) ]
dp[0]=0

i=1

for i in range(1,8):
	for n in range(N):
		if n+ 9**i  <=N: 	dp[ n+ 9**i ]=min( dp[n]+1, dp[ n+9**i ] )
		if n+ 6**i  <=N: 	dp[ n+ 6**i ]=min( dp[n]+1, dp[ n+6**i ] )
		if n+ 1  <=N:	dp[ n+ 1 ]=min( dp[n]+1, dp[ n+1 ] )


print dp[N]

Measured memory_bytes: 34156
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int a,b,n,c,t,ans=0;
	vector<int> d;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	rep(i,n){
		scanf("%d",&t);
		d.push_back(t);
	}
	sort(d.rbegin(),d.rend());
	int m,s;
	rep(i,n){
		m=(i+1)*b+a;
		s=c;
		rep(j,i+1)s+=d[j];
		ans=max(ans,s/m);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1212
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    w, h, n = MI()
    tt = [[1] * w for _ in range(h)]
    for _ in range(n):
        x, y, a = MI()
        if a == 1: i0, i1, j0, j1 = 0, h, 0, x
        if a == 2: i0, i1, j0, j1 = 0, h, x, w
        if a == 3: i0, i1, j0, j1 = 0, y, 0, w
        if a == 4: i0, i1, j0, j1 = y, h, 0, w
        for i in range(i0, i1):
            for j in range(j0, j1):
                tt[i][j] = 0
    ans=sum(sum(row) for row in tt)
    print(ans)

main()


Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

typedef long long ll;

const int N_MAX = 100000;

int N;
int A[N_MAX];

void solve() {
  sort(A, A + N);
  ll sum = 0;
  REP(i, N) sum += A[i];
  int ans = 1;
  for (int i = N - 1; i > 0; i--) {
    sum -= A[i];
    if (sum * 2 >= A[i]) ans++;
    else break;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", A + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

typedef pair<int,int> P;

int w, h;
int gx, gy;
char t[1002][1002];
bool flg[1002][1002];

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

bool solve(int sx, int sy){
  queue<P> open;
  open.push(P(sx, sy));

  while(!open.empty()){
    P p = open.front(); open.pop();
    if(flg[p.second][p.first]) continue;
    flg[p.second][p.first] = true;

    if(p.first == gx && p.second == gy){
      return true;
    }

    for(int i = 0; i < 4; i++){
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];

      if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
      if(t[ny][nx] == '#') continue;
      open.push(P(nx, ny));
    }
  }

  return false;
}

int main(){
  while(cin >> w >> h){
    for(int i = 0; i < h; i++){
      cin >> t[i];

      for(int j = 0; j < w; j++){
        if(t[i][j] == 't'){
          gx = j;
          gy = i;
          t[i][j] = '.';
        }
      }
    }

    int ans = -1;
    memset(flg, 0, sizeof(flg));
    if(solve(0, 0)) ans = 0;

    int T;
    cin >> T;

    for(int i = 0; i < T; i++){
      int x, y;
      cin >> x >> y;

      if(0 <= ans) continue;

      t[y][x] = '.';

      for(int j = 0; j < 4; j++){
        int nx = x + dx[j];
        int ny = y + dy[j];
        if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
        if(flg[ny][nx]){
          bool tmp = solve(x, y);
          if(tmp) ans = i + 1;
          break;
        }
      }
    }

    cout << ans << endl;
  }
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N, K; cin >> N >> K;
  vector<int> p(N);
  rep(i, N) {
    cin >> p[i];
  }
  double curr = 0.0;
  double ans = 0.0;
  rep(i, K) {
    curr += (p[i] + 1) / 2.0;
  }
  ans = curr;
  REP(i, K, N) {
    curr -= (p[i - K] + 1) / 2.0;
    curr += (p[i] + 1) / 2.0;
    ans = max(ans, max(ans, curr));
  }
  printf("%.10f\n", ans);
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = (n-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    string s; lint k; cin >> s >> k;
    int n = s.size();
    rep(i, n){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
        else{
            k--;
            if(k == 0){
                cout << "1" << endl;
                return 0;
            }
        }
    }
    cout << "1" << endl;;
}

Measured memory_bytes: 256
#include <iostream>

void solve() {
    int k, a, b;
    std::cin >> k >> a >> b;

    for (int x = a; x <= b; ++x) {
        if (x % k == 0) {
            std::cout << "OK" << std::endl;
            return;
        }
    }

    std::cout << "NG" << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int ans = 0;

void dfs(int array[], int k, int s){
  if(array[0] == 2){
    int sum = 0;
    for(int i=1; i<=3; i++)
      sum += array[i];
    if(s-k <= sum  &&  sum <= s)
      ans++;
    return;
  }

  for(int i=0; i<=k; i++){
    array[++array[0]] = i;
    dfs(array, k, s);
    array[0]--;
  }
}
int main(){
  int k, s;  scanf("%d %d", &k, &s);
  int array[4] = {0};
  dfs(array, k, s);

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

s = input()
k = int(input())

#1が続いたあと1出ない最初の文字があとはつづく

one_seq = 0
ret = 0
for i in s:
    if i == "1":
        one_seq+=1
    else:
        ret = i
        break

#one_seq = 左からxx文字1が続く
if k <= one_seq:
    print(1)
else:
    print(ret)

Measured memory_bytes: 3060
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        ws: [i32; n],
    }
    let mut min = 100000;
    let mut i = 0;
    let (mut j, mut s1, mut s2);

    let wss = ws.clone();
    for _ in ws {
        s1 = 0;
        s2 = 0;
        j = i + 1;
        for x in 0..j {
            s1 += wss[x];
        }
        for x in j..n {
            s2 += wss[x];
        }

        let dif = (s1 - s2).abs();
        if dif < min {
            min = dif;
        }
        // println!("{}: s1={}, s2={}, dif={}", i, s1, s2, dif);
        i += 1;
    }
    println!("{}", min);
}


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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    int n;cin>>n;
    vi dat(101);
    dat[0]=1;
    dat[4]=1;
    dat[7]=1;
    FOR(i,8,101){
        if(dat[i-4]==1 or dat[i-7]==1){
            dat[i]=1;
        }
    }
    cout<<(dat[n]==1?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256