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

using namespace std;
int main()
{
    long long n,x,y,d;
    int t;
    int p;
    cin>>p;
    int ans=7%p;
    int cnt=1;
    while(ans)
    {
        ans=(ans*10+7)%p;
        cnt++;
        if(cnt>p+100)
            {
                cout<<-1;
                return 0;
            }
    }
    cout<<cnt;
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    if (a == 1) {
        if (n == b) {
            vector<int> ans(n);
            for (int i = 0; i < n; i++) ans[i] = n - i;
            cout << ans[0];
            for (int i = 1; i < n; i++) cout << " " << ans[i];
            cout << endl;
        } else {
            cout << -1 << endl;
        }
    } else if (b == 1) {
        if (n == a) {
            vector<int> ans(n);
            for (int i = 0; i < n; i++) ans[i] = i + 1;
            cout << ans[0];
            for (int i = 1; i < n; i++) cout << " " << ans[i];
            cout << endl;            
        } else {
            cout << -1 << endl;
        }
    } else if (n <= a || n <= b) {
        cout << -1 << endl;
    } else {
        vector<int> ans(n);
        if (a <= b) {
            for (int i = 0; i < a; i++) ans[i] = n - a + i + 1;
            int lim = n - a + 1;
            if (b < 2 || b > lim || (n + b - 1) / b > a) cout << -1 << endl;
            else {
                int idx = a, cnt = 1;
                while (idx < n) {
                    for (int i = 0; i < b - 1; i++) {
                        ans[idx] = min((b - 1) * cnt - i, n - a - i);
                        idx++;
                        if (idx == n) break;
                    }
                    cnt++;
                }
                cout << ans[0];
                for (int i = 1; i < n; i++) cout << " " << ans[i];
                cout << endl;             
            }
        } else {
            for (int i = 0; i < b; i++) ans[i] = b - i;
            int lim = n - b + 1;
            if (a < 2 || a > lim || (n + a - 1) / a > b) cout << -1 << endl;
            else {
                int idx = b, cnt = 1;
                while (idx < n) {
                    for (int i = 0; i < a - 1; i++) {
                        ans[idx] = max(n - (a - 1) * cnt + i + 1, b + 1 + i);
                        idx++;
                        if (idx == n) break;
                    }
                    cnt++;
                }
                cout << ans[0];
                for (int i = 1; i < n; i++) cout << " " << ans[i];
                cout << endl;             
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,aa[5];
ll sum,ans;
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>aa[i],sum+=aa[i];
	{
		vector<int>M,N;
		for(int j=0;j<(1<<n);j++){
			if(__builtin_popcount(j) >= 2 && __builtin_popcount(j) <= 3) M.pb(j);
			else if(__builtin_popcount(j) >= 4) N.pb(j);
		}
		int sz = M.size();
		for(int j=0;j<(1<<sz);j++){
			vector<int>vec; int cnt[5]={}; ll C=0;
			rep(k,sz) if(((j>>k)&1)) vec.pb(M[k]);
			rep(k,vec.size())for(int a=k+1;a<vec.size();a++){
				int v = (vec[k]&vec[a]);
				if(__builtin_popcount(v) >= 2) goto fail;
			}
			rep(k,vec.size()){
				rep(a,n) if(((vec[k]>>a)&1)) cnt[a]++;
			}
			rep(a,n) if(cnt[a] > aa[a]) goto fail;
			rep(a,n) C += cnt[a];
			C -= vec.size();
			ans = max(ans,C);
			for(int k=0;k<N.size();k++){
				bool ok = 1;
				rep(a,n) if(((N[k]>>a)&1)&&cnt[a]>=aa[a]) ok=0;
				if(!ok) continue;
				rep(kk,vec.size()) if(__builtin_popcount(vec[kk]&N[k])>=2) ok=0;
				if(!ok) continue;
				ll D = C;
				D += __builtin_popcount(N[k])-1;
				ans = max(ans,D);
			}
			fail:;
		}
	}
	cout<<sum-ans<<endl;
}


Measured memory_bytes: 3144
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s
}

fn main () {
	let s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();

	let i = s.concat().parse::<i32>().unwrap();

	if (i%4) == 0 {
		println!("YES");
	}else{
		println!("NO");
	}
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N, long long K, std::vector<long long> A){
  for (int i = 0; i < K; ++i) {
    std::vector<long long> B(N+1, 0);
    for (int j = 0; j < N; ++j) {
      B[max(0LL, j-A[j])]++;
      B[min(N, j+A[j]+1)]--;
    }
    long long t = 0;
    bool flag = true;
    for (int j = 0; j < N; ++j) {
      t += B[j];
      A[j] = t;
      if (t != N) flag = false;
    }
    if (flag) break;
  }

  for (int i = 0; i < N; ++i) {
    if (i != 0) std::cout << " ";
    std::cout << A[i];
  }
  std::cout << std::endl;
}

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


Measured memory_bytes: 6428
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- 整数の入力
    n <- getLine
    -- スペース区切り整数の入力
    l <- map strToInt . words <$> getLine
    let ex = length $ filter (>= 3200) l
        ans = length . group . sort $ map (`div` 400) $ filter (< 3200) l
    -- 出力
    putStrLn $ show (max ans 1) ++ " " ++ show (ans + ex)


Measured memory_bytes: 892
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
void print() {}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail){ cout << head << " \n"[sizeof...(tail) == 0]; print(forward<Tail>(tail)...);}

ll dp[1010][(1LL<<12) + 10] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll a[1010], b[1010];
    vector<ll> c[1010];
    rep(i,0,M){
        cin >> a[i] >> b[i];
        rep(j,0,b[i]){
            ll tmp;
            cin >> tmp;
            c[i].push_back(tmp);
        }
    }

    ll bit_val[1010] = {};
    rep(i,0,M){
        for(auto &e: c[i]){
            e--;
            bit_val[i] += (1LL<<e);
        }
    }

    rep(i,0,M+1){
        rep(j,0,(1LL<<N)+1){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i,0,M){
        rep(bit,0,(1LL<<N)){
            dp[i+1][bit | bit_val[i]] = min(dp[i+1][bit | bit_val[i]], dp[i][bit] + a[i]);
            dp[i+1][bit] = min(dp[i+1][bit], dp[i][bit]);
        }
    }
    ll ans = dp[M][(1LL<<N)-1];
    if(ans == INF){
        print(-1);
    }else{
        print(ans);
    }

    
}

Measured memory_bytes: 32512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vi a;
  int cnt = 0;
  rep(i, n) {
    int x;
    cin >> x;
    if (x < 0) cnt++;
    a.push_back(abs(x));
  }
  sort(ALL(a));
  ll ans = 0;
  rep(i, n) ans += (ll)a[i];
  if (cnt%2) ans -= ll(2*a[0]);
  cout << ans << endl;
}

Measured memory_bytes: 3928
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n, k := io.NextInt(), io.NextInt()
	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = io.NextInt() - 1
	}
	c := io.NextInts(n)
	ans := solve(n, k, p, c)
	io.Println(ans)
}

func solve(n, k int, p, c []int) int {
	var max int
	for i := 0; i < n; i++ {
		score := play(n, k, i, p, c)
		if i == 0 || score > max {
			max = score
		}
	}
	return max
}

func play(n, k, i int, p, c []int) int {
	score := 0
	scores := []int{}
	j := i
	for {
		score += c[p[j]]
		scores = append(scores, score)
		j = p[j]
		if j == i {
			break
		}
	}
	if k <= len(scores) {
		return Max(scores[:k]...)
	}
	if score <= 0 {
		return Max(scores[:Min(k, len(scores))]...)
	}
	q := k / len(scores)
	r := k % len(scores)
	s1 := Max(scores...)
	s2 := score
	if r != 0 {
		s2 += Max(0, Max(scores[:r]...))
	}
	score *= q - 1
	score += Max(s1, s2)
	return score
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

// Max returns max value of inputs
func Max(a ...int) (max int) {
	for i, ai := range a {
		if i == 0 || ai > max {
			max = ai
		}
	}
	return max
}

// Min returns minimum value of inputs
func Min(a ...int) (min int) {
	for i, ai := range a {
		if i == 0 || ai < min {
			min = ai
		}
	}
	return min
}


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

#define pb push_back
#define all(v) (v).begin(),(v).end()
#define ll long long int
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define sz(a) (ll)(a.size())
#define MOD 1000000007
#define fi first
#define se second
#define pii pair<ll,ll>

using namespace std;
const ll hell = (ll)(1e18+100LL);
const double pi = acos(-1.0);

int main(){
    ll t,i,j,k,m,n,x,y;
    t=1;
    //cin>>t;
    while(t--){
        ll flag=0,K;
        cin>>n>>K;
        vector<ll>ar(n+1);
        for(i=1;i<=n;i++){
            cin>>ar[i];
        }
        i = 1;
        while(i+K<=n){
            if(ar[i+K]>ar[i]){
                cout<<"Yes\n";
            }else{
                cout<<"No\n";
            }
            i++;
        }
        
    }
    return 0;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
	int l,r,d,sum=0;cin>>l>>r>>d;
	for(int i=l;i<=r;++i)
	{
		if(i%d==0) sum++;
	}
	cout<<sum;
 } 

Measured memory_bytes: 3616
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int out=0;
	bool h=false;
	rep(i,s.size()){
		int t=s.size()-i-1;
		int sum=0;
		bool H=false;
		if(s[t]!='0')H=true;
		if(s[t]!='0'&&h)s[t]--;
		rep(j,s.size())sum+=s[j]-'0';
		if(H)out=max(out,sum);
		if(s[t]!='9')h=true;
		s[t]='9';
	}
	cout<<out<<endl;
}








Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int N, M, K;
  cin >> N >> M >> K;
  for(int i=0; i<=N; i++) {
    for(int j=0; j<=M; j++) {
      if((M-j)*i+(N-i)*j == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	}

}



Measured memory_bytes: 26424
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int H, W, N;
    cin >> N >> H >> W;
    cout << (N-H+1)*(N-W+1) << endl;

    return 0;

}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"sort"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // Use Fprintf

	// CODE
	N := nextInt()
	b := nextInts(N)
	ans := []int{}
	for i := 0; i < N; i++ {
		t := pickup(&b)
		if t == -1 {
			fmt.Fprintf(out, "%v\n", -1)
			return
		}
		ans = append(ans, t)
	}
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(out, ans[i])
	}
}

func pickup(a *[]int) int {
	// fmt.Fprintf(out, "a=%v\n", a)
	r := -1
	for i := len(*a) - 1; i >= 0; i-- {
		if (*a)[i] == i+1 {
			r = (*a)[i]
			*a = append((*a)[:i], (*a)[i+1:]...)
			break
		}
	}
	return r
}

// Template

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(nextStr())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(nextStr(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = nextStr()
	}
	return ret
}

func maxInt(x int, y int) int {
	if x > y {
		return x
	}
	return y
}

func minInt(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func dummy() {
	fmt.Fprintf(out, "Hello, World\n")
	fmt.Fprintf(out, "%v", reflect.TypeOf(0))

	arr := []int{10, 9, 8, 7, 1}
	sort.Ints(arr)
	fmt.Fprintln(out, arr)
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
    int a,b,max,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a>=b && a>=c){
        max=a;
        printf("%d\n",(max*10)+b+c);
    }
    
    else if(b>=a && b>=c){
        max=b;
        printf("%d\n",(max*10)+a+c);
    }
    
    else if(c>=a && c>=b){
        max=c;
        printf("%d\n",(max*10)+b+a);
    }
    
    return 0;
}

Measured memory_bytes: 128
/*
 * @Author: BilyHurington
 * @Date: 2020-09-15 13:22:15
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-09-15 13:45:06
 */
#include<bits/stdc++.h>
using namespace std;
int n,q,m;
long long st[100010],num[100010],cnt[100010];
void add_num(int l,int r,long long t){num[l]+=t;num[r+1]-=t;}
void calc(int nxt,long long now,long long ti){
    cnt[nxt]+=ti*(now/st[nxt]);now%=st[nxt];
    int x=upper_bound(st+1,st+m+1,now)-st-1;
    if(!x) add_num(1,now,ti);
    else calc(x,now,ti);
}
int main(){
    scanf("%d %d",&n,&q);
    st[m=1]=n;long long x;
    for(int i=1;i<=q;i++){
        scanf("%lld",&x);
        while(m&&x<=st[m]) m--;
        st[++m]=x;
    }
    cnt[m]=1;
    for(int i=m;i>1;i--) calc(i-1,st[i],cnt[i]);
    for(int i=1;i<=n;i++) num[i]+=num[i-1];
    for(int i=1;i<=st[1];i++) num[i]+=cnt[1];
    for(int i=1;i<=n;i++) printf("%lld\n",num[i]);
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

vector<int> ary;
const int MAX = 999999;

void generate_prime(int max) {
	bool prime[MAX];

	for(int i = 0; i < max; i++) {
		prime[i] = true;
	}
	prime[0] = false; // 1 is not a prime number

	for(int i = 1; i < sqrt((double)max); i++) {
		if(prime[i]) {
			for(int j = i + 1; (i + 1) * j <= max; j++) {
				prime[(i + 1) * j - 1] = false;
			}
		}
	}

	for(int i = 0; i < max; i++) {
		if(prime[i]) {
			ary.push_back( i + 1 );
		}
	}
}

int main(){
	int n;
	generate_prime(MAX);

	while(cin >> n) {
		vector<int>::iterator it = ary.begin(); 
		int result = 0;

		while(it != ary.end() && *it <= n ) {
			it++;               
			result++;
		}
		cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 2564
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

struct Edge
{
	int u,v,a,b;
	Edge(int u, int v, int a, int b) : u(u),v(v),a(a),b(b) {}
};

struct Station
{
	int c,d;
	Station(int c, int d) : c(c),d(d) {}
};

signed main() {
	int n,m,s;
	std::cin >> n >> m >> s;
	std::vector<Edge> edges;
	rep(i,m) {
		int a,b,c,d;
		std::cin >> a >> b >> c >> d;
		a--;b--;
		edges.emplace_back(a,b,c,d);
	}
	std::vector<Station> nodes;
	rep(i,n) {
		int c,d;
		std::cin >> c >> d;
		nodes.emplace_back(c,d);
	}
	int X=n*2*50+1;
	std::vector<std::vector<int> > dp(n,std::vector<int>(X,INF));
	dp[0][std::min(X-1,s)]=0;
	rep(xx,n*2) {
		for(auto e:edges) {
			// connect two stations
			rep(xxx,2) {
				for(int i=0;i<X;i++) {
					if(i+e.a>=X) break;
					dp[e.v][i]=std::min(dp[e.v][i],dp[e.u][i+e.a]+e.b);
				}
				std::swap(e.u,e.v);
			}
		}
		// trade
		rep(i,n) {
			for(int j=0;j<X;j++) {
				dp[i][std::min(X-1,j+nodes[i].c)]=std::min(dp[i][std::min(X-1,j+nodes[i].c)],dp[i][j]+nodes[i].d);
			}
		}
	}
	for(int i=1;i<n;i++) {
		int min=INF;
		for(int x:dp[i]) {
			min=std::min(min,x);
		}
		print(min);
	}
	return 0;
}


Measured memory_bytes: 5288
import java.util.*;

public class Main{
    public static void main(String args[]){

      Scanner scn = new Scanner(System.in);
      int A = scn.nextInt();
      int B = scn.nextInt();
      int C = scn.nextInt();
      int D = scn.nextInt();
      
      while(A>0 || C>0){
      C=C-B;
         if(C<=0){
        System.out.println("Yes");
          break;
        }
      A=A-D;
         if(A<=0){
        System.out.println("No");
          break;
        }
      }
         }
}

Measured memory_bytes: 35724
#include<stdio.h>

int main(void)
{int i,j;
int c[3][3];
int a0[3],a1[3],a2[3];
for(i=0;i<3;i++)
{for(j=0;j<3;j++)
{scanf("%d",&c[i][j]);}}

a0[0]= c[0][2]-c[0][0];
a1[0]= c[1][2]-c[1][0] ;
a2[0]= c[2][2]-c[2][0];
a0[1]= c[0][2]-c[0][1] ;
a1[1]= c[1][2]-c[1][1] ;
a2[1]= c[2][2]-c[2][1];
a0[2]= c[0][1]-c[0][0] ;
a1[2]= c[1][1]-c[1][0] ;
a2[2]= c[2][1]-c[2][0];
for(i=0;i<3;i++)
{if(a0[i]!=a1[i]||a0[i]!=a2[i])
{printf("No");
return 0;}}
a0[0]= c[0][0]-c[2][0] ;
a1[0]= c[0][1]-c[2][1] ;
a2[0]= c[0][2]-c[2][2];
a0[1]= c[0][0]-c[1][0] ;
a1[1]= c[0][1]-c[1][1] ;
a2[1]= c[0][2]-c[1][2];
a0[2]= c[1][0]-c[2][0] ;
a1[2]= c[1][1]-c[2][1] ;
a2[2]= c[1][2]-c[2][2];
for(i=0;i<3;i++)
{if(a0[i]!=a1[i]||a0[i]!=a2[i])
{printf("No");
return 0;}}
printf("Yes");
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int solve(const char x, std::string str)
{
  const size_t k = count(begin(str), end(str), x);
  if(k == str.size()) return 0;
  if(!k) return 100000;

  {
    string val(str.size() - 1, ' ');
    for(size_t i = 0; i + 1 < str.size(); ++i)
      val[i] = str[i] == x || str[i + 1] == x ? x : str[i];

    str.swap(val);
  }

  return 1 + solve(x, str);
}

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  string str;
  cin >> str;

  const int inf = str.size() + 1000;
  int out = inf;

  for(char x = 'a'; x <= 'z'; ++x)
    out = min(out, solve(x, str));

  cout << out;
  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define fast ios_base::sync_with_stdio(false)
#define cintie cin.tie(NULL)
vi bit(200010,0);
ll query(ll x)
{
	ll res=0;
	for(;x>0;x-=x&(-x))
	res=res+bit[x];
	return res;
}
ll update(ll x,ll f)
{
	for(;x<200005;x+=x&(-x))
	bit[x]=bit[x]+f;
}
int main()
{
	    ll n,d,a,i,x,y;
		cin>>n>>d>>a;
		vpi v;
		for(i=0;i<n;i++)
		{
			cin>>x>>y;
			v.pb(mkp(x,y));
		}
		sort(v.begin(),v.end());
		vi xc;
		for(i=0;i<n;i++)
		{
			xc.pb(v[i].fs);
		}
		ll ans=0;
		ll t=0;
		ll j;
		map<ll,ll> mp;
		for(i=0;i<xc.size();i++)
		{
			mp[xc[i]]=i+1;
		}
		ll upd,div,ind;
		for(i=0;i<n;i++)
		{
			upd=query(mp[v[i].fs]);
			ll temp=v[i].se-upd*a;
			if(temp<=0)
			continue;
			div=temp/a;
			if((temp%a)!=0)
			div=div+1;
			ans=ans+max(t,div);
		//	cout<<upd<<" "<<temp<<" "<<div<<" "<<ans<<endl;
			update(mp[v[i].fs],div);
			ind=lower_bound(xc.begin(),xc.end(),v[i].fs+2*d+1)-xc.begin();
			if(ind<n)
			update(mp[v[ind].fs],-div);
		//	for(j=1;j<=3;j++)
		//	cout<<bit[j]<<" ";
		//	cout<<endl;
		}
		cout<<ans<<endl;
}

Measured memory_bytes: 19436
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
bool adj[55][55];
int a[55], b[55];
int n;

bool check(){
    for(int k=0;k<=50;k++){
        for(int i=0;i<=50;i++){
            for(int j=0;j<=50;j++){
                if(adj[i][k] && adj[k][j]) adj[i][j] = 1;
            }
        }
    }
    for(int i=1;i<=n;i++) if(!adj[a[i]][b[i]]) return 0;
    return 1;
}

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

    for(int i=1;i<=50;i++){
        for(int a=0;a<=50;a++){
            adj[a][a%i] = 1;
        }
    }
    if(!check()){
        printf("-1\n");
        return 0;
    }   

    LL ans = 0;
    vector<int> v;
    for(int i=50;i>=1;i--){
        memset(adj, 0, sizeof(adj));
        for(int a=0;a<=50;a++) adj[a][a] = 1;
        for(int j=1;j<i;j++){
            for(int a=0;a<=50;a++){
                adj[a][a%j] = 1;
            }
        }
        for(int i=0;i<v.size();i++){
            int j = v[i];
            for(int a=0;a<=50;a++){
                adj[a][a%j] = 1;
            }
        }
        if(!check()){
            ans += (1ll<<i);
            v.push_back(i);
        }
    }
    printf("%lld\n", ans);
}

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

int main() {
    int N;
    cin >> N;
    string S;
    vector<int> C(4);
 

    for (int i=0; i<N; i++){
        cin >> S;
        if (S == "AC"){
            C.at(0)++;
        }
        else if (S == "WA"){
            C.at(1)++;
        }
        else if (S == "TLE"){
            C.at(2)++;
        }
        else {
            C.at(3)++;
        }
    }

    cout << "AC x " << C.at(0) << endl; 
    cout << "WA x " << C.at(1) << endl; 
    cout << "TLE x " << C.at(2) << endl; 
    cout << "RE x " << C.at(3) << endl; 

}

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

using namespace std;

int main(void){

  int a, b, c, d, ans = 0;

  cin >> a >> b >> c >> d;

  if(a < c){
    if(b < d) ans = b-c;
    else ans = d-c;
  }
  else{
    if(b < d) ans = b-a;
    else ans = d-a;
  }
  if((a<c && a<d) && (b<c && b<d)) ans = 0;
  else if((c<a && c<b) && (d<a && d<b)) ans = 0;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	long r = read.to!long;
	long d = read.to!long;
	long x = read.to!long;
	
	foreach(i; 0 .. 10){
		x = r * x - d;
		x.writeln;
	}
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long S;
int main(){
	scanf("%lld",&S);
	if (S<=1e9){
		cout<<0<<" "<<0<<" "<<0<<" "<<1<<" "<<S<<" "<<0<<endl;
		return 0;
	}
	cout<<0<<" "<<0<<" ";
	int A=1e9;
	int B=S/A+!!(S%A);
	int C=1;
	int D=A*1ll*B-S;
	//cout<<A*B<<" "<<"wqsb"<<endl;
	cout<<A<<" "<<C<<" "<<D<<" "<<B;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0; i<N; i++)
#define lint long long
#define square_vector(name,N,M) vector<vector<lint>>name(N,vector<lint>(M,0))
#define sort(V) sort(V.begin(),V.end())

int main() {
  int A,B;
  cin >> A >> B;
  if (A > B) {
    swap(A,B);
  }
  if (B == 2) {
    cout << 3 << endl;
  }
  else if (A == 2) {
    cout << 1 << endl;
  }
  else {
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
void Rotate(string &str)
{
	char t = str[str.length() - 1];
	for (int i = str.length() - 1; i > 0; i--)
	{
		str[i] = str[i - 1];
	}
	str[0] = t;
}

int main()
{
	string str;
	string str1;
	cin >> str >> str1;
	for (int i = 0; i <= str.length(); i++)
	{
		if (str == str1)
		{
			cout << "Yes";
			return 0;
		}
		Rotate(str);
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}



int solve()
{
	ll x;cin>>x;
	rep(i,0,1005)
	{
		rep(j,0,i+1)
		{
			ll a5 = (ll)pow(i,5);
			ll b5 = (ll)pow(j,5);
			if(a5+b5==x)
			{
				cout<<i<<" "<<-1*j<<"\n";
				return 0;
			}

			if(a5-x==b5)
			{
				cout<<i<<" "<<j<<"\n";
				return 0;
			}
		}
	}





	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
 #define f first
 #define s second
 #define endl '\n'
 #define LL long long
 #define pb push_back
 #define sz(a) (int)a.size()
 #define all(a) a.begin(),a.end()
 #define rall(a) a.rbegin(),a.rend()
 #define debug(x) cerr << #x << " is " << x << endl;
 using namespace std;
 int const MAXN = 2e6 + 9;
 int main(){
    ios_base::sync_with_stdio (0),cin.tie(0);
    LL a, b;
    cin >> a >> b;
    LL g = __gcd(a,b);
    cout << (a * b) / g;
 }


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from math import factorial 
def main():
    n, m, k = map(int, readline().split())
    P = int(1e9)+7

    def C(n, m, p):
        a = 1
        for i in range(m):
            a *= (n-i)
            a %= p
        b = factorial(m)%p 
        b = pow(b, p-2, p)
        return a*b%p

    c = C(n*m-2, k-2, P)
    s_x = 0
    for d in range(1, m):
        s_x += d*(m-d)*n*n
        s_x %= P
    s_y = 0
    for d in range(1, n):
        s_y += d*(n-d)*m*m
        s_y %= P

    ans = (s_x+s_y)*c%P
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 56540
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string input;
    cin >> n >> input;
    bool flag = true;
    if(n%2==1){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(input.at(i)!=input.at(n/2+i))flag=false;
    }
    if(flag)cout<<"Yes";
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            out.print((n - 1) * (m - 1));
        }

    }

    static class InputReader {
        private int lenbuf = 0;
        private int ptrbuf = 0;
        private InputStream in;
        private byte[] inbuf = new byte[1024];

        public InputReader(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

ll n, k;
vector<ll> visited;
vector<ll> temp;
vector<ll> p, c;

ll ans = -INF;

void init(){
  visited = vector<ll>(n, 0);
}

void dfs(int i){
  if (visited[i] == 1){
    ll l = temp.size();

    ll sum = 0;
    for (int i = 0; i < l; i++){
      sum += temp[i];
    }


    if (sum < 0){
      vector<vector<ll>> dp(l, vector<ll>(l, 0));
      ll ma = -INF;
      for (int i = 0; i < l; i++){
        dp[i][0] = temp[i];
        ma = max(ma, dp[i][0]);
      }
      for (int i = 0; i < l; i++){
        for (int j = 1; j < l; j++){
          dp[i][j] = dp[i][j-1] + temp[(i+j) % l];
          ma = max(ma, dp[i][j]);
        }
      }
      ans = max(ans, ma);
    }
    else {
      ll t = (k/l) * sum;

      ll x = k % l;

      ll ma = -INF;
      ll ma2 = -INF;

      vector<vector<ll>> dp(l, vector<ll>(l, 0));
      for (int i = 0; i < l; i++){
        dp[i][0] = temp[i];
      }
      for (int i = 0; i < l; i++){
        for (int j = 1; j < l; j++){
          dp[i][j] = dp[i][j-1] + temp[(i+j) % l];
        }
      }
      for (int i = 0; i < l; i++){
        for (int j = 0; j < l; j++){
          ma = max(ma, dp[i][j]);
        }
      }
      for (int i = 0; i < l; i++){
        for (int j = 0; j < x; j++){
          ma2 = max(ma2, dp[i][j]);
        }
      }
      ans = max(ans, max(t + ma2, t - sum + ma));
    }
  }
  else {
    visited[i] = 1;
    temp.emplace_back(c[i]);
    dfs(p[i]);
  }
}

int main(void){
  cin >> n >> k;
  
  p = vector<ll>(n);
  for (int i = 0; i < n; i++){
    cin >> p[i];
    p[i]--;
  }
  c = vector<ll>(n);
  for (int i = 0; i < n; i++){
    cin >> c[i];
  }

  init();

  for (int i = 0; i < n; i++){
    if (visited[i] == 0){
      temp = vector<ll>(0);
      dfs(i);
    }
  }

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


Measured memory_bytes: 198888
fn main() {
    ioset! { inp, buf }
    macro_rules! scan {
        ($($r:tt)*) => {
            input! { inp, $($r)* }
        }
    }
    macro_rules! print {
        ($($t:expr),*) => {
            write!(buf, $($t),*).unwrap();
        } 
    }
    scan! { n: usize, l: [u64; n], }
    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            for k in (j + 1)..n {
                let mut v = [l[i], l[j], l[k]].to_vec();
                v.sort();
                if v[0] < v[1] && v[1] < v[2] && v[0] + v[1] > v[2] {
                    ans += 1;
                }
            }
        }
    }
    print!("{}\n", ans);
}

use std::io::{ stdout, BufWriter, Write };

#[macro_export]
macro_rules! ioset {
    ($inp:ident, $buf:ident) => {
        inset!($inp);
        outset!($buf);
    }
}

#[macro_export]
macro_rules! inset {
    (source = $s:expr, $iter:ident) => {
        let mut $iter = $s.split_whitespace();
    };
    ($iter:ident) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut $iter = s.split_whitespace();
    }
}

#[macro_export]
macro_rules! input {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt, $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input! { $iter, $($r)* }
    };
    ($iter:expr, mut $var:ident : $t:tt, $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input! { $iter, $($r)* }
    };
    ($iter:expr, ($var:expr) : $t:tt, $($r:tt)*) => {
        $var = read_value!($iter, $t);
        input! { $iter, $($r)* }
    };
}

#[macro_export]
macro_rules! read_value {

    // tuple
    ($iter:expr, ( $($t:tt), * )) => {
        ( $(read_value!($iter, $t)), * )
    };
    
    // array
    ($iter:expr, [ $t:tt; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    
    // string
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        $iter.next().unwrap().parse::<usize>().expect("Parse error") - 1
    };
    
    // any other
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[macro_export]
macro_rules! outset {
    ($buf:ident) => {
        let sout = stdout();
        let mut $buf = BufWriter::new(sout.lock());
    }
}

#[macro_export]
macro_rules! output {
    ($buf:expr, $($t:expr),*) => {
        write!($buf, $($t),*).unwrap();
    }
}

struct Chars<'a>(&'a Vec<char>);

impl<'a> std::fmt::Display for Chars<'a> {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
        write!(f, "{}", self.0.iter().collect::<String>())
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a[n-1] - a[0] << endl;

    return 0;
}


Measured memory_bytes: 256
def memoize(f):
    cache={}
    def helper(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]
    return helper

N = int(input())
h = list(map(int,input().split()))

import sys
sys.setrecursionlimit(1000000)

@memoize
def f(n):
    if n==1:
        return 0
    elif n==2:
        return abs(h[1]-h[0])
    elif n==3:
        return abs(h[2]-h[0])
    else:
        return min(f(n-1)+abs(h[n-1]-h[n-2]),f(n-2)+abs(h[n-1]-h[n-3]))

print(f(N))


Measured memory_bytes: 213112
//Counting of Trees

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int mpow(int a,int b,int mod){
    int ans = 1;
    rep(i,0,b)ans=(ans*a)%mod;
    if(b==0)return 0;
    else return ans;
}

signed main (){
    int n;cin>>n;
    map<int,int>m{};
    int t = 0,ans = 1;
    rep(i,0,n){
        int a;cin>>a;
        if(i==0&&a!=0){
            cout<<0<<nnn;
            return 0;
        }
        m[a]++;
        t = max(t,a);
    }
    if(m[0]!=1){
        cout<<0<<nnn;
        return 0;
    }
    rep(i,1,t+1){
        ans=(ans*mpow(m[i-1],m[i],998244353))%998244353;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 9768
days = int(input())
activities = []

for _ in range(days):
	activities.append([int(x) for x in input().split()])

a, b, c = 0, 0, 0
for x, y, z in activities:
	a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z
print(max(a, b, c))

Measured memory_bytes: 24308
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    vl t(n), a(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ret = 1;
    if (n == 1) {
        if (t[0] != a[0])
            cout << 0 << "\n";
        else
            cout << 1 << "\n";
        return 0;
    }
    if ((a[0] > a[1] && t[0] != a[0]) || (t[n - 1] > t[n - 2] && t[n - 1] != a[n - 1])) {
        cout << 0 << "\n";
        return 0;
    }

    for (int i = 1; i < n - 1; ++i) {
        if (t[i] > t[i - 1]) {
            if (t[i] > a[i]) {
                cout << 0 << "\n";
                return 0;
            }
            continue;
        }
        if (a[i] > a[i + 1]) {
            if (t[i] < a[i]) {
                cout << 0 << "\n";
                return 0;
            }
            continue;
        }
        ret = (ret * min(t[i], a[i])) % MOD;
    }
    cout << ret << "\n";
    return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long long int> a(n);
	int ans = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n > 1) {
		int k = 0;
		if (a[0] < a[1]) {
			k = 1;
		}
		else if (a[0] > a[1]){
			k = 2;
		}
		for (int i = 2; i < n; i++) {
			if (a[i - 1] < a[i]) {
				if (k == 2) {
					ans++;
					k = 0;
				}
				else {
					k = 1;
				}
			}
			else if (a[i - 1] > a[i]) {
				if (k == 1) {
					ans++;
					k = 0;
				}
				else {
					k = 2;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main(){
    int P[100000], Y[100000];
    vector<int> V[100001];
    int N,M;
    scanf("%d %d", &N, &M);

    for(int i=0; i<M; i++){
        scanf("%d %d", &P[i], &Y[i]);
        V[P[i]].push_back(Y[i]);
    }

    for(int i=1; i<N+1; i++){
        sort(V[i].begin(), V[i].end());
    }

    for(int i=0; i<M; i++){
        auto it=lower_bound(V[P[i]].begin(), V[P[i]].end(), Y[i]);
        int rank=it-V[P[i]].begin()+1;
        printf("%06d%06d\n", P[i], rank);
    }

    return 0;
}

Measured memory_bytes: 7808
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

ll NthPowerOf2(ll N){
	ll ans = 1;
	for(int i = 0; i < N; i++){
		ans *= 2;
	}
	return ans;
}

int main()
{
	ll N, K;
	cin >> N >> K;
	
	// N = 1 の場合だけ特別
	if(N == 1){
		if(K == 0){
			cout << "0 0 1 1" << endl;
		}else{
			cout << -1 << endl;
		}
		return 0;
	}
	
	// N >= 2 のとき、0〜2^N-1 で各ビットについて、1が偶数回出てくることを利用する
	if(K >= NthPowerOf2(N)){
		cout << -1 << endl;
		return 0;
	}
	
	cout << K << " ";
	ll Max = NthPowerOf2(N);
	for(int i = 0; i < Max; i++){
		if(i != K){
			cout << i << " ";
		}
	}
	cout << K << " ";
	for(int i = Max-1; i >= 0; i--){
		if(i != K){
			cout << i << " ";
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 1920