akhauriyash/Code-Regression huggingface dataset:
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
ll mod=1000*1000*1000+7;
int main() {
    cout.precision(10);
    cout<<fixed;
    int S,W;
    cin >> S>> W;
    if (W>=S)
        cout << "unsafe"<<endl;
    else
        cout<<"safe"<<endl;
}

struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};


Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long n,p,ans;
int main(){
	scanf("%lld%lld",&n,&p);
	long long ans=1;
	for(long long i=2;i*i<=p;i++){
		int tot=0;
		while(p%i==0){
			tot++;
			if(tot==n)tot=0,ans*=i;
			p/=i;
		}
	}
	if(n==1)ans*=p;
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long K, A, B;
    long ans = 1;
    cin >> K >> A >> B;
    if(B-A <= 2 || K <= A) ans += K;
    else{
        K -= A-1;
        ans = A+(K/2)*(B-A);
        if(K%2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int SMALL = 1;
const int MIDDLE = 2;
const int LARGE = 3;
int paper[10][10] = {0};

void Dropping_Ink(int x, int y, int size)
{
		paper[y][x]++;
		if(x-1 > -1)    paper[y][x-1]++;
		if(x+1 < 10)    paper[y][x+1]++;
		if(y-1 > -1)    paper[y-1][x]++;
		if(y+1 < 10)    paper[y+1][x]++;

		if(size >= MIDDLE)
		{
			if(x-1 > -1)
			{
				if(y-1 > -1)    paper[y-1][x-1]++;
				if(y+1 < 10)    paper[y+1][x-1]++;
			}
			if(x+1 < 10)
			{
				if(y-1 > -1)    paper[y-1][x+1]++;
				if(y+1 < 10)    paper[y+1][x+1]++;
			}
		}

		if(size == LARGE)
		{
			if(x-2 > -1)    paper[y][x-2]++;
			if(x+2 < 10)    paper[y][x+2]++;
			if(y-2 > -1)    paper[y-2][x]++;
			if(y+2 < 10)    paper[y+2][x]++;
		}
}

int main()
{
	int x, y, size, white, color;
	char c[2];

	while(cin >> x >> c[0] >> y >> c[1] >> size)
	{
		if(cin.eof())    break;

		Dropping_Ink(x, y, size);	
	}

	white = 0;
	color = 0;	
	
	for(int i=0; i<10; i++)
	{
		for(int j=0; j<10; j++)
		{
			if(paper[i][j] == 0)    white++;
			if(paper[i][j] > color)    color = paper[i][j];
		}
	}

	cout << white << endl << color << endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	int ans=0,ren=0;
	for(int i=0;i<N;i++){
		int p;
		cin>>p;
		if(p==i+1)
			ren++;
		else{
			ans+=(ren+1)/2;
			ren=0;
		}
		//cout<<ren<<endl;
	}
	ans+=(ren+1)/2;
	ren=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(){
  int k;
  char string[100000];
  scanf("%d", &k);
  scanf("%s", string);
  int n = strlen(string);
  
  for (int i = 0; i < k && i < n; i++)
  {
    printf("%c", string[i]);
  }
  if (n > k)
  {
    printf("...\n");
  }
  return 0;
}

Measured memory_bytes: 1672
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=j;i<=k;++i)
#define Forr(i,j,k) for (int i=j;i>=k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T& a,T b) {return a<b?a=b,1:0;}
template<typename T>bool chkmin(T& a,T b) {return a>b?a=b,1:0;}

const int maxn=10000+100;
int n;
int a[maxn],b[maxn];

inline void read(int &x) {
	x=0;
	int p=1;
	char c=getchar();
	while (!isdigit(c)) {if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) {x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	x*=p;
}

inline void file() {
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
}

int main() {
//	file();
	read(n);
	ll suma=0,sumb=0;
	For (i,1,n) read(a[i]),suma+=a[i];
	For (i,1,n) read(b[i]),sumb+=b[i];
	ll step=sumb-suma;
	ll sum=0;
	For (i,1,n)
		if (a[i]<b[i]) sum+=(b[i]-a[i]+1)/2;
	if (sum>step || step<0) printf("No");
	else printf("Yes");
/*	ll sum1=0,sum2=0;
	For (i,1,n) {
		if (a[i]>=b[i]) sum1+=(a[i]-b[i]);
		else {
			if ((b[i]-a[i])%2==0) sum2+=(b[i]-a[i])/2;
			else {
				sum2+=(b[i]-a[i])/2+1;
				sum1++;
			}
		}
	}
	if (sum1<=sum2) printf("Yes");
	else printf("No");*/
/*	int ok=1;
	For (i,1,n) if (a[i]!=b[i]) ok=0;
	if (ok) {
		printf("Yes");
		return 0;
	}
	ll sum1=0,sum2=0,sum=0;
	For (i,1,n) {
		if (a[i]>=b[i]) sum1+=(ll)(a[i]-b[i]);
		if (a[i]<b[i]) sum2+=(ll)(b[i]-a[i]);
		if (abs(a[i]-b[i])%2==1) sum++;
	}
	if (sum1>sum2) {
		printf("No");
		return 0;
	}
	ll step=sum2-sum1;
	if (sum2>2*step) {
		printf("No\n");
		return 0;
	}
	printf("Yes");*/
	return 0;
}

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

    using namespace std;
    int main()
    {
        // 整数の入力
        int N;
        cin >> N;
        vector<int> bVector(N - 1);
        for(int i = 0; i < N - 1; i++){
            cin >> bVector.at(i);
        }
        int totalA = 0;
        int prevB = 99999999;
        for(int i = 0; i < N; i++){
            int currentB;
            if(i < N - 1){
                currentB = bVector.at(i);
            }else {
                currentB = 99999999;
            }
            totalA += min(prevB, currentB);
            prevB = currentB;
        }
        cout << totalA;
        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;++i)
    {
        long long a;
        cin>>a;
        while(a%2==0)
        {
            sum++;
            a/=2;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
ll power(ll x, ll y); 

const ll MOD = 1000000007;
const int MX = 1e5 + 6;

int arr[MX], pre[MX], suf[MX];
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    int n;
    cin >> n;
    repp(i, 1, n) cin >> arr[i];
    repp(i, 1, n) pre[i] = __gcd(pre[i - 1], arr[i]);
    rrep(i, n, 1) suf[i] = __gcd(suf[i + 1], arr[i]);
    int mx = 0;
    repp(i, 1, n) mx = max(mx, __gcd(pre[i - 1], suf[i + 1]));
    cout << mx;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 1408
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
int n,prt[300005],w[300005],fa[300005],sizes[300005],sums[300005];
long long ans=0;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int find(int x)
{
	return (x==fa[x])?x:fa[x]=find(fa[x]);
}
struct que
{
	int id;
	long long v,num;
	friend bool operator <(const que &a,const que &b)
	{
		if(a.v*b.num==b.v*a.num) return a.id<b.id;
		return a.v*b.num>b.v*a.num;
	}
};
set<que> s;
set<que>::iterator it;
int main()
{
	n=read();
	for(int i=2;i<=n;i++) prt[i]=read();
	for(int i=1;i<=n;i++) w[i]=read();
	for(int i=1;i<=n;i++) fa[i]=i;
	for(int i=2;i<=n;i++)
	{
		if(!w[i])
		{
			fa[i]=find(prt[i]),sizes[fa[i]]++;
			if(fa[i]==1&&!w[1]) continue;
			ans++;
		}
	}
	for(int i=1;i<=n;i++) if(w[i]) sums[i]=1;
	for(int i=2;i<=n;i++) if(w[i]) s.insert((que){i,sizes[i],sums[i]});
	int sz=s.size();
	while(sz)
	{
		it=s.begin();s.erase(it);
		int u=(*it).id;
		int fas=find(prt[u]);
		ans+=1ll*sums[fas]*sizes[u];
		if(fas!=1)
		{
			que y=(que){fas,sizes[fas],sums[fas]};s.erase(y);
			sums[fas]+=sums[u];sizes[fas]+=sizes[u];fa[u]=fas;
			y=(que){fas,sizes[fas],sums[fas]};s.insert(y);
		}
		else sums[fas]+=sums[u],sizes[fas]+=sizes[u],fa[u]=fas;
		sz--;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 19992
#include <bits/stdc++.h>
#define llong long long
#define mp make_pair
#define f first
#define s second

using namespace::std;

int main()
{
    ios::sync_with_stdio(false);
    ifstream fin("input.txt");
    int N;
    cin >> N;
    map<int, int> freq;
    vector<int>(arr);
    for (int i = 0; i < N; i++) {
        int val;
        cin >> val;
        freq[val]++;
        if (freq[val] % 2 == 0) {
            arr.push_back(val);
        }
    }
    sort(arr.rbegin(), arr.rend());
    if (arr.size() < 2) {
        cout << "0";
    }
    else {
        cout << (llong)arr[0] * arr[1];
    }
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,j=0;
  float total;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<N-1;i++){
    j++;
    if(i == 0){
      total = (vec.at(0) + vec.at(1)) / 2.0;
    }else{
      total = (total + vec.at(j)) / 2.0;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
def main():
    N=input()
    X=len(N)
    INF=10**100
    dp=[[INF,INF] for i in range(0,X+1)]
    dp[0][0]=0
    dp[0][1]=1
    for j in range(1,X+1):
        dp[j][0]=min(dp[j-1][0]+int(N[j-1])%10,dp[j-1][1]+10-int(N[j-1])%10)
        if int(N[j-1])%10!=9:
            dp[j][1]=min(dp[j-1][1]+9-int(N[j-1])%10,dp[j-1][0]+int(N[j-1])%10+1)
        else:
            dp[j][1]=dp[j-1][1]+9-int(N[j-1])%10
    print(dp[X][0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 153164
import java.util.Arrays;
import java.util.Scanner;

//Lottery
public class Main{

	public static void main(String[] args) {
		boolean[] p = new boolean[1000001];
		int[] s = new int[1000001];
		Arrays.fill(p, true);
		p[0]=p[1]=false;
		for(int i=2;i<1000001;i++){
			s[i] = s[i-1];
			if(p[i]){
				s[i]++;
				for(int j=i*2;j<1000001;j+=i)p[j]=false;
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int prime = 0;
			while(n--!=0){
				int P = sc.nextInt();
				int m = sc.nextInt();
				int l = Math.max(1, P-m);
				int r = Math.min(1000000, P+m);
				int x = s[r]-s[l-1];
				if(x==0)prime--;
				else prime+=x-1;
			}
			System.out.println(prime);
		}
	}
}

Measured memory_bytes: 0
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

n = int(input())		# 文字列の入力  abcdefg...

A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

from collections import defaultdict
dicCount = defaultdict(int)
for key in A:
	dicCount[key]+=1

sumA=0
dicSum = defaultdict(int)
for key in A:
	if dicSum[key] > 0: continue
	cnt = dicCount[key]
	dicSum[key] = (cnt*(cnt-1))//2
	sumA += dicSum[key]


#p(dicCount)
#p(dicSum)

for key in A:
	cnt = dicCount[key]
	
	i = (cnt-1)*(cnt-2)//2
	
	ans = sumA - dicSum[key] + i
	
	print( ans )
	
	#p("key,cnt,i,sumA,dicSum[key],ans, ", key,cnt,i,sumA,dicSum[key],ans)
	

Measured memory_bytes: 32484
a = 3.times.map{gets.split.map(&:to_i)}
n = gets.to_i
b = n.times.map{gets.to_i}
i = 0
j =0
ans = [[0,0,0],[0,0,0],[0,0,0]]


a.each do |c|

  c.each do |d|

    if ans[i][j] == 0
      b.each do |t|
        if t == d
          ans[i][j] =1
        end
      end
    end
    j +=1
  end
  j=0
  i +=1
end



#p a


#p ans

array2 = ans.flatten

if(array2[0]+array2[3]+ array2[6]==3)
  puts "Yes"
  exit
elsif (array2[1]+array2[4]+ array2[7]==3)
  puts "Yes"
  exit
elsif(array2[2]+array2[5]+ array2[8]==3)
  puts "Yes"
  exit
elsif (array2[0]+array2[1]+ array2[2]==3)
  puts "Yes"
  exit
elsif (array2[3]+array2[4]+ array2[5]==3)
  puts "Yes"
  exit
elsif (array2[6]+array2[7]+ array2[8]==3)
  puts "Yes"
  exit
elsif (array2[0]+array2[4]+ array2[8]==3)
  puts "Yes"
  exit
elsif (array2[2]+array2[4]+ array2[6]==3)
  puts "Yes"
  exit
else
  puts "No"
end





Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll N,W;
ll w[101],v[101];
int main(){
    cin >> N;
    string s; cin >> s;
    map<char,int> mp;
    for(int i = 0; i < N; i++){
        mp[s[i]]++;
    }
    ll ans = 1;
    for(char t = 'a'; t <= 'z'; t++){
        if(mp[t] == 0) continue;
        ans *= (mp[t]+1);
        ans %= MOD;
    }




    cout << ans-1 << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdint>
#include<map>
using namespace std;

int main()
{
  uint64_t N;

  cin >> N;
  map<string, uint64_t> m;
  for (uint64_t i = 0; i < N; ++i) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    auto f = m.find(s);
    if (f != m.end()) {
      ++((*f).second);
    } else {
      m.insert(make_pair(s, 1));
    }
  }

  uint64_t c = 0;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    for (uint64_t i = 1; i < (*itr).second; ++i) {
      c += i;
    }
  }

  cout << c;

  return 0;
}



Measured memory_bytes: 11136
#include<stdio.h>

int main()
{
    int i;
    int j=0;
    char s[4];
    char t[4];
    scanf("%s",s);
    scanf("%s",t);
    for(i=0;i<3;i++){
        if(s[i]==t[i])
            j++;
    }
    printf("%d\n",j);
    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		int sum = 1;
		for(int i = static_cast<int>(sqrt(n)); i > 1; --i){
			if(n % i == 0){
				sum += i;
				if(n / i != i){ sum += n / i; }
			}
		}
		if(sum < n || n == 1){
			cout << "deficient number" << endl;
		}else if(sum > n){
			cout << "abundant number" << endl;
		}else{
			cout << "perfect number" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = input()
    result = None

    for s in S:
        if result is None:
            result = s
        elif result[-1] != s:
            result += s

    print(len(result))


if __name__ == "__main__":
    main()


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

int main(){
    int a,b;
    cin >> a >> b;
    int num=1250;
    int ans=0;
    while(num>0){
        if((int)(num * 0.08) == a && (int)(num * 0.1)== b){
            ans=num;
        }
        num--;
    }
    if(ans>0){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>

constexpr bool divisible(const std::size_t n, const std::size_t m)
{
    return (0 == n % m);
}

std::vector<std::size_t> prime_table = {2};

bool prime(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        std::list<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            undefined_table.push_back(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; !undefined_table.empty() && p < prime_table.size(); ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(divisible(*u, prime_table.at(p)))
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(!undefined_table.empty() && found_last_prime <= prime_table.at(p))
            {
                prime_table.push_back(undefined_table.front());
                undefined_table.pop_front();
                if(sn < prime_table.back())
                {
                    break;
                }
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
    return std::binary_search(prime_table.begin(), prime_table.end(), n);
}

std::pair<std::size_t, std::size_t> find_twin_prime(const std::size_t limit, const bool next_skip = false)
{
    return prime(limit) ?
        prime(limit - 2) ?
        std::make_pair(limit - 2, limit) :
        find_twin_prime(limit - (next_skip ? 3 : 1), true) :
        find_twin_prime(limit - (next_skip ? 2 : 1), false);
}

int main()
{
    std::size_t n;

    while(std::cin >> n, n != 0)
    {
        const auto&& t = find_twin_prime(n);
        std::cout << t.first << " " << t.second << std::endl;
    }
}

Measured memory_bytes: 1248
module Main where

import Numeric
import Data.Functor

main :: IO ()
main = do
  { [a,b] <- getInts
  ; let (q,r) = divMod a b
  ; let s = fromIntegral a / fromIntegral b
  ; putStrLn . unwords $ [show q, show r, showFFloat Nothing s ""]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

done :: IO ()
done = return ()

Measured memory_bytes: 4008
import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {

    fun PrintWriter.solve() {
        var (a,b) = List(2){nextInt()}

        var xmin = 10*b
        var xmax = xmin + 9

        for (x in xmin..xmax){
            if ((0.08*x).toInt() == a){
                println(x)
                return
            }
        }

        println(-1)


    }

    writer.solve()
    writer.flush()


}


private val reader = System.`in`.bufferedReader()
private val writer = PrintWriter(System.out, false)

private var tokenizer: StringTokenizer = StringTokenizer("")

private fun next(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
    return tokenizer.nextToken()
}

private fun nextInt() = next().toInt()
private fun nextLong() = next().toLong()
private fun nextDouble() = next().toDouble()
private fun nextLine() = reader.readLine()



Measured memory_bytes: 34444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <iso646.h>
#include <exception>
#include <stdexcept>

using namespace std;

typedef long long i64;

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

    i64 n;
    cin >> n;

    for (i64 a = 1; a <= 3500; a++)
        for (i64 b = 1; b <= 3500; b++)
        {
            i64 d1 = n * a * b;
            i64 d2 = 4 * a * b - n * b - n * a;

            if (d2 != 0)
            {
                i64 c = d1 / d2;
                i64 r = d1 % d2;

                if (r == 0 && c >= 1 && c <= 3500)
                {
                    cout << a << ' ' << b << ' ' << c;
                    return 0;
                }
            }
        }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
	int n;
	long long int y;
	bool bl=false;
	cin>>n>>y;
	for(int i=0;i<=n;i++){
		for(int k=0;k<=n-i;k++){
			int j=n-k-i;
			if((10000*i)+(5000*k)+(1000*j)==y){
				cout<<i<<' '<<k<<' '<<j<<endl;
				bl=true;
				exit(0);
			}
		}
	}
	if(!bl)cout<<"-1 -1 -1"<<endl;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;

  ll ans = 0;
  for(int bit = 0; bit < (1 << (s.length()-1)); bit++){
    
    string tmp = "";
    tmp += s[0];
    for(int i = 0; i < s.length()-1; i++){
      if(bit & (1<<i)){
        ans += stoll(tmp);
        tmp = "";
      }
      tmp = tmp + s[i+1];
    }
    ans += stoll(tmp);

  }

  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);

    auto cnt = new int[](m);

    foreach (i ; 0 .. n) {
        auto li = readln.split.to!(int[]);

        foreach (b ; li[1 .. $]) {
            cnt[b - 1]++;
        }
    }

    int ans;

    foreach (i ; 0 .. m) {
        ans += cnt[i] == n;
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li a[200100];
li n;
li k;

inline bool check(li x) {
	li cnt = 0;
	rep(i, n) {
		if (a[i] < 0) {
			cnt += a + n - partition_point(a, a + n, [&](li b) {
				return a[i] * b > x;
			});
		} else {
			cnt += partition_point(a, a + n, [&](li b) {return a[i] * b <= x;}) - a;
		}
		if (a[i]*a[i] <= x) {
			cnt--;
		}
	}
	cnt /= 2;
	return cnt < k;
}

int main() {
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);

	const li INF = 1ll << 61;

	li left = -INF;
	li right = INF + 1;

	li cnt = 0;
	while (left < right) {
		li med = (left + right + 2 * INF) / 2 - INF;
		if (check(med)) {
			left = med + 1;
		} else {
			right = med;
		}
	}

	cout << left << endl;


	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int S(int n){
  string s = to_string(n);
  int sum = 0;
  for(int i=0; i<s.length(); i++)
    sum += n = (int)(s[i] - '0');
  return sum;
}
int main(){
  int N;
  cin>>N;
  cout<<(N%S(N)==0?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
A=input()
B=input()
C=input()
count=0
for i in range(0,N):
    if A[i]==B[i]==C[i]:
        count=count
    elif A[i]==B[i] or A[i]==C[i] or B[i]==C[i]:
        count=count+1
    else:
        count=count+2
print(count)

Measured memory_bytes: 3060
n = int(input())
ary = []
ans = 0
final_a = 0
start_b = 0
ab = 0
for i in range(n):
  s = input()
  ary.append(s)
  if s[0] == "B" and s[-1] == "A":
    ab += 1
  else:
    if s[0] == "B":
      start_b += 1
    if s[-1] == "A":
      final_a += 1
  while True:
    idx = s.find("AB")
    if idx == -1:
      break
    else:
      s = s[idx+2:]
      ans += 1

if ab > 0:
  ans += ab - 1
  if start_b > 0:
    ans += 1
    start_b -= 1
  if final_a > 0:
    ans += 1
    final_a -= 1

if start_b >= final_a:
  ans += final_a
else:
  ans += start_b
print(ans)


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

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

int main(){
        int n;cin >> n;
        int wrong = 0;
        rep{
                int a;cin >> a;
                if(a != i+1) wrong += 1;
        }
        if(wrong == 0 or wrong == 2){
                cout << "YES" << endl;
        }else{
                cout << "NO"<<endl;
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	long long n, sum = 0, min = 1000005, max = -1000001, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		sum += c;
		if (min > c) min = c;
		if (max < c) max = c;
	}
	cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3112
import java.util.Arrays;
import java.util.Scanner;

class Main{

    static long M;
    static long[][] S;
    static long[][] C;
    static int N;

    static long[][] complex(int N){
        long[][] res = new long[N+1][N+1];
        for(int i=0;i<=N;++i){
            res[i][0]=res[i][i]=1;
            for(int j=1;j<i;++j){
                res[i][j]=(res[i-1][j]+res[i-1][j-1])%M;
            }
        }
        return res;
    }

    static long[][] stirling(int N){
        long[][] res = new long[N+1][N+1];
        //i個を空でないjに分割(含まれないものが合っても良い)
        for(int i=0;i<=N;++i){
            res[i][0]=res[i][i]=1;
            for(int j=1;j<i;++j){
                res[i][j] = (res[i-1][j-1] + (long)(j+1)*(res[i-1][j]%M))%M;
            }
        }
        return res;
    }

    //a^x
    static long beki(long a, long x, long mod){
        long res=1;
        for(int i=0;i<32;++i){
            if(((x>>i)&1)==1)res=(res*a)%mod;
            a = (a*a)%mod;
        }
        return res;
    }

    static long ways(int i){
        long res = 0;
        long b1 = beki(2,N-i,M);
        long beki1 = 1;
        long beki2 = beki(2,beki(2,N-i,M-1)%(M-1),M);
        for(int j=0;j<=i;++j){
            res = (res+ways2(i,j,beki1,beki2))%M;
            beki1 = (beki1*b1)%M;
        }
        return res;
    }

    static long ways2(int i,int j,long beki1, long beki2){
        return ((S[i][j]*beki1)%M*beki2%M)%M;
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        N = scan.nextInt();
        M = scan.nextLong();
        C = complex(N);
        S = stirling(N);
        long ans = 0;
        for(int i=0;i<=N;++i){
            ans = (ans + (i%2==0 ? 1:-1)*(C[N][i]*ways(i))%M + (i%2==0 ? 0:M))%M;
        }
        System.out.println(ans);
    }
}

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


typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long > vll;
typedef vector<pii> vii;

#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

long long p = 1000000007;
const long long INF64 = 1e18;

 
long long power(long long a, long long b, long long p)
{
	long long res =1;
 
	while(b)
	{
		if(b&1)
			res = (res*a)%p;
		a = (a*a)%p;
		b/=2;
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if(b==0)return a;
	return gcd(b, a%b);
}




int main() 
{
cin.sync_with_stdio(0); cin.tie(0);
cin.exceptions(cin.failbit);
int T;
T=1;
while(T--)
{
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl;
	
	
}
return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

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

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

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

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const int MOD = 1e9 + 7;

long long inq(long long a, long long b)
{
    if (b == 0) return 1;
    long long l = inq(a, b / 2);
    if (b % 2) return l * l % MOD * a % MOD;
    return l * l % MOD;
}

int n, m;
string s[700];
string a[700], b[700];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        a[i] = s[i];
        b[i] = s[i];
    }
    for (int i = 1; i < n - 1; i++)
    {
        a[i][0] = '#';
        b[i][m - 1] = '#';
    }
    for (int i = 1; i < n - 1; i++)
    {
        if (i % 2 == 1)
        {
            for (int j = 1; j < m - 1; j++) a[i][j] = '#';
        }
        else
        {
            for (int j = 1; j < m - 1; j++) b[i][j] = '#';
        }
    }
    for (int i = 0; i < n; i++) cout << a[i] << "\n";
    cout << "\n";
    for (int j = 0; j < n; j++) cout << b[j] << "\n";
}


Measured memory_bytes: 1536
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	k, a, b := nextInt(), nextInt(), nextInt()

	for i := a; i <= b; i++ {
		if i%k == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}


Measured memory_bytes: 1756
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int r, c, dat[90][90][2];
bool mstat[80][80][12801];

int fun()
{
	mstat[0][0][abs(dat[0][0][0] - dat[0][0][1])] = true;
	for (int i = 1; i < r; i++) {
		int tmp = abs(dat[i][0][0] - dat[i][0][1]);
		for (int k = 0; k <= 12800; k++) {
			if (mstat[i - 1][0][k]) {
				if (abs(k - tmp) >= 0 && abs(k - tmp) <= 12800) {
					mstat[i][0][abs(k - tmp)] = true;
				}
				if (k + tmp <= 12800) {
					mstat[i][0][k + tmp] = true;
				}
			}
		}
	}
	for (int j = 1; j < c; j++) {
		int tmp = abs(dat[0][j][0] - dat[0][j][1]);
		for (int k = 0; k <= 12800; k++) {
			if (mstat[0][j - 1][k]) {
				if (abs(k - tmp) >= 0 && abs(k - tmp) <= 12800) {
					mstat[0][j][abs(k - tmp)] = true;
				}
				if (k + tmp <= 12800) {
					mstat[0][j][k + tmp] = true;
				}
			}
		}
	}
	for (int i = 1; i < r; i++) {
		for (int j = 1; j < c; j++) {
			int tmp = abs(dat[i][j][0] - dat[i][j][1]);
			for (int k = 0; k <= 12800; k++) {
				if (mstat[i][j - 1][k]) {
					if (abs(k - tmp) >= 0 && abs(k - tmp) <= 12800) {
						mstat[i][j][abs(k - tmp)] = true;
					}
					if (k + tmp <= 12800) {
						mstat[i][j][k + tmp] = true;
					}
				}
				if (mstat[i - 1][j][k]) {
					if (abs(k - tmp) >= 0 && abs(k - tmp) <= 12800) {
						mstat[i][j][abs(k - tmp)] = true;
					}
					if (k + tmp <= 12800) {
						mstat[i][j][k + tmp] = true;
					}
				}
			}
		}
	}
	int g = 100;
	for (int k = 0; k <= 12800; k++) {
		if (mstat[r - 1][c - 1][k]) {
			g = k;
			break;
		}
	}
	return g;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> dat[i][j][0];
		}
	}
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> dat[i][j][1];
		}
	}
	cout << fun() << E;
	//system("pause");
	return 0;
}


Measured memory_bytes: 79488
import collections
n=int(input())
l=[]
for i in range(n):
  l.append(input())
c=collections.Counter(l)
for k in ['AC','WA','TLE','RE']:
  if k in c.keys():
    print(k+' x '+str(c[k]))
  else: print(k+' x '+str(0))


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

const int Maxn = 52;

int n, k;
int v[Maxn];
int res;

int main()
{
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &v[i]);
    for (int i = 0; i < n; i++)
        for (int j = 0; i + j <= min(n, k); j++) {
            vector <int> neg;
            int sum = 0;
            for (int z = 0; z < i; z++) {
                sum += v[z];
                if (v[z] < 0) neg.push_back(v[z]);
            }
            for (int z = 1; z <= j; z++) {
                sum += v[n - z];
                if (v[n - z] < 0)
                    neg.push_back(v[n - z]);
            }
            sort(neg.rbegin(), neg.rend());
            int lft = k - i - j;
            while (lft > 0 && !neg.empty()) {
                sum -= neg.back(); neg.pop_back();
                lft--;
            }
            res = max(res, sum);
        }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
/*input
6
30 10 60 10 60 50

*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    

 
int32_t main() {
    IOS;
	int n;cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int dp[n] ;
	fill(dp,dp+n,INT_MAX);
	dp[0] = 0;
	for(int i=0;i<n;i++){
		if(i+1<n){
			//cout<<dp[i]+abs(arr[i]-arr[i+1])<<" "<<dp[i+1]<<endl;
			dp[i+1] =  min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
			
		}
		if(i+2<n){
			dp[i+2] = min(dp[i+2],dp[i]+abs(arr[i]-arr[i+2]));
			//cout<<dp[i+2]<<" ";
		}
		//cout<<dp[i]<<" ";
	}
	//cout<<endl;
	cout<<dp[n-1]<<endl;
	return 0;
}




Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  for (int n = 1; n <= N; ++n) {
    int ans = 0;
    for (int x = 1; x <= sqrt(n/6.0) + 1; x++) {
      for (int y = x; y <= sqrt(n/3.0) + 1; y++) {
        if (2*x*x + 3*y*y + x*y > n) break;
        for (int z = y; z <= sqrt(n) + 1; z++) {
          if (x*x + y*y + z*z + x*y + y*z + z*x == n) {
            if (x == y) {
              if (y == z) ans += 1;
              else ans += 3;
            }
            else if (y == z) ans += 3;
            else ans += 6;
          }
          else if (x*x + y*y + z*z + x*y + y*z + z*x > n) break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <string>

using namespace std;

constexpr bool WHITE = false;
constexpr bool BLACK = true;

using Row = vector<bool>;
using Board = vector<Row>;

uint H, W;
Board board{};

bool IsOk(uint i, uint j) {

  if (board[i][j] == WHITE)
    return true;

  try {
    if (board.at(i - 1)[j] == BLACK)
      return true;
  } catch (const std::out_of_range &) {
    ;
  }

  try {
    if (board.at(i + 1)[j] == BLACK)
      return true;
  } catch (const std::out_of_range &) {
    ;
  }

  try {
    if (board[i].at(j - 1) == BLACK)
      return true;
  } catch (const std::out_of_range &) {
    ;
  }

  try {
    if (board[i].at(j + 1) == BLACK)
      return true;
  } catch (const std::out_of_range &) {
    ;
  }

  return false;
}

int main() {

  cin >> H >> W;
  board.reserve(H);

  string line{};
  line.reserve(W);

  for (uint i = 0; i < H; ++i) {
    Row row{};
    row.reserve(W);

    cin >> line;
    for (const auto c : line) {
      if (c == '.')
        row.push_back(WHITE);
      else
        row.push_back(BLACK);
    }

    line.clear();
    board.push_back(move(row));
  }

  for (uint i = 0; i < H; ++i) {
    for (uint j = 0; j < W; ++j) {
      if (!IsOk(i, j)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>

int main()
{
	long long a = 0, b = 0, c = 0, d = 0, e = 0, min = 0, ma = 0, ans = 0, count = 0;
	bool okada = true;
	bool whiteyoko = false, whitetate = false;
	char grid[100][100];
	using namespace std;
	int answer[100][100] = {};
	cin >> a >> b;

//for(int i=0;i<a;i++){}


	cout << std::max(a-b,std::max(a*b,a+b));
	}



Measured memory_bytes: 256
import sys

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

def main():
    N,K = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [0] * (N + 1)

    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2,N):
        dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(0,i-K),i))
    print(dp[N-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 13980
a, b, c , d = map(int, input().split())

if a >= 0 and b >= 0:
  if c >= 0 and d >= 0:
    print(b*d)
    
  elif c < 0 and d >= 0:
    print(b*d)
  
  elif c < 0 and d < 0:
    print(a*d)
    
elif a < 0 and b >= 0:
  if c >= 0 and d >= 0:
    print(b*d)
    
  elif c < 0 and d >= 0:
    print(max(c*a, b*d))
    
  elif c < 0 and d < 0:
    print(a*c)
    
elif a < 0 and b < 0:
  if c >= 0 and d >= 0:
    print(b*c)
    
  elif c < 0 and d >= 0:
    print(a*c)
    
  elif c < 0 and d < 0:
    print(a*c)
    
    

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define Max(x, y)(max(decltype(x)(0), max((x), (y))))
#define Min(x, y)(max(decltype(x)(0), min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
#define Out(x) cout<<(x)<<_end
template<typename T> inline bool _max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool _min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    int a[n];
    int ali = 0;
    int bob = 0;

    int i;

    rep(i, n) cin >> a[i];

    sort(a, a + n, std::greater<int>());

    repiin(i, n, 1) {
        if (i % 2 == 1) ali += a[i - 1];
        else bob += a[i - 1];
    }

    Out(ali - bob);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int r1[1000005],r2[500],r3[500];
int main()
{
    int a,b,c,d,e,f,g,h,i,j,k;

    while(cin>>a)
    {

      for(b=1;b<=a;b++)
      {
          cin>>r1[b];
      }
      for(b=1;b<=a;b++)
      {
          cin>>r2[b];
      }
      for(b=1;b<=a-1;b++)
      {
          cin>>r3[b];
      }
      e=0;
       for(b=1;b<=a;b++)
      {
         if(b==1)
         {
             d=r1[b];
             e+=r2[d];
         }
         else
         {
             if(r1[b]-1==r1[b-1])
             {
                 d=r1[b];
                 e+=r2[d];
                 e+=r3[r1[b-1]];
             }
             else
             {

                 d=r1[b];
                 e+=r2[d];
             }


         }
      }
      cout<<e<<endl;




    }







    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int INF=1000000;

int n;
vector<pair<int,int> > nex[10000];

void dijkstra(){ 
  priority_queue<pair<int,int> >PQ;
  int d[10000];
  int color[10000];  
  for(int i=0;i<n;i++){
    d[i]=INF;
    color[i]=0;
  }
  
  color[0]=1;
  d[0]=0;
  PQ.push(make_pair(0, 0));
  
  while( !PQ.empty() ){
    pair<int,int> f = PQ.top();PQ.pop();
    int u =f.second;
    color[u]=2;
    if(d[u] < f.first *(-1)) continue;
    
    for(int j=0;j<nex[u].size();j++){
      int v=nex[u][j].first;
      if(color[v] == 2) continue;
      if(d[v]>d[u]+nex[u][j].second){
        d[v]=d[u]+nex[u][j].second;
        PQ.push(make_pair(d[v]*(-1),v));
        color[v]=1;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i] == INF ?:d[i])<<endl;
  }
}


int main(){
  cin>>n;
  int u,k,v,c;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      nex[u].push_back(make_pair(v,c));
    }
  }
  
  dijkstra();
  return 0;
}

      
  


Measured memory_bytes: 7964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACB75A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);


            if (b == c)
            {
                Console.WriteLine(a);
            }
            else if (a == c)
            {
                Console.WriteLine(b);
            }
            else if (a == b)
            {
                Console.WriteLine(c);
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define INF 3e+18
#define int long long
using namespace std;

int n,k,w[100000],d[100000];

bool C(int x){
	int sum = 0;
	for(int i = 0;i < n;i++) sum += max(0ll,(x - w[i]) / d[i] + 1);
	return sum >= k;
}

signed main(){
	cin >> n >> k;
	for(int i = 0;i < n;i++) cin >> w[i] >> d[i];
	int low = 0,up = INF;
	while(up - low > 1){
		int mid = (up + low) / 2;
		if(C(mid)) up = mid;
		else low = mid;
	}
	cout << up << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
lint n;
vector<lint> ret;
lint ans;

int main(){
  cin >> n;
  for(lint i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  reverse(begin(ret), end(ret));

  if(ret.size()%2==0){
    if(abs(ret[ret.size()/2-1]-ret[ret.size()/2])==1){
      for(lint j = 0;j<ret.size()/2-1;j++){
        ans += ret[j]-1;
      }
    }
    else{
      for(lint j = 0;j<ret.size()/2;j++){
        ans += ret[j]-1;
      }
    }
  }
  else{
    if(abs(ret[ret.size()/2-1]-ret[ret.size()/2+1])==1){
      for(lint j = 0;j<ret.size()/2-1;j++){
        ans += ret[j]-1;
      }
    }
    else{
      for(lint j = 0;j<ret.size()/2;j++){
        ans += ret[j]-1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384