akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

int s[100001];

int main(){
	int n;
	while(cin>>n&&n){
		for(int i=0; i<n; ++i){
			cin >> s[i];
		}
		vector<P> t;
		t.push_back(P(s[0],1));
		for(int i=1; i<n; ++i){
			if((i+1)%2==0){
				if(t[t.size()-1].first!=s[i]){
					int sum=t[t.size()-1].second+1;
					t.pop_back();
					if(!(t.empty())) t[t.size()-1].second+=sum;
					else t.push_back(P(s[i],sum));
				} else{
					++t[t.size()-1].second;
				}
			} else {
				if(t[t.size()-1].first==s[i]){
					++t[t.size()-1].second;
				} else {
					t.push_back(P(s[i],1));
				}
			}
		}
		int ans=0;
		for(int i=0; i<t.size(); ++i){
			if(t[i].first==0) ans+=t[i].second;
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 1584
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,cnt=1024*1024*1024;
    cin>>n;
    for(int i=1;i*i<=n;i++){
        if(n%i!=0)continue;
        string as=to_string(i),bs=to_string(n/i);
        int m=max(as.size(),bs.size());
        cnt=min(cnt,m);
    }
    cout<<cnt<<endl;
    system("PAUSE");
}

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

using namespace std;

int n;

bool canReach(int X, vector<int> lengths) {
    int size = 2 * n + 5;
    vector<int> dp(size);
    dp[n + 1] = 1;
    for (int len : lengths) {
        vector<int> newDP(size);
        bool can = true;
        if (len < 0) can = false, len = -len;
        for (int i = 0; i < size; i++) {
            if (i + len < size) {
                newDP[i + len] |= dp[i];
            }
            if (can && i - len >= 0) {
                newDP[i - len] |= dp[i];
            }
        }
        for (int i = 0; i < size; i++) {
            dp[i] = newDP[i];
        }
    }
    return dp[X];
}
const int N = 8005;

int xS, yS;
char word[N];

int main() {
    
    scanf("%s", &word[1]);
    n = strlen(word + 1);
    
    vector<int> lengths[2];
    int curL = 0;
    int type = 0;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (word[i] == 'T') {
            if (curL > 0) {
                if (cnt == 0) curL = -curL;
                lengths[type].push_back(curL);
            }
            cnt++;
            type = 1 - type;
            curL = 0;
        } else {
            curL++;
        }
    }
    
    if (curL > 0) {
        if (cnt == 0) curL = -curL;
        lengths[type].push_back(curL);
    }
    
    for (int t = 0; t < 2; t++) {
        for (int len : lengths[t]) {
            cerr << len << " ";
        }
        cerr << endl;
    }
    
    scanf("%d %d", &xS, &yS);
    
    xS += n + 1;
    yS += n + 1;
    
    bool ans = canReach(xS, lengths[0]) && canReach(yS, lengths[1]);
    
    printf(ans ? "Yes\n" : "No\n");
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#define rep(a,i,n) for(int i=(a);i<(n);i++)
typedef long long ll;

using namespace std;

void count_seq(ll *d,const ll *s,ll n){
	rep(0,i,n){
		d[s[i]]++;
	}
}

ll count(ll *b,ll n){
	ll sum=0;
	rep(1,i,n+1){
		sum += b[i]*(b[i]-1)/2;
	}
	return sum;
}

ll selection(const ll *b,const ll *a,ll n,ll i,ll sum){
	sum = sum + (b[a[i]]-1)*(b[a[i]]-2)/2 - (b[a[i]])*(b[a[i]]-1)/2;
	return sum;
}

int main(){
	ll n;
	cin >> n;
	ll a[n],b[n+1];
	rep(0,i,n){
		cin >> a[i];
		b[i+1] = 0;
	}
	count_seq(b,a,n);
	ll sum = count(b,n);
	rep(0,i,n){
		cout << selection(b,a,n,i,sum) << endl;
	}
}

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

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=1e5+50, mod=1e9+7;

inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int dec(int x,int y) {return (x-y<0) ? (x-y+mod) : (x-y);}
inline int mul(int x,int y) {return (long long)x*y%mod;}
inline int power(int a,int b,int rs=1) {for(;b;b>>=1,a=mul(a,a)) if(b&1) rs=mul(rs,a); return rs;}
inline int cinv(int a) {return power(a,mod-2);}

int n,ans=1,fa[N],incir[N],vis[N];
int cnt[N];
vector <int> edge[N];

struct combin {
	int fac[N],ifac[N];
	combin() {
		fac[0]=1;
		for(int i=1;i<N;i++) fac[i]=mul(fac[i-1],i);
		ifac[N-1]=cinv(fac[N-1]);
		for(int i=N-2;~i;i--) ifac[i]=mul(ifac[i+1],i+1);
	}
	inline int C(int a,int b) {return (a<b) ? 0 : (mul(fac[a],mul(ifac[b],ifac[a-b])));}
} C;

inline void dfs(int x) {
	vis[x]=1; 
	for(auto v:edge[x]) {
		if(!vis[v]) fa[v]=x, dfs(v);
		else {
			for(int u=x;;u=fa[u]) {
				if(!incir[u]) incir[u]=1;
				else {puts("0"); exit(0);}
				if(u==v) break;
			}
		}
	}
}

inline int calc_dep(int x) {
	if(edge[x].size()>=2) return -1e9;
	if(!edge[x].size()) return 1;
	return calc_dep(edge[x][0])+1;
}

vector <int> cir;
vector <int> ft;
int pos[N],dep[N],f[N];

inline int calc(int x) {
	cir.clear(); ft.clear();
	int now=x;
	while(1) {
		cir.push_back(now); pos[now]=cir.size();
		vis[now]=1;
		if(edge[now].size()>=3) return 0; 
		for(auto v:edge[now]) {
			if(!incir[v]) {
				int t=calc_dep(v);
				if(t>0) ft.push_back(now), dep[now]=t;
				else return 0;
			}
		}
		for(auto v:edge[now]) if(incir[v]) {now=v; break;}
		if(now==x) break;
	}
	if(!ft.size()) return ++cnt[cir.size()],1;
	else {
		int sum=1;
		for(int i=0;i<ft.size();++i) {
			int dis=(ft.size()==1) ? cir.size() : (ft[i]==ft.back() ? cir.size()-pos[ft[i]]+pos[ft[0]] : pos[ft[i+1]]-pos[ft[i]]);
			if(dis<dep[ft[i]]) return 0;
			else if(dis>dep[ft[i]]) sum=mul(sum,2); 
		} return sum;
	}
}

int main() {
	n=rd();
	for(int i=1;i<=n;i++) 
		edge[rd()].push_back(i);
	for(int i=1;i<=n;i++)
		if(!vis[i] && edge[i].size()>=2) dfs(i);
	for(int i=1;i<=n;i++) 
		if(!vis[i]) dfs(i);
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
		if(incir[i] && !vis[i] && ans) ans=mul(ans,calc(i));
	f[0]=f[2]=1;
	for(int i=4;i<=n;i+=2) f[i]=add(f[i-2],mul(mul(i-2,i-3),f[i-4]));
	for(int i=1;i<=n;i++) {
		int sum=0;
		for(int j=0;j<=cnt[i];j+=2) {
			int tp=mul(C.C(cnt[i],j),f[j]);
			if(i!=1) {
				if(i&1) tp=mul(tp,power(2,cnt[i]-j));
				tp=mul(tp,power(i,j/2));
			} sum=add(sum,tp);
		} ans=mul(ans,sum);
	}
	cout<<ans<<'\n'; 
}

Measured memory_bytes: 13048
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long k = scanner.nextLong();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] visit = new int[n];
        visit[0] = 1;
        int loopLen = 1;
        int loopStart = 0;
        for (int i = 0; i < n; i++) {
            if (visit[a[loopStart]] != 0) {
                if (k > visit[a[loopStart]] - 1) {
                    k -= visit[a[loopStart]] - 1;
                    loopLen = visit[loopStart] + 1 - visit[a[loopStart]];
                    k = k % loopLen;
                    loopStart = a[loopStart];
                } else {
                    loopStart = 0;
                }
                break;
            } else {
                visit[a[loopStart]] = visit[loopStart] + 1;
                loopStart = a[loopStart];
            }
        }
        for (int i = 0; i < k; i++) {
            loopStart = a[loopStart];
        }
        System.out.println(loopStart + 1);
    }
}


Measured memory_bytes: 60116
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

typedef long long ll;

ll n;
ll a[205][205];
ll d[205][205];
ll mx;

int main()
{
    cin>>n;
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++)
        {
            scanf("%1lld", &a[i][j]);
            d[i][j] = a[i][j];
        }
    }
    for(ll k = 0; k < n; k++)
    {
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                if(i == k || i == j || j == k) continue;
                if(d[i][k] && d[k][j])
                {
                    if(d[i][j])
                    {
                        if((d[i][j] + d[i][k] + d[k][j]) % 2 == 1)
                        {
                            printf("-1\n");
                            return 0;
                        }
                        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                    }
                    else
                    {
                        d[i][j] = d[i][k] + d[k][j];
                    }
                }
            }
        }
    }
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++)
        {
            mx = max(mx, d[i][j]);
        }
    }
    cout<<mx + 1<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<edge>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }

vector<bool> seen;
vector<ll> dist;
void dfs(const Graph &G, int v,ll cos){

    dist.at(v) = cos;
    seen.at(v) = true;

    for(auto d : G.at(v)){
        if(seen.at(d.to)) continue;
        ll new_cos = cos + d.weight;
        dfs(G,d.to,new_cos);
    }

}

int main(){

    int n; cin >> n;
    Graph G(n);
    rep(i,n-1){
        int a,b,c; cin >> a >> b >> c;
        a--;b--;
        G.at(a).push_back(edge(b,c));
        G.at(b).push_back(edge(a,c));
    }
    int q,k; cin >> q >> k;
    k--;
    seen.assign(n,false);
    dist.assign(n,-1);
    dfs(G,k,0);

    rep(i,q){
        int x,y; cin >> x >> y;
        x--;y--;
        cout << dist.at(x)+dist.at(y) << endl;;
    }

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}

int main(){
    ll X, Y;
    cin>>X>>Y;
    if((X + Y)%3 != 0 || X*2 < Y || Y*2 < X) {
        cout<<0<<endl;
        return 0;
    }
    N = (X + Y)/3;
    K = min(X,Y) - N;
    ll ans = 1;
    rep(i,N){
        (ans *= i + 1)%=MOD;
    }
    rep(i, N - K){
        (ans *= fastpow(i + 1, MOD - 2))%=MOD;
    }
    rep(i,K){
        (ans *= fastpow(i + 1, MOD - 2))%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun next(a0: IntArray): IntArray {
        var a = a0
        var i = 0
        while (a[i] == 9 || (i + 1 < a.count() && a[i] + 1 > a[i + 1] + 1)) {
            i++
            if (a0.count() <= i) {
                a = a0 + 0
                break
            }
        }
        a[i]++
        i--
        while (i >= 0) {
            a[i] = listOf(a[i + 1] - 1, 0).max()!!
            i--
        }
        return a
    }

    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val K = sc.next().toInt()
        var n = IntArray(1) { 0 }
        for (i in 0 until K) {
            n = next(n)
//            println(n.reversed().joinToString(""))
        }
        pw.println(n.reversed().joinToString(""))
    }
}


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

int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

int main(){
    long N;
    cin >> N;
    vector<long> L(101);
    long s, l;
    for(int i = 0; i < N; ++i){
        cin >> l;
        ++L[l];
        s += l;
    }
    for(int i = (s + 1) / 2; i <= 100; ++i)
        if(L[i])return 0 & puts("No");
    puts("Yes");
    return 0;
}

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

int main() {
  int n,m,c;
  cin>>n>>m>>c;
  vector<int>b(m);
  for(int i=0;i<m;i++) cin>>b[i];
  int ans=0;
  for(int i=0;i<n;i++){
    vector<int>a(m);
    for(int i=0;i<m;i++) cin>>a[i];
    int x=c;
    for(int i=0;i<m;i++) x+=a[i]*b[i];
    if(x>0) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;

int main(){
    fastio
    int n , X ; 
    cin >> n >> X ; 
    vector<int> v(n) ; 
    for(int &x : v){
    	cin >> x ; 
    }
    if ( n == 1 ){
    	cout << abs(X-v[0]) << endl;
    	return 0 ; 
    }
    sort(v.begin(),v.end());
    debug() << imie(v) ; 
    vector<int> diff ; 
    for(int i=1;i<n;i++){
    	diff.push_back(v[i]-v[i-1]) ; 
    }
    debug() << imie(diff) ; 
    int d = v[1] - v[0] ; 
    vector<int> divisors ; 
    for(int i=1;i<=sqrt(d);i++){
    	if ( d % i == 0 ){
    		if ( d / i == i ) divisors.push_back(i) ; 
    		else {
    			divisors.push_back(d/i) ; 
    			divisors.push_back(i) ; 
    		}
    	}
    }
    sort(divisors.begin(),divisors.end()) ; 
    reverse(divisors.begin(),divisors.end()) ; 
    debug() << imie(d) ; 
    for(int div : divisors){
    	if ( d%div == 0 && abs(X-v[0]) % div == 0 ){
    		bool flag = true ; 
    		for(int c : diff){
    			if ( c % div != 0 ) {
    				flag = false ; 
    				break ; 
    			}
    		}
    		if ( flag ) {
    			cout << div << endl;
    			return 0 ; 
    		}
    	}
    }
    return 0 ;
}


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

using namespace std;

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

    int n , m;
    cin >> n >> m;

    int mx_start = -1e9 , mn_end = 1e9;
    while (m--) {
        int l , r;
        cin >> l >> r;
        mx_start = max(mx_start , l);
        mn_end = min(mn_end , r);
    }

    cout << max(0 , mn_end - mx_start + 1);
}


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

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define P pair<ll,ll>

using namespace std; 

int main(){
    int n;
    cin>>n;
    vl v(n),ans(n);
    ll sum=0,esum=0;
    pan(i,n){
        cin>>v[i];
        sum+=v[i];
        if(i%2!=0) esum+=v[i];
    }
    ans[0]=sum-2*(esum);
    for(int i=1;i<n;i++){
        ans[i]=2*v[i-1]-ans[i-1];
    }
    pan(i,n) cout<<ans[i]<<" ";
}

Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  int N,M,C; cin >> N >> M >> C;
  int B[25],A[25][25];
  for ( int j = 0; j < M; j++ ) cin >> B[j];
  for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < M; j++ ) {
      cin >> A[i][j];
    }
  }
  int ans = 0;

  for ( int i = 0; i < N; i++ ) {
    int cnt = C;
    // cout << cnt << endl;
    for ( int j = 0; j < M; j++ ) {
      cnt += A[i][j]*B[j];
    }

    if ( cnt > 0 ) ans++;
  }

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


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, M = MI()

    if N % 2 == 1:
        pairs = []
        for i in range(N//2):
            pairs.append((i+1, N-i))

        # print(pairs)
        for i in range(M):
            print(*pairs[i])
            # print((pairs[i][0] - pairs[i][1]) % N)
            # print((pairs[i][1] - pairs[i][0]) % N)
    else:
        pairs = []
        for i in range(N//2//2):
            pairs.append((i+1, N-i))

        for i in range(N//2//2+1, N//2):
            pairs.append((i+1, N-i+1))

        # print(pairs)
        for i in range(M):
            print(*pairs[i])
            # print((pairs[i][0] - pairs[i][1]) % N)
            # print((pairs[i][1] - pairs[i][0]) % N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 77492
n, m, Q = map(int, input().split())
d = [[0 for i in range(n + 1)] for i in range(n + 1)]
for i in range(m):
    l, r = map(int, input().split())
    d[l][r] += 1
for i in range(n + 1):
    for j in range(n):
        d[i][j + 1] += d[i][j]
for i in range(n + 1):
    for j in range(n):
        d[n - 1 - j][i] += d[n - j][i]
for i in range(Q):
    p, q = map(int, input().split())
    print(d[p][q])

Measured memory_bytes: 14584
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

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

using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;

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

    // count loop size
    ll loopStartOffset = 0;
    ll loopSize = 0;

    vector<ll> step(n);
    vector<bool> mark(n); // false : not reached
    
    ll next = 1;
    ll stepCount = 0;
    step[next-1] = stepCount;
    mark[next-1] = true;
    while(true)
    {
        stepCount++;
        next = a[next-1];
        if (mark[next-1] == true)
        {
            // update
            loopStartOffset = step[next-1];
            loopSize = stepCount - loopStartOffset;
            //cout << loopStartOffset << ":" << loopSize << endl;
            break;
        }
        mark[next-1] = true;
        step[next-1] = stepCount;
    }

    ll answerStep = 0;    
    if (k > loopStartOffset)
    {
        answerStep = ((k - loopStartOffset) % loopSize) + loopStartOffset;
    }
    else
    {
        answerStep = k;
    }
    //cout << "ansStep:" << answerStep << endl;

    ll answerTown = 1;
    next = 1;
    stepCount = 0;
    while(true)
    {
        if (answerStep == 0)
        {
            break;
        }
        stepCount++;
        next = a[next-1];
        if (stepCount == answerStep)
        {
            answerTown = next;
            break;
        }
    }
    cout << answerTown << endl;
    return 0;
}


Measured memory_bytes: 6428
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n;
ll W;
ll w[105],val[105];
ll dp[MAX];

int main(){FAST;
cin>>n>>W;
for(ll i=1;i<=n;++i){
  cin>>w[i]>>val[i];
}
memset(dp,-1,sizeof dp);
dp[0] = 0;
for(ll i=1;i<=n;++i){
  for(ll j=W;j>=w[i];--j){
    if(dp[j-w[i]]!=-1){
      dp[j] = max(dp[j-w[i]]+val[i],dp[j]);
    }
  }
}
cout<<*max_element(dp,dp+W+1);
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 4356
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int city = sc.nextInt();
    int way = sc.nextInt();
    
    int[] cityWay = new int[city];
 
    while(sc.hasNext()){
      int wayi = sc.nextInt();
      cityWay[wayi-1] += 1;
      }
  
  for(int i = 0; i < cityWay.length; i++){
    System.out.println(cityWay[i]);
  }
  
  }  
}

Measured memory_bytes: 35920
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;

ll gcd(ll a,ll b){
    ll M=max(a,b);
    ll m=min(a,b);
    if(m==0){
        return M;
    }
    return gcd(m,M%m);
}


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

int main(){
    int n;
    cin>>n;
    ll a;
    ll ans=1;
    for(int i=0;i<n;i++){
        cin>>a;
        ans=lcm(ans,a);

    }
    cout<<ans<<endl;

    
}

Measured memory_bytes: 3604
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long A = sc.nextInt();
		long B = sc.nextInt();
		long temp = Math.min(A, B);
		A = Math.max(A, B);
		B = temp;
		
		long result = A * B;
		
		long gcd = B;
		while(gcd != 0){
			gcd = A % B;
			A = B;
			B = gcd;
		}
		gcd = A;
		
		System.out.println(result/A);
	}
}

Measured memory_bytes: 21972
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

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

int main(void){
  int N;
  while(cin>>N){
    int p1=0,p2=0;
    if(N==0) break;
    REP(i,N){
      int n1,n2;
      cin>>n1>>n2;
      if(n1>n2){
        p1+=n1+n2;
      }else if(n1<n2){
        p2+=n1+n2;
      }else{
        p1+=n1;
        p2+=n2;
      }
    }
    cout<<p1<<" "<<p2<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

void swap(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

int main()
{
    int N, a[105];

    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
    }

    for (int i = N - 1; i > 0; --i)
    {
        for (int j = 0; j < i; ++j)
        {
            if (a[j] < a[j + 1])
            {
                swap(a[j], a[j + 1]);
            }
        }
    }

    int sumA, sumB;
    sumA = sumB = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i % 2)
        {
            sumB += a[i];
        }
        else
        {
            sumA += a[i];
        }
    }

    cout << (sumA - sumB);
    return 0;
}

Measured memory_bytes: 256
#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) { cout << #a << " = " << a << endl; }
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); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int a, b, h; cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
  
  return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define pb push_back
#define mp make_pair
#define F first
#define pf push_front
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}
vector<ll> countDivisors(ll x){
    vector<ll> v;
    for(ll i=1;i<=sqrt(x);i++){
        if(x%i==0){
        if(x/i==i){
            v.pb(i);
        }
        else{
            v.pb(i),v.pb(x/i);
        }
        }
    }
    return v;
}
int main(){
    ll n; cin>>n;
    vector<ll> v1=countDivisors(n-1);
    vector<ll> v2=countDivisors(n);
    set<ll> s;
    for(auto i:v1){
        s.in(i);
    }
    for(auto i:v2){
        ll x=n;
        if(i!=1)
        while(x%i==0) x/=i;
        
        if(x%i==1) s.in(i);
    }
    cout<<s.size()-1;
    return 0;
}


Measured memory_bytes: 384
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
count = 0
res = 0
for i in range(n):
    a = list(map(int,input().split()))
    for j in range(m):
        res += a[j]*b[j]
    if res + c > 0:
        count += 1
    res = 0
print(count)

Measured memory_bytes: 3064
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var N = Convert.ToString(int.Parse(Console.ReadLine()),2);
        var answer = Convert.ToInt32("1".PadRight(N.Length, '0'), 2);
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(ll i = 0; i < N; i++)
#define REP(i, n) for(int i = 0; i <= n; i++)
#define rrep(i,n) for(int i=n;i>0;i--)
#define RREP(i,n) for(int i=n;i>=0;i--)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int n;cin>>n;
    int p[n+1];
    rep(i,n) cin>>p[i];
    int flag=1;
    rep(i,n){
        if(p[i]==flag){
            flag++;
        }
    }
    if(flag==1) cout<<"-1"<<endl;
    else cout<<n-flag+1<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int nmax = 100005;
const ll mod = 1e4;
const ll inf = 1e9;
const ld EPS = 1e-2;
const ld PI = acos(-1.0);
const int kor = 320;
int a[205];
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0; i < n + n; ++i) cin >> a[i];
    sort(a, a + n + n);
    int cnt = 0;
    for(int i = 0; i < n + n; i += 2) cnt += a[i];
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(input())
T = list(input())

if S[0] != T[0]:
    print(-1)
    exit()

# lcmで異なる文字が重なるようならダメ。そうでなければOK


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


def lcm(a, b):
    return a * b // gcd(a, b)


l = lcm(N, M)

s = l // N
t = l // M
# print(f'{s=}, {t=}')
S_set = set([s * i for i in range(N)])
T_set = set([t * i for i in range(M)])

_set = S_set & T_set
# print(f'{S_set=}, {T_set=}, {_set=}')

for i in _set:
    if S[i // s] != T[i // t]:
        print(-1)
        exit()
print(l)
# a c p |
# a  e  |


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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

int main() {
	Boost();

	int n; cin >> n;
	vector < int > v(n);
	for (auto &x: v) cin >> x;

	for (int i = 0; i < n; ++i) {
		v[i] = v[i] - i - 1;
	}
	
	sort(v.begin(), v.end());
	
	ll sum = 0;
	for(int i = 0; i < n; ++i) {
		sum += abs(v[i] - v[n / 2]);
	}

	cout << sum;
	return 0;
}

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

int main() {
    int N;
    std::cin >> N;

    std::vector<int> map(N, 0);
    int max = int(std::sqrt(N)) + 1;

    for (int x = 1; x < max; x++) {
        for (int y = x; y < max; y++) {
            for (int z = y; z < max; z++) {
                int val = x * x + y * y + z * z + x * y + y * z + z * x;
                if (val <= N) {
                    if (x == y && y == z) {
                        map[val - 1]++;
                    } else if (x == y || y == z) {
                        map[val - 1] += 3;
                    } else {
                        map[val - 1] += 6;
                    }
                }
            }
        }
    }
    for (int i = 0; i < N; i++) {
        std::cout << map[i] << std::endl;
    }
}


Measured memory_bytes: 3568
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	n=1000-n;
	int i=0;
	while(true){
		if(n==0)
			break;
		while(true){
			if(n>=500){
				n-=500;
				break;
			}
			if(n>=100){
				n-=100;
				break;
			}
			if(n>=50){
				n-=50;
				break;
			}
			if(n>=10){
				n-=10;
				break;
			}
			if(n>=5){
				n-=5;
				break;
			}
			if(n>=1){
				n-=1;
				break;
			}
			break;
		}
		i++;
	}
	cout<<i<<endl;
	}
	return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

const string MS = "-";
void chmax(string &a, string b) {
    if (a == MS) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

ll match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10101];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M; cin >> N >> M;
    vector<int> A(M);
    rep(i, M) cin >> A[i];
    rep(i, 10101) dp[i] = MS;
    dp[0] = "";
    reps(i, N) {
        if (dp[i] == MS) continue;
        for (auto a : A) {
            chmax(dp[i+match[a-1]], dp[i] + (char)('0' + a));
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 43776
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N,D;
  cin >> N >> D;
  int cnt = 0;
  for(int i=0; i<N; i++){
    ll x,y;
    cin >> x >> y;
    if(D*D >= x*x + y*y) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifdef APURBA
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 1e9+7;
const int N = 1e5+5;
typedef pair<int,int> pii;

class Trie
{
    public:
    int ending = 0;
    Trie *child[26];

    Trie()
    {
        ending = 0;
        for(int i=0; i<26; i++)
        {
            child[i]= NULL;
        }
    }

};
void Insert(Trie *root, string &s)
{
    for(int i=0; i<s.size(); i++)
    {
        int now= s[i]-'a';
        if(root->child[now]==NULL)
        {
            root->child[now] = new Trie();
        }
        root= root->child[now];
    }
    root->ending++;
}
int query(Trie *root, string &s)
{
    int ans =0;
    vector<int>ache(26,0);
    for(int i=s.size()-1;i>=0;i--)
    {
        ache[s[i]-'a']++;
    }

    for(int i=0; i<s.size(); i++)
    {
        int now= s[i]-'a';
        for(int j=0;j<26;j++)
        {
            if(ache[j] && root->child[j]!=NULL && root->child[j]->ending)
            {
                ans++;
            }
        }
        ache[now]--;
        root= root->child[now];
    }
    return ans-1;
}
void TEST_CASES(int cas)
{
    int n;
    scanf("%d",&n);
    Trie *t = new Trie();
    vector<string >s(n);
    for(int i=0; i<n; i++)
    {
        cin>>s[i];
        reverse(s[i].begin(),s[i].end());
        Insert(t,s[i]);
    }
    int ans =0;
    for(int i=0;i<s.size();i++)
    {
        ans+= query(t,s[i]);
    }
    printf("%d\n",ans);


}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}



template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


Measured memory_bytes: 223732
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  int ans=0;
  for(int i=1;i<N;i++){
    if(A[i]>A[i-1]) ans++;
  }
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define MAX 100005
using namespace std;
int a[MAX],b[3];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    int ans=0;
    for(int i=2;i<n;i++){
        if((a[i-1]>=a[i-2] && a[i-1]<=a[i] )|| (a[i-1]<=a[i-2] && a[i-1]>=a[i]))
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


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

long long int money(int x){
    if(x == 1){
        return 101;
    } else {
        return floor((double)money(x - 1) * 1.01);
    }
}

int main(){
    long long int x;
    long long int i = 1;
    cin >> x;
    while(true){
        if(money(i) >= x){
            cout << i << endl;
            return 0;
        }
        i++;
    }
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
string S;
bool b=true,c=true;
int main(){
  cin>>S;
  int a=S.size();
  for(int i=0;i<a;i++){
    if(i%2==0 && S.at(i)=='L'){
      b=false;
    }
    if(i%2==1 && S.at(i)=='R'){
      c=false;
    }
  }
  if(b==true&&c==true)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const int INF = 0x3f3f3f3f;

int x[1000123];

int main()
{
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        scanf("%d", &a);
        ++x[a];
    }
    int ans = 0;
    Rep(i, 1000000) if(x[i]) {
        ans += x[i] == 1;
        for(int j = i*2; j <= 1000000; j += i) x[j] = 0;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int,int>;

int main(){
    int k,x;
    cin >> k >> x;
    if (500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
  ll n;cin >> n;
  deque<string> g(n);
  rep(i,n)cin >> g[i];
  ll ans=0;
  rep(i,n){
    bool check=true;
    rep(j,n){
      rep(k,n){
        if(g[j][k]!=g[k][j])check=false;
      }
    }
    if(check)ans+=n;
    string s=g[0];
    g.pop_front();
    g.pb(s);
  }
  cout <<ans <<endl;
}

Measured memory_bytes: 384
n = int(input().strip())
a = list(map(int, input().strip().split()))
b=[0]*n
for i in range(0,n-1):
    b[i]=a[i+1]/a[i]
money=1000
for i in range(n):
    if b[i]>1:
        money=(money//a[i])*a[i+1]+(money%a[i])
print(money)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n, m, c;
  cin >> n >> m >> c;
  vector<ll> B(m);
  rep(i,m) cin >> B[i];
  int ans = 0;
  rep(q,n) {
    ll res = 0;
    rep(i,m) {
      ll a;
      cin >> a;
      res += a*B[i];
    }
    res += c;
    if (res > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int N; cin >> N;
	vector<int>a(N);
	long long ans = 0;
	bool flag = true;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if(a[i] % 2)flag = false;
	}

	cout<<(flag ? "second":"first")<<endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> F(N,vector<int>(10));
  vector<vector<int>> P(N,vector<int>(11));
  rep(i, 0, N) rep(j, 0, 10) cin >> F[i][j];
  rep(i, 0, N) rep(j, 0, 11) cin >> P[i][j];
  ll ans = -1e18;
  rep(i, 1, 1 << 10) {
    ll tmp = 0;
    rep(j, 0, N) {
      int cnt = 0;
      rep(k, 0, 10) if(i & (1 << k) && F[j][k]) cnt++;
      tmp += P[j][cnt];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(lambda x: int(x), input().split())
dx = tx - sx
dy = ty - sy
s = 'U' * dy + 'R' * dx
s += 'D' * dy + 'L' * dx
s += 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
s += 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define maxn 100005
#define inf (1<<30)
#define mod 1000000007
using namespace std;
typedef long long LL;
LL read()
{
	char c=getchar();LL f=1,sum=0;
	while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
LL n,k;
int main()
{
	n=read();k=read();
	if(k&1)
	{
		LL num=n/k;
		printf("%lld\n",num*num*num);
	}
	else
	{
		LL a=n/k;
		k>>=1;
		LL b=n/k;
		b-=a;
		printf("%lld\n",a*a*a+b*b*b);
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC109B
int main(void) {
  int n, i, len;
  scanf(" %d", &n);
  char w[n][11];
  for(i=0; i<n; i++)
    scanf(" %s", w[i]);


  for(i=0; i<n-1; i++){
    for(len=0; w[i][len]!='\0'; ++len)
      ; //文字数
    if(w[i][len-1]!=w[i+1][0]){
      printf("No");
      return 0;
    }
  }
  qsort(w, n, sizeof(char)*11, strcmp); //文字列ソート

  for(i=0; i<n-1; i++){
    if(strcmp(w[i], w[i+1])==0){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 128
# coding: utf-8


def main():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]

    for i in range(1, N):
        A[0][i] += A[0][i - 1]
        A[1][N - i - 1] += A[1][N - i]

    ans = max([A[0][i] + A[1][i] for i in range(N)])

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 3001
using namespace std;
bool bzs[N],bzw[N];
int a,b,c,d,e,f,ans1,ans2;
int main(){
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	bzs[0]=bzw[0]=1;
	a*=100,b*=100;
	for (int i=1;i<=f;i++){
		if (i>=a)bzw[i]|=bzw[i-a];
		if (i>=b)bzw[i]|=bzw[i-b];
		if (i>=c)bzs[i]|=bzs[i-c];
		if (i>=d)bzs[i]|=bzs[i-d];
	}
	for (int i=0;i<=f;i++)
		if (bzw[i])
		for (int j=i/100*e;j>=0;j--)
			if (bzs[j]){
				if ((i+j<=f)&&(j*ans1>=ans2*(i+j)))ans1=i+j,ans2=j;
			}
	printf("%d %d\n",ans1,ans2);
	return 0;
}

Measured memory_bytes: 256