akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"strings"
)

type ll int64

type part_time_job struct {
	days ll
	paid ll
}

type Bydays []part_time_job
func (a Bydays) Len() int           { return len(a) }
func (a Bydays) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Bydays) Less(i, j int) bool { return a[i].days <  a[j].days }

type Bypaid []part_time_job
func (a Bypaid) Len() int           { return len(a) }
func (a Bypaid) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Bypaid) Less(i, j int) bool { return a[i].paid > a[j].paid }


func main() {

	var S,SS string
	fmt.Scan(&S,&SS)

	var ans = 0

	s := strings.Split(S, "") //[]stringに一文字ずつ格納
	ss := strings.Split(SS, "") //[]stringに一文字ずつ格納

	for i := 0 ; i< len(s); i++ {
		if s[i] == ss[i] {
			ans++
		}
	}

	fmt.Println(ans)



}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000; // 十分大きな値

int main(){
    ll x;
    cin >> x;

    bool flag = false;
    while(!flag){
        flag = true;
        for(int i = 2;i < x;i++){
            if(x % i == 0){ 
                x++;
                flag = false;
                break;
            }
        }
        
    }
    if(flag) cout << x << endl;
    else cout << x << endl;
}


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

int main(){
	cin >> k >> x;

	for(int i = max(-1000000, x - k + 1); i <= min(1000000, x + k - 1); i++){
		cout << i << ' ';
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#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<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

int main() {
    int N; cin >> N;
    vll A(N), B(N);
    rep(i, N) {
        cin >> A[N-1-i] >> B[N-1-i];
    }

    vll dp(N); 
    if (A[0] % B[0] == 0) {
        dp[0] = 0;
    }
    else {
        dp[0] = B[0] - (A[0] % B[0]);
    }

    for (int i = 1; i < N; i++) {
        if ( ((A[i] + dp[i - 1]) % B[i]) == 0) {
            dp[i] = dp[i - 1];
        }
        else {
            dp[i] = dp[i - 1] + B[i] - ((A[i] + dp[i - 1]) % B[i]);
        }

    }

    cout << dp[N - 1] << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 4e5 + 5;
const int MOD = 1e9 + 7;

int n, m, k;
int fact[N], invfact[N];

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
}

int nCr(int x, int y)
{
	if(y>x)
		return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}


int32_t main()
{
	IOS;
	cin >> n >> m >> k;
	precompute();
	int ans = 0;
	int always = nCr(n * m - 2, k - 2);
	for(int dist = 1; dist <= n - 1; dist++)
	{
		int cur = dist;
		int pairs = m * m;
		pairs %= MOD;
		pairs *= (n - dist);
		pairs %= MOD;
		cur *= pairs;
		cur %= MOD;
		cur *= always;
		cur %= MOD;
		ans += cur;
		ans %= MOD;
	}
	for(int dist = 1; dist <= m - 1; dist++)
	{
		int cur = dist;
		int pairs = n * n;
		pairs %= MOD;
		pairs *= (m - dist);
		pairs %= MOD;
		cur *= pairs;
		cur %= MOD;
		cur *= always;
		cur %= MOD;
		ans += cur;
		ans %= MOD;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

const int maxn = 2e5 + 5;

int n, m;

int l[maxn], r[maxn];
typedef long long LL;
LL a[maxn];
LL score[maxn];

LL maxv[maxn << 2];
LL addv[maxn << 2];
#define lson o*2,l,mid
#define rson o*2+1,mid+1,r

void pushup(int o){
    maxv[o] = max(maxv[o*2],maxv[o*2+1]);
}

void pushdown(int o){
    if(addv[o]){
        addv[o*2] += addv[o];
        addv[o*2+1] += addv[o];
        maxv[o*2] += addv[o];
        maxv[o*2+1] += addv[o];
        addv[o] = 0;
    }
}

void build(int o, int l, int r){
    maxv[o] = 0;
    addv[o] = 0;
    if(l == r)
        return;
    int mid = (l + r) / 2;
    build(lson);
    build(rson);
}

void update(int o, int l, int r, int ql, int qr, LL v){
    if(ql <= l && r <= qr){
        maxv[o] += v;
        addv[o] += v;
        return;
    }
    int mid = (l + r) / 2;
    pushdown(o);
    if(ql <= mid)
        update(lson, ql, qr, v);
    if(qr > mid)
        update(rson, ql, qr, v);
    pushup(o);
}

LL querymax(int o, int l, int r, int ql, int qr){
    if(ql > qr)
        return 0;
    if(ql <= l && r <= qr){
        return maxv[o];
    }
    int mid = (l + r) / 2;
    pushdown(o);
    if(qr <= mid)
        return querymax(lson, ql, qr);
    if(ql > mid)
        return querymax(rson, ql, qr);
    return max(querymax(lson, ql, qr), querymax(rson, ql, qr));
}

vector<int> in[maxn], out[maxn];

LL dp[maxn];

int main(){
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        scanf("%d%d%lld", &l[i], &r[i], &a[i]);
        score[l[i]] += a[i];
        score[r[i] + 1] -= a[i];
        in[l[i]].push_back(i);
        out[r[i] + 1].push_back(i);
    }
    score[0] = 0;
    for(int i = 1;i <= n;i++){
        score[i] += score[i - 1];
    }
    for(int i = 1;i <= n;i++){
        for(auto id : out[i]){
            update(1, 1, n + 1, l[id] + 1, r[id] + 1, a[id]);
        }
        for(auto id : in[i]){
            update(1, 1, n + 1, l[id] + 1, r[id] + 1, -a[id]);
        }
        dp[i] = querymax(1, 1, n + 1, 1, i) + score[i];        
        update(1, 1, n + 1, i + 1, i + 1, dp[i]);
    }
    LL ans = 0;
    for(int i = 1;i <= n;i++){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 40832
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  int x,y;
  cin >> x >> y;

  lint result = 0;
  if(x <= 3) result += 100000 * (4-x);
  if(y <= 3) result += 100000 * (4-y);
  if(x == 1 && y == 1) result += 400000;

  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 256
(N,),*A=$<.map{_1.split.map &:to_i}
d=1,-1,*[0]*5e5
N.times{|i|T=d[i]%=998244353
d[i+1]+=T
A.map{d[i+_1]+=T
d[i+_2+1]-=T}}
p T

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

const long long INF = 1LL << 60;

int main() {
    int N, M, L;
    std::cin >> N >> M >> L;

    std::vector<std::vector<long long>> dist(
        N,
        std::vector<long long>(N, INF)
    );

    for (int i = 0; i < M; ++i) {
        int A, B, C;
        std::cin >> A >> B >> C;
        --A;
        --B;
        dist[A][B] = C;
        dist[B][A] = C;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                long long &d = dist[i][j];
                d = std::min(d, dist[i][k] + dist[k][j]);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            long long &d = dist[i][j];
            d = d <= L ? 1 : INF;
        }
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                long long &d = dist[i][j];
                d = std::min(d, dist[i][k] + dist[k][j]);
            }
        }
    }

    int Q;
    std::cin >> Q;
    
    for (int i = 0; i < Q; i++) {
        int s, t;
        std::cin >> s >> t;
        --s;
        --t;
        long long &d = dist[s][t];
        std::cout << (d == INF ? -1 : d - 1) << "\n";
    }
}

Measured memory_bytes: 1280
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 99999999

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

void shortestPath(Graph &g, int s,
    map<int,Weight> &dist, map<int,int> &prev) {
  for(auto &f:g)dist[f.first]=INF; dist[s] = 0;
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev.find(e.dst) != prev.end()) continue;
    prev[e.dst] = e.src;
    for(auto &f:g[e.dst]) {
      if (dist[f.dst] > e.weight+f.weight) {
        dist[f.dst] = e.weight+f.weight;
        Q.push(Edge(f.src, f.dst, e.weight+f.weight));
      }
    }
  }
}

char buf[101];
int W;
int coor(int x,int y){return (y)*(W*2+2)+x;}
int main(){
	int H,N,X1,Y1,X2,Y2;
	scanf("%d%d%d%d%d%d%d",&W,&H,&N,&X1,&Y1,&X2,&Y2);
	X1=coor(X1*2,Y1*2),X2=coor(X2*2,Y2*2);
	vector<vector<int> >m(H*2+1);
	for(auto &&e:m)e.resize(W*2+1);
	for(int i=0;i<N;i++){
		int x,y,t,l;
		scanf("%d%d%d%s",&x,&y,&t,buf);
		l=strlen(buf);
		x=2*x+1,y=2*y+1;
		for(int j=0;j<t;j++){
			for(int k=0;k<l;k++){
				int c=buf[k];
				if(c=='L'&&1<x)m[y][x-1]++,x-=2;
				if(c=='U'&&1<y)m[y-1][x]++,y-=2;
				if(c=='R'&&x<W*2-1)m[y][x+1]++,x+=2;
				if(c=='D'&&y<H*2-1)m[y+1][x]++,y+=2;
			}
		}
	}
	//puts("a");
	Graph g;
	for(int h=0;h<=H*2;h+=2)for(int w=0;w<=W*2;w+=2){
		int a=coor(w,h),b;
		if(h<H*2-1)b=coor(w,h+2),g[a].push_back(Edge(a,b,m[h+1][w])),g[b].push_back(Edge(b,a,m[h+1][w]));
		if(w<W*2-1)b=coor(w+2,h),g[a].push_back(Edge(a,b,m[h][w+1])),g[b].push_back(Edge(b,a,m[h][w+1]));
	}
	map<int,Weight> dist;
	map<int,int> prev;
	//puts("b");
	shortestPath(g,X1,dist,prev);
	printf("%d\n",dist[X2]);
}

Measured memory_bytes: 66568
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
string S;

ll dfs(int cur_pos, int prev_delim, ll sum) {
  if (cur_pos == S.length()) {
    string sub = S.substr(prev_delim, cur_pos - prev_delim);
    return sum + atoll(sub.c_str());
  }
  ll ret = 0;
  ret += dfs(cur_pos + 1, prev_delim, sum);
  string sub = S.substr(prev_delim, cur_pos - prev_delim);
  ll new_sum = sum + atoll(sub.c_str());
  ret += dfs(cur_pos + 1, cur_pos, new_sum);
  return ret;
}

int main() {
  cin >> S;
  ll ans = dfs(1, 0, 0);
  cout << ans << endl;
  return 0;
}

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

int main(){
    int N,M;cin >> N >> M;
    vector<int> x(M);

    rep(i,M){
        cin >> x[i];
    }
    if(N>=M){
        cout << "0" << endl;
        return 0;
    }
    sort(x.begin(),x.end());
    vector<int> l(M-1);
    int ans = 0;
    rep(i,M-1){
        l[i] = abs(x[i+1]-x[i]);
        ans += l[i];
    }
    sort(l.begin(),l.end());
    rep(i,N-1){
        ans -= l.back();
        l.pop_back();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main () {
  map<int,int> mp;
  for(int i=0;i<4;i++){
    int n;
    cin>>n;
    mp[n]++;
  }
  if (all_of(mp.begin(),mp.end(),[](auto &p){
    auto& [key,val]=p;
    return val==1&&(key==1||key==7||key==9||key==4);
  })) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 3636
from sys import exit
n=int(input())
H=list(map(int,input().split()))
H[0] -= 1
for i in range(n-1):
	if H[i]>H[i+1]:
		print("No")
		exit()
	elif H[i]!=H[i+1]:
		H[i+1] -= 1
print("Yes")

Measured memory_bytes: 14252
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <deque>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 100000;

/*
1 3 2 4 = 5

1 4 2 3 = 6

3 1 4 2 = 7

1 2 3 4 5

1 5 2 4 3  = 4 + 3 + 2 + 1 = 10

1 5 3 2 4  = 4 + 2 + 1 + 2 = 9

1 2 3 4 5 6
3 5 1 6 2 4
*/

int n;
deque <LL> d;
LL a[MaxN + 5], b[MaxN + 5];

void Solve() {
	int t = 0;
	for(int i = 1; i <= n / 2; i++) {
		if(t == 0) {
			d.push_front(a[i]);
			d.push_back(a[n - i + 1]);
		}
		else {
			d.push_front(a[n - i + 1]);
			d.push_back(a[i]);
		}
		t = t ^ 1;
	}
	int tot = 0;
	while(!d.empty()) {
		b[++tot] = d.front();
		d.pop_front();
	}
	LL ans = 0LL;
	for(int i = 1; i < tot; i++) ans += abs(b[i] - b[i + 1]);
	if(n & 1) ans += max(abs(a[(n + 1) / 2] - b[1]), abs(a[(n + 1) / 2] - b[tot]));
	printf("%lld\n", ans);
}

int main()
{
	while(scanf("%d", &n) != EOF) 
	{
		for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
		sort(a + 1, a + n + 1);
		Solve();
	}
	return 0;
}

Measured memory_bytes: 2688
until (a = $<.gets.split.map(&:to_i)) == [0, 0, 0]
  $<.gets.to_i.times.map {$<.gets.to_i}.each do |r|
    result = a.combination(2).map do |w, h|
      Math.sqrt((w / 2.0) ** 2 + (h / 2.0) ** 2) < r
    end.any?
    puts result ? "OK" : "NA"
  end
end



Measured memory_bytes: 6908
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define alint(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int prime[1000010]; 
bool is_prime[1000011];

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

int main(){
	int a,d,n;
	sieve(1000001);
	while(1){
		cin>>a>>d>>n;
		if(a==0 && d==0 && n==0) break;
		int ans=0;
		for(int i=a;;i+=d){
			if(is_prime[i]) ans++;
			if(ans==n){
				o(i);
				break;
			}
		}
	}
}

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

int main(){
  int d,n,m;
  while(cin >> d,d){
    cin >> n >> m;
    int nv[n+1];
    int sum = 0;
    nv[0] = 0;
    nv[n] = d;
    for(int i=1; i<n; ++i){
      int tmp;
      cin >> tmp;
      nv[i] = tmp;
    }
    sort(nv,nv+n);
    for(int i=0; i<m; ++i){
      int tmp;
      int left = 0;
      int right = n;
      cin >> tmp;
      while(right >= left){
        int mid = left + (right - left)/2;
        //cout << "mid=" << mid << endl;
        if(nv[mid]<= tmp && nv[mid+1]>=tmp){
          int add = min({tmp-nv[mid],nv[mid+1]-tmp,tmp,d-tmp});sum+=add;
          //cout << "add=" << add << endl;
          break;
        }
        if(nv[mid]>tmp){
          right = mid-1;
            }else if(nv[mid]<tmp){
          left = mid+1;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}




Measured memory_bytes: 3548
#include<iostream>
#include<string>
using namespace std;
int prime[100000];
int main(){
	int count=0;
	for(int i=6;i<300000;i++){
		if(i%7==1||i%7==6){
			bool t=true;
			for(int j=0;j<min(107,count);j++){
				if(i%prime[j]==0)
					t=false;
			}
			if(t==true){
				prime[count]=i;
				count++;
			}
		}
	}
	int n;
	while(true){
		cin>>n;
		if(n==1)
			break;
		cout<<n<<":";
		for(int i=0;i<count;i++){
			if(n%prime[i]==0)
				cout<<" "<<prime[i];
		}
		cout<<endl;
	}
	return 0;
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
  }
  
  std::vector<int64_t> f(n);  // f(i):在第i天，手里最多能有多少钱.
  f[0] = 1000;
  for (int i = 1; i < n; ++i) {
    f[i] = f[i - 1];
    for (int j = 0; j < i; ++j) {
      int64_t cur = f[j] / a[j] * a[i] + f[j] % a[j];
      if (cur > f[i]) f[i] = cur;
    }
  }
  std::cout << f[n - 1] << std::endl;
  return 0;
}

Measured memory_bytes: 3632
# ABC090 C - Flip,Flip, and Flip......
n,m = map(int,input().split())

if m==1 and n==1:
    print(1)
elif m!=1 and n==1:
    print(m-2)
elif m==1 and n!=1:
    print(n-2)
else:
    print((m-2)*(n-2))

Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL){
    if(u->key == k)return u;
    else if( u->key > k)u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL)
    return treeMinimum(x->right);
  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL){
    y = z; /* zが子を最大１つ持つ場合は入力節点のz */
  }
  else y = treeSuccessor(z);/* z が子を2つ持つ場合はzの次節点 */
  
  /*xをyのNILではない子またはyが子を持たない場合はNILに設定 */
  
  if(y->left != NIL){
    x = y->left;
  }
  else x = y->right;
  
  /*yの親とxのポインタを変更しyを削除する*/
  
  if(x != NIL){
    x->parent = y->parent;       /* yが子を１つ持つ場合 */
  }
  if(y->parent == NIL){
    root = x;                  /* yが根のときの境界条件を処理*/  
  }            
  else if(y == y->parent->left) {  
    y->parent->left = x;               /* y が左の子の場合 */
  }
  else y->parent->right = x;               /* y が右の子の場合 */
  
  
  /* zの次節点が削除されたときにyの内容をzに移動する*/
  if(y != z){
    z->key = y->key;
  }
}



void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right;
  }

  z->parent = y;
  if(y == NIL) {
    root = z;  
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else y->right = z;
}


void inorder(Node u){
  if(u->left != NIL){
    inorder(u->left);
  }
  printf(" %d",u->key);
  if(u->right != NIL){
    inorder(u->right);
  }

}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!= NIL){
    preorder(u->left);
  }
  if(u->right!= NIL){
    preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	ll n,m;cin>>n>>m;
	vector<pii>v;
	rep(i,0,n){
		ll x;cin>>x;v.pb({x,1});
	}
	rep(i,0,m){
		ll b,c;cin>>b>>c;v.pb({c,b});
	}
	sort(v.rbegin(),v.rend());
	ll ans=0,cnt=0;
	rep(i,0,sz(v)){
		if(cnt+v[i].se<=n) ans+=v[i].se*v[i].fi,cnt+=v[i].se;
		else ans+=v[i].fi*(n-cnt),cnt=n;
		if(cnt==n)break;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 6256
N = int(input())
S = list(input())
ans = 0
n_ans = 0
for i in range(N):
  if(S[i]=='I'):
    n_ans += 1
    ans = max(ans, n_ans)
  else:
    n_ans -= 1
    ans = max(ans, n_ans)
print(ans)

Measured memory_bytes: 9100
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		List<Integer> A1 = new ArrayList<>();
		List<Integer> A2 = new ArrayList<>();
		List<Integer> A3 = new ArrayList<>();

		List<Integer> b = new ArrayList<>(Arrays.asList(0, 1, 2));
		List<Integer> c = new ArrayList<>(Arrays.asList(3, 4, 5));
		List<Integer> d = new ArrayList<>(Arrays.asList(6, 7, 8));
		List<Integer> e = new ArrayList<>(Arrays.asList(0, 3, 6));
		List<Integer> f = new ArrayList<>(Arrays.asList(1, 4, 7));
		List<Integer> g = new ArrayList<>(Arrays.asList(2, 5, 8));
		List<Integer> h = new ArrayList<>(Arrays.asList(2, 4, 6));
		List<Integer> j = new ArrayList<>(Arrays.asList(0, 4, 8));

		List<List<Integer>> all = new ArrayList<>();
		Collections.addAll(all, b, c, d, e, f, g, h, j);

		for (int i = 1; i <= 9; i++) {
			int a = sc.nextInt();
			A1.add(a);
		}

		int a = sc.nextInt();
		for (int i = 1; i <= a; i++) {
			int bb = sc.nextInt();
			A2.add(bb);
		}

		int ee = 0;
		for (int m = 0; m <= a - 1; m++) {
			ee = A1.indexOf(A2.get(m));
			if (ee != -1) {
				A3.add(ee);
			}
		}

		for (List<Integer> ele : all) {
			if (A3.containsAll(ele)) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 23892
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Coerce (coerce)
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VU.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VU.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: Int -> VU.Vector Int16 -> Int32
solve n hs = uread (n - 1) dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp :: VUM.IOVector Int32
  dp = VU.foldl'
    (\(!dp) (!i, !v) -> if i == 0
      then uwrite 0 0 dp
      else if i == 1
        then uwrite 1 (uread 0 dp + abs (fromIntegral $ v - hs VU.! 0)) dp
        else uwrite
          i
          (min (uread (i - 1) dp + abs (fromIntegral $ v - hs VU.! (i - 1)))
               (uread (i - 2) dp + abs (fromIntegral $ v - hs VU.! (i - 2)))
          )
          dp
    )
    (unew n)
    (VU.indexed hs)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n hs


Measured memory_bytes: 2300
#include <stdio.h>
int main(void){
    
    int a, b, op, x;
    
    while(1){
        scanf("%d %c %d\n", &a, &op, &b);
        if ( op == '+' ){
            x = a + b;
        } else if ( op == '-' ){
            x = a - b;
        } else if ( op == '*' ){
            x = a * b;
        } else if ( op == '/' ){
            x = a / b;
        }
        if (op == '?')   break;
        printf("%d\n", x);
    }
    
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#include <ext/pb_ds/assoc_container.hpp> // Used to include policy based data structure 
using namespace __gnu_pbds;  // Only for g++ compiler
using namespace std;

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define max(a, b)  (a > b) ?a :b  // max of 2 elements 
#define min(a, b)  (a < b) ?a :b  // min of 2 elements

//short hand for usual tokens
#define pb              push_back
#define fi              first
#define se              second
#define mp              make_pair
#define mii             map<int,int>
#define pqb             priority_queue<int>   // Max Heap
#define pqs             priority_queue<int,vi,greater<int> >   // Min Heap
#define setbits(x)      __builtin_popcountll(x)   // returns the number of set bits in the binary representation of x
#define zrobits(x)      __builtin_ctzll(x)   // returns the number of zeroes before the first set bit in the binary representation of x       
#define mod             1000000007   // 1e9 + 7   
#define inf             1e18   // pow(10, 18)  
#define mk(arr,n,type)  type *arr=new type[n];   // generates a dynamic array
#define w(x)            int x; cin>>x; while(x--)   // for taking test cases 
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());   // used with shuffle

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;   // Used to implement policy-based data structure

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    
    int a;
    cin>>a;
    int ans = (a + pow(a, 2) + pow(a, 3));
    cout<<ans;
  
    return 0;
}


Measured memory_bytes: 4084
#include <stdio.h>
#include <stdlib.h>
int main(){
       char s[150];
       int count=0;
       scanf("%s",s);
       for(int i=0;s[i]!='\0';i++){
              if(i==0) printf("%c",s[i]);
              else if(s[i+1]=='\0'){
                     printf("%d%c",count,s[i]);
                     break;
              }
              else count++;
       }
       return 0;
}


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

using namespace std;

#define MAX 10000
#define INFTY (1 << 29)

class DisjointSet{
public:
  vector<int> rank, p;

  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) {
      makeSet(i);
    }
  }

  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }

  bool same(int x, int y) {
    return findSet(x) == findSet(y);
  }

  void unite(int x, int y) {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }

  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

class Edge {
public:
  int source, target, cost;
  Edge(int source = 0, int target = 0, int cost = 0)
    : source(source)
    , target(target)
    , cost(cost) {}

  bool operator < (const Edge& e) const {
    return cost < e.cost;
  }
};

int kruskal(int N, vector<Edge> edges) {
  int totalCost = 0;
  sort(edges.begin(), edges.end());

  DisjointSet dset = DisjointSet(N + 1);

  for (int i = 0; i < N; i++) {
    dset.makeSet(i);
  }

  int source, target;
  for (int i = 0; i < edges.size(); i++) {
    Edge e = edges[i];
    if (!dset.same(e.source, e.target)) {
      totalCost += e.cost;
      dset.unite(e.source, e.target);
    }
  }
  return totalCost;
}

int main() {
  int N, M, cost;
  int source, target;

  cin >> N >> M;

  vector<Edge> edges;
  for (int i = 0; i < M; i++) {
    cin >> source >> target >> cost;
    edges.push_back(Edge(source, target, cost));
  }

  cout << kruskal(N, edges) << endl;

  return 0;
}



Measured memory_bytes: 5192
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

int main(void){

  int length = 0;
  bool judge = true;

  int N;
  scanf("%d", &N);

  char W[100][11];
  for(int i = 0 ; i < N ; i++){
    scanf("%s",W[i]);
  }

  
  for(int i = 0 ; i < N - 1 ; i++){
    length = strlen(W[i]);
    if(W[i][length - 1] != W[i + 1][0])   judge = false;
  }

  for(int i = 1 ; i < N ; i++){
    for(int j = 0 ; j < i ; j++){
      if(strcmp(&W[i],&W[j]) == 0){
			judge = false;
			break;
      }
    }
    
    if(judge == false)   break;

  }


  if(judge)     puts("Yes");
  else          puts("No");

  return 0;
}

Measured memory_bytes: 128
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 998244353;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;

set<int> st;
int freq[N];

signed main(){
    fastio;
    int i,n,m,p,pen=0;
    cin>>n>>m;
    string s;
    for(i=0;i<m;++i){
        cin>>p>>s;
        if(s=="AC"){
            if(st.find(p)!=st.end()){
                continue;
            }
            pen+=freq[p];
            st.insert(p);
        }
        else freq[p]++;
    }
    cout<<st.size()<<" "<<pen;
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	string s;
	cin >> s;
	if(s == "AAA" || s == "BBB")
	{
		cout << "No\n";
	}
	else
	{
		cout << "Yes\n";
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    AB = []
    for a in A:
        for b in B:
            AB.append(a + b)
    AB.sort(reverse=True)
    C.sort(reverse=True)
    ret = []
    idx = [0] * Z
    for i in range(K):
        tmp = -1
        cur = -1
        for j in range(Z):
            if idx[j] < len(AB) and C[j] + AB[idx[j]] > tmp:
                tmp = C[j] + AB[idx[j]]
                cur = j
        ret.append(tmp)
        idx[cur] += 1
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 55388
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        final int K = sc.nextInt();
        
        final int[] Ps = new int[N];
        for (int i = 0; i < N; i++) {
            Ps[i] = sc.nextInt() - 1;
        }
        
        final long[] Cs = new long[N];
        for (int i = 0; i < N; i++) {
            Cs[i] = sc.nextLong();
        }
        
        long maxScore = Long.MIN_VALUE;
        final long[][] scores = new long[N][N];
        
        for (int i = 0; i < N; i++) {
            int p = Ps[i];
            scores[i][0] = Cs[p];
            
            int n = 1;
            p = Ps[p];
            while (p != Ps[i]) {
                scores[i][n] = scores[i][n - 1] + Cs[p];
                n++;
                p = Ps[p];
            }
            
            if (K <= n) {
                final long currMax = LongStream.of(scores[i]).limit(K).max().getAsLong();
                if (maxScore < currMax) {
                    maxScore = currMax;
                }
            } else {
                final int Kdiv = K % n == 0 ? K / n - 1 : K / n;
                final int Kmod = K % n == 0 ? n : K % n;
                
                final long total = scores[i][n - 1];
                if (0 < total) {
                    for (int j = 0; j < n; j++) {
                        scores[i][j] += j < Kmod ? total * Kdiv : total * (Kdiv - 1);
                    }
                }
                
                final long currMax = LongStream.of(scores[i]).max().getAsLong();
                if (maxScore < currMax) {
                    maxScore = currMax;
                }
            }
        }
        
        System.out.println(maxScore);
    }
}


Measured memory_bytes: 237768
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  a,b,k = map(int,input().split())
  k -= 1 # indexed
  ANS = []
  if a > b:
    a,b = b,a
  for i in range(1,a+1):
    if a%i == 0 and b%i == 0:
      ANS.append(i)
  ANS = sorted(ANS,reverse=True)
  print(ANS[k])
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    for(int i = n - 1; i > 0; i--)
    {
        if(h[i - 1] - h[i] == 1)
        {
            h[i - 1]--;
        }
        else if(h[i - 1] - h[i] > 1)
        {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

    return 0;
}


Measured memory_bytes: 640
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IArray
import Control.Monad

lowerBound:: (Integral i, Ix i, Ord e, IArray a e) => e -> a i e -> i
lowerBound x a =
    let (b,e) = bounds a in bsearch b (e + 1)
  where
    bsearch b e
      | e == b    = b
      | x <= a!p  = bsearch b p
      | otherwise = bsearch (p + 1) e
      where p = (b + e) `div` 2

main :: IO ()
main = do
    _ <- getLine
    l <- map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    let sl = listArray (0,length l - 1) $ sort l :: Array Int Int
    suma <- forM [0..length sl - 1] $ \a -> do
        sumb <- forM [(a+1)..length sl - 1] $ \b -> do
            let c = lowerBound ((sl!a)+(sl!b)) sl
            return $ c - (b+1)
        return sumb
    print . sum . concat $ suma


Measured memory_bytes: 321916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

int N;
int sieve[10001];
vint primes;

void eratos(){

	for(int i = 0; i <= 10000; i++){
		sieve[i] = 1;
	}
	for(int i = 2; i <= 10000; i++){
		if(sieve[i] == 0) continue;
		primes.push_back(i);
		for(int j = i * 2; j <= 10000; j += i){
			sieve[j] = 0;
		}
	}
	// for(int i: primes) cerr << i << ", ";
	// cerr << primes.size() << endl;
}

int main() {
	cin >> N;
	eratos();

	int ret = 0;
	rep(i, N){
		int x; cin >> x;
		for(int p:primes) {
			if(p < x && x % p == 0) {
				x = -1;
				break;
			}
		}
		if(x != -1) ret++;
	}

	cout << ret << endl;
}

Measured memory_bytes: 3176
#include<stdio.h>
#include<string.h>
main(){
  int i=0,j=0,nikai=0,a,b,max;
  char p[1024],s[1024],t[1024];
  scanf("%s",s);
  scanf("%s",p);
  strcpy(t,s);
  strcat(s,t);
  if(strstr(s,p)!=NULL) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 544
s1 = input()
s2 = input()

dp = [[0 for j in range(len(s2)+1)] for k in range(len(s1)+1)]

for i in range(len(s1)+1):
    dp[i][0] = i

for i in range(len(s2)+1):
    dp[0][i] = i

for i in range(0, len(s1)):
    for j in range(0, len(s2)):
        cost = 0 if s1[i] == s2[j] else 1
        dp[i+1][j+1] = min(dp[i][j+1]+1, dp[i+1][j]+1, dp[i][j]+cost)

print(dp[len(s1)][len(s2)])


Measured memory_bytes: 44016
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MAXN = 100000;

vector<int>G[MAXN + 5];
map<ll, int>mp;
int siz[MAXN + 5];

ll check(int x) {
	ll ret = 0;
	for (int i = 0; i < G[x].size(); i++) {
		int to = G[x][i];
		ret += check(to) + siz[to];
	}
	return ret;
}

int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		ll D; scanf("%lld", &D);
		mp[D] = i, siz[i] = 1;
	}
	map<ll, int>::reverse_iterator rt;
	for (map<ll, int>::reverse_iterator it = mp.rbegin(); it != mp.rend(); it++) {
		if (siz[it->second] == n) {
			rt = it;
			break;
		}
		int x = it->second;
		ll k = it->first + siz[x] - (n - siz[x]);
		if (k < it->first && mp.count(k)) {
			int p = mp[k];
			siz[p] += siz[x];
			G[p].push_back(x);
		}
		else {
			puts("-1");
			return 0;
		}
	}
	if (check(rt->second) == rt->first) {
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < G[i].size(); j++)
				printf("%d %d\n", i, G[i][j]);
		}
	}
	else puts("-1");

	return 0;
}


Measured memory_bytes: 15872
#include "bits/stdc++.h"
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl

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

  long long x;
  cin>>x;
  int ans=0;

  for(long long i=100;i<x;){

     i+=(i/100);     
     ans++;

  }
   cout<<ans<<endl;

  
     
  return 0;
}


Measured memory_bytes: 3640
<?php
$n = trim(fgets(STDIN));
$p = explode(" ",trim(fgets(STDIN)));

$i = 1;
while($i <= $n){
    $a[$i] = $i - $p[$i - 1];
    ++$i;
}

$ans = 0;
$i = 1;
foreach($a as $val){
    if($val == 0){
        if($i == 0){
            $i = 1;
        }else{
            ++$ans;
            $i = $val;
        }
    }else{
        $i = $val;
    }
}

echo $ans;

Measured memory_bytes: 35308
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================
//using系

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ld = long double;
using qul = queue<ll>;
using pql = priority_queue<ll>;

// ========================================================================
//define系

//#define int long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i <= n; i++)

// ========================================================================


ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll mch(ll n) {
	if (n == 1) return 1;
	else return n * mch(n - 1);
}
//1から整数nまでの階乗を出す(INFで割っていない)
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります（ただの前座）
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の10^9+7等対策で逆元を出します 




// ========================================================================


/*signed*/int main() {
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	ll e, f;
	e = f = 0;
	sort(a.begin(), a.end());
	for (int i = n - 1; i > 0; i--) {
		if (e == 0) {
			if (a[i] == a[i - 1]) {
				e = a[i];
				i -= 2;
			}
		}
		if (a[i] == a[i - 1]) {
			f = a[i];
			break;
		}
	}
	cout << e * f << endl;

	return 0;
}

Measured memory_bytes: 4128
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in input( ).split( " " ) ]
roll = input( )
for i in range( len(  roll ) ):
	if "E" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Measured memory_bytes: 6800
#include <iostream>

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

using namespace std;

int main(void)
{
  int H, N;
  int num;
  
  cin >> H >> N;

  rep(N)
  {
    cin >> num;
    H -= num;
  }

  if(H <= 0)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	double dn;
	double list[4] = {0.5, 0.25, 0.125, 0.0625};
	string sm;
	while(cin >> dn, dn >= 0){
		int n = (int)dn;
		double m = dn-n;
		bitset<8> nn(n);
		bool pm[4] = {false};

		if(n > 255){
			cout << "NA" << endl;
			continue;
		} 

		for(int i = 0; i < 4; i++){
			if(m >= list[i]){
				m-=list[i];
				pm[i] = true;
			}
		}
		if(m != 0){
			cout << "NA" <<endl;
			continue;
		}
		cout << nn << ".";
		for(int i = 0; i < 4; i++){
			cout << pm[i];
		}
		cout << endl;

	}

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1240