akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H, W;
    string t;
    vector<string> M;
    cin >> H >> W;
    for (int i=0; i<H; ++i) {
        cin >> t;
        M.emplace_back(t);
    }
    
    for (int y=0; y<H; ++y) {
        string s;
        for (int x=0; x<W; ++x) {
            if (M[y][x] == '#') {
                s += "#";
                continue;
            }
            int d = min(y+1, H-1);
            int r = min(x+1, W-1);
            int b = 0;
            
            for (int u = max(y-1, 0); u<=d; ++u) {
                for (int l = max(x-1, 0); l<=r; ++l) {
                    if (M[u][l] == '#') { b += 1; }
                }
            }
            s += to_string(b);
            
        }
        cout << s << endl;
    }
    
    return 0;
}


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

int main() {

  long long N;
  cin >> N;

  vector<int> v;
  while (26 <= N) {
    if ((N % 26) == 0) {
      v.push_back(26);
      N /= 26;
      N--;
    } else {
      v.push_back(N % 26);
      N /= 26;
    }
    
  }

  if (N != 0) {
    v.push_back(N);
  }

  for (int i = v.size() - 1; 0 <= i; i--) {
    cout << char(v[i]+96);
  }

  cout << endl;

  return 0;

}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  int n;
  cin >> n;

  vector<int> b(n), a(n);
  rep(i, n - 1) cin >> b[i];


  ll ans = b[n - 2] + b[0];
  b[n - 1] = b[n - 2];

  for(int i = n - 2; i >= 1;--i){
    ans += min(b[i - 1], b[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		//StringBuilder sb=new StringBuilder();
		int i,j,k;
		int[][][] list=new int[4][3][10];
		for(i=0;i<4;i++){
			for(j=0;j<3;j++){
				for(k=0;k<10;k++){
					list[i][j][k]=0;
				}
			}
		}
		String str=br.readLine();
		int n=Integer.parseInt(str);
		for(i=0;i<n;i++){
			String[] house=br.readLine().split(" ");
			int b=Integer.parseInt(house[0]);
			int f=Integer.parseInt(house[1]);
			int r=Integer.parseInt(house[2]);
			int v=Integer.parseInt(house[3]);
			
			b--;
			f--;
			r--;
			list[b][f][r]+=v;
		}
		for(i=0;i<4;i++){
			for(j=0;j<3;j++){
				for(k=0;k<10;k++){
					System.out.print(" "+ list[i][j][k]);
				}
				System.out.println();
			}
			if(i==3)break;
			System.out.println("####################");
		}
	}
}

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

using namespace std;
using ll = long long;

const int N = 1e5 + 15, MOD = 1e9 + 7;

vector<int> g[ N ];
ll dp[ N ][ 2 ];

ll dfs(int u, int par, int black) {
    ll &ret = dp[ u ][ black ];
    if( ret > 0 ) return ret;
    ret = 1LL;
    for(int v : g[ u ]) {
        if( v == par ) continue;
        if( black )
            ret = (ret * dfs(v, u, 0)) % MOD;
        else
            ret = (ret * (dfs(v, u, 1) + dfs(v, u, 0)) % MOD) % MOD;
    }
    return ret;
}

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

    int n;
    cin >> n;

    for(int i = 1; i < n; i += 1) {
        int u, v;
        cin >> u >> v;
        g[ u ].push_back(v);
        g[ v ].push_back(u);
    }
    ll ans = dfs(1, 0, 1) + dfs(1, 0, 0);
    cout << ans % MOD << '\n';
	return 0;
}


Measured memory_bytes: 17024
#include <iostream>

int main(void){
  int row, col;
  std::cin >> row >> col;
  
  std::string cboard[row];
  int iboard[row][col];
  for(int i = 0; i < row; i++) std::cin >> cboard[i];
  for(int i = 0; i < row; i++) for(int j = 0; j < col; j++) iboard[i][j] = 0;
  
  const int x[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  const int y[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  for(int i = 0; i < row; i++){
    for(int j = 0; j < col; j++){
      if(cboard[i][j] != '#') continue;
      for(int k = 0; k < 8; k++){
        if(i+x[k] < 0 or i+x[k] >= row) continue;
        if(j+y[k] < 0 or j+y[k] >= col) continue;
        iboard[i+x[k]][j+y[k]]++;
      }
    }
  }
  for(int i = 0; i < row; i++){
    for(int j = 0; j < col; j++){
      if(cboard[i][j] == '#') std::cout << '#';
      else std::cout << iboard[i][j];
    }
    std::cout << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

Int N, M, V, P;
vector<Int> A;

bool isOK(Int i) {

	Int temp = 0;
	temp += M * (P - 1);

	if (A[i] + M < A[N - P]) {
		return false;
	}
	temp += M * (i + 1);
	for (Int j = i + 1; j <= N - P; j++) {
		temp += A[i] + M - A[j];
	}

	return temp >= V * M;
}

Int binary_search() {
	Int ng = -1;
	Int ok = N-P; 

	while (abs(ok - ng) > 1) {
		Int mid = (ok + ng) / 2;

		if (isOK(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {

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

	
	cin >> N >> M >> V >> P;
	A.resize(N);
	
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end());

	Int res = binary_search();
	cout << N-res << "\n";
}


Measured memory_bytes: 1024
import math
lis = list(map(int, input().split(' ')))
def calcAngle(h,m): 
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m  
        angle = abs(hour_angle - minute_angle) 
        angle = min(360 - angle, angle)         
        return angle
a = math.radians(calcAngle(lis[2], lis[3]))
print(math.sqrt(lis[0]*lis[0]+lis[1]*lis[1]-2*lis[0]*lis[1]*math.cos(a)))

Measured memory_bytes: 9416
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int m;
	while(cin >> m, m) {
		vvi seiza(m, vi(2));
		REP(i, m) {
			cin >> seiza[i][0] >> seiza[i][1];
		}
		sort(ALL(seiza));

		int n;
		cin >> n;
		vvi stars(n, vi(2));
		map<pii, int> table;
		REP(i, n) {
			cin >> stars[i][0] >> stars[i][1];
			table[make_pair(stars[i][0], stars[i][1])]++;
		}
		sort(ALL(stars));

		REP(i, n-m) {
			int sx = stars[i][0]-seiza[0][0];
			int sy = stars[i][1]-seiza[0][1];

			bool flag = true;
			FOR(j, 1, m-1) {
				if(!table[make_pair(seiza[j][0]+sx, seiza[j][1]+sy)]) {
					flag = false;
					break;
				}
			}
			if(flag) {
				cout << sx << " " << sy << endl;
				goto next;
			}
		}

		next:;
	}
}

Measured memory_bytes: 1368
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
int main(void){
	int n,ans=0;cin>>n;
	map<int,int> has;
	while(n--){
		int a;cin>>a;
		has[a]++;
	}
	for(auto it:has){
		if(it.fir>it.sec){ans+=it.sec;}
		else{ans+=it.sec-it.fir;}
	}
	cout<<ans<<endl;
	RE;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n,m;
    cin>>n>>m;
    int day,rwd;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int> >> work;
    priority_queue<int> reward;
    int totalrewd = 0;

    for(int i=0;i<n;i++){
        cin>>day>>rwd;
        work.push({day,rwd});
    }

    for(int i=1;i<=m;i++){
        while(!work.empty() and work.top().first<=i){
            reward.push(work.top().second);
            work.pop();
        }
        if(!reward.empty()){
            totalrewd+=reward.top();
            reward.pop();
        }
    }
    cout<<totalrewd<<endl;

    return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int c_[300100];
ll M = 998244353;
ll inv(ll x) {
	ll res = 1;
	ll p = M-2;
	while(p) {
		if(p&1) res = (res * x) % M;
		x = x*x % M;
		p /= 2;
	}
	return res;
}
ll comb(int n, int r) {
	if(c_[r]) return c_[r];
	return c_[r] = comb(n, r-1) * (((ll)n-(r-1)) * inv(r) % M) % M;
}

int main() {
	ll N, A, B, K;
	cin >> N >> A >> B >> K;
	c_[0] = 1;
	for(int i = 0; i <= N; i++) {
		comb(N,i);
	}

	ll res = 0;
	for(int i = 0; i <= N; i++) {
		if(A*i <= K && (K-A*i) % B == 0 && (K-A*i) / B <= N) {
			res += comb(N,i) * comb(N,(K-A*i)/B);
			res %= M;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,p,q,r,oh=300;
  cin>>a>>b>>c;
  p=a+b;
  q=b+c;
  r=a+c;
  oh=min(oh,p);
  oh=min(oh,q);
  oh=min(oh,r);
  cout<<oh<<endl;
  

  
  
 return 0; 
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        var strs = Console.ReadLine().Split(' ');
        var n = int.Parse(strs[0]);
        var a = int.Parse(strs[1]);
        var b = int.Parse(strs[2]);

        Console.Write(Math.Min(a * n, b));
    }
}


Measured memory_bytes: 13140
n = gets.to_i
pa = gets.split.map(&:to_i)

a = Array.new(n,1)
b = Array.new(n,1)

n.times{|i|
  idx = pa[i]-1
  a[idx] = i+1
  b[idx] = i+1
}

(n-1).times{|i|
  a[i+1] += a[i]
  b[n-i-2] += b[n-i-1]
}

puts a*" "
puts b*" "


Measured memory_bytes: 6852
#include<stdio.h>
int main(void){
    int x,y;
    while(1){
        scanf("%d%d",&x,&y);
        if(x==0&&y==0){
            break;
        }
        if(x<=y){
            printf("%d %d\n",x,y);
        }
        if(x>y){
            printf("%d %d\n",y,x);
        }

    }













return 0;
}

Measured memory_bytes: 600
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1e9+7	// int 1000000007
const int inf{int(1e9)};	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;


int main(void) {
	
	int a, b, c;
	cin >> a >> b >> c;

	FOR(i, 1, b) {
		if ((a*i)%b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

set<int> to[101];
vector<int> from[101];
vector<int> d(101);
vector<int> f(101);

int dfs(int n, int t){
    if(d[n] != -1) return t-1;
    d[n] = t;
    for(auto it = to[n].begin(); it != to[n].end(); it++){
        t = dfs((*it),t+1);
    }
    t++;
    f[n] = t;
    return t;
}

int main(){
    int n;
    cin >> n;
    
    for(int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            to[u].insert(v);
            from[v].push_back(u);
        }
        d[u] = -1;
        f[u] = -1;
    }
    
    int t = dfs(1,1);
    for(int i = 1; i <= n; i++){
        if(d[i] == -1){
            t = dfs(i,t+1);
        }
    }

    for(int i = 1; i <= n; i++){
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b + c == a * 2 || a + b + c == b * 2 || a + b + c == c * 2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

int GCD(int a,int b){
	if(max(a,b)%min(a,b)==0){
		return min(a,b);
	}else{
		return GCD(min(a,b),max(a,b)%min(a,b));	
	}
}

int LCM(int a,int b){
	return a*b/GCD(a,b);
}
	
int main(){
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	
	for(int i=0;i<n;i++){
		cin >> a[i];
		b[i]=a[i]-1;
	}
	
	long long ans=0;
	for(int i=0;i<n;i++){
		ans+=b[i];
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	int mn = 1e9, cnt = 0;
	for (int i = 0; i < N; i++)
	{
		int P;
		cin >> P;
		if (P <= mn)
			cnt++;
		mn = min(mn, P);
	}
	cout << cnt << endl;
}



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

using namespace std;


typedef long long ll ;
const ll mk = 100055;
const ll logn  = 29;
const ll mod = 1e9 + 7; 
#define endl "\n"
#define IOS  ios::sync_with_stdio(0); cin.tie(0);
#define fi first
#define se second
#define pii pair<ll,ll>
#define pq priority_queue
#define UwU              uwu
#define UwU              Mikuwu
#define Miku             best_waifu
#define Miku_dancing     god_waving
#define a_Miku           cho_doi_bot_ngu

ll Sum, ans = 0  ; 

ll log10(ll x) {
	if(x == 0) return 0;
	return log10(x / 10) + 1;
}

ll query(ll x, ll y)
{
    if (!y) return 1;
    ll temp = query(x, y / 2);
    if (y % 2) return temp * temp % mod * x % mod;
    return temp * temp % mod;
}

signed main()
{
    
    cin >> Sum;
    ll r = 1, sub_sum = 0 ; 
    for (ll l = 1; l < 1e7; l++)
    {
        while (sub_sum + log10(r) <= Sum) sub_sum += log10(r), r++;
        if (sub_sum == Sum) ans++;
        sub_sum -= log10(l);
    }   // brute_forces for Miku to dance uwu
    for (ll dig = 8; dig <= Sum; dig++)
    {
        if (Sum % dig == 0)
        {
            ans = (ans  + query(10, dig) - query(10, dig - 1) - Sum / dig + 1 + mod) % mod;   // number of start a sequence
        }
        ll r = Sum % dig;
        if (r == 0) r += dig;
        ll val = r * (dig + 1);
        ll c = 1ll * dig * (dig + 1);
        if (val < Sum) ans = (ans + (Sum - val) / c + ((Sum - val) % c > 0)) % mod;   // still can take those numbers as a sequence
    }
    cout << ans % mod;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
      cin>>s;
     int x=0;
    for(int i=0;i<s.length();i++)
    {
        x+=s[i]-48;
    }
    //cout<<x;
  if(x%9==0)
    cout<<"Yes";
  else
    cout<<"No";
}


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

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


	int a, b;
	cin >> a >> b;

	if (a > 8 || b > 8)
		cout << ":(\n";
	else 
		cout << "Yay!\n";
}

Measured memory_bytes: 256
import sys

import numpy as np

sys.setrecursionlimit(100000)
INF = float('inf')

H, W = list(map(int, sys.stdin.readline().split()))
_ = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

board = np.zeros(H * W, dtype=int)
board[np.array(A).cumsum()[:-1]] = 1
board = (board.cumsum() + 1).reshape(H, W)
for i, row in enumerate(board):
    print(*(row if i % 2 else reversed(row)))


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i) cin >> a[i];
    int total = accumulate(a.begin(), a.end(), 0);
    if (n >= total) cout << n - total << endl;
    else cout << -1 << endl;
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; cin>>n>>k;
	int64_t ans=(k?0:-n);
	for(int i=k+1;i<=n;++i){
		ans+=1L*n/i*(i-k)+max(n%i-k+1,0);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3624
A, B, C, D = map(int, input().split())

def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x * (y // gcd(x, y))

def N(x, y):
    """x以下の整数のうちyで割り切れるものの個数"""
    return x // y

def N2(x, y, z):
    """x以下の整数のうちyまたはzで割り切れるものの個数"""
    return N(x, y) + N(x, z) - N(x, lcm(y, z))

n = N2(B, C, D) - N2(A - 1, C, D)
n = B - A + 1 - n
print(n)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e3+6;
const int mod = 1e9+7;
const ll inf = 1e18;
int cnt[N];
int lst[N];
void solve(){
    ll a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+')cout<<a+b<<endl;
    else cout<<a-b<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var n = h[0];
		var ls = Enumerable.Range(0, h[1]).Select(i => new { i, ss = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).Skip(1).ToArray() }).ToArray();
		var p = Console.ReadLine().Split().Select(x => int.Parse(x) == 0).ToArray();

		var f = Enumerable.Range(0, n + 1).Select(i => (int)Math.Pow(2, i)).ToArray();
		Console.WriteLine(Enumerable.Range(0, f[n]).Count(b => ls.All(l => l.ss.Select(s => (b & f[s]) != 0).Aggregate((x, y) => x ^ y) ^ p[l.i])));
	}
}


Measured memory_bytes: 13524
from math import sqrt

x = int(input())

for i in range(-int(sqrt(sqrt(x))), int(sqrt(sqrt(x))) + 1):
    for j in range(-int(sqrt(sqrt(x))), int(sqrt(sqrt(x))) + 1):
        if i ** 5 - j ** 5 == x:
            print(i, j)
            exit()


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;


int main() {
	int n;
	cin >> n;
	VI a(n), b(n);
	REP(i, n) {
		cin >> a[i];
		b[a[i] - 1] = i;
	}

	
	ll ans = 0;

	set<int> s;
	s.insert(-1);
	s.insert(n);
	
	REP(i, n) {
		set<int>::iterator itr = s.lower_bound(b[i]);
		ll right = (*itr) - b[i];
		itr--;
		ll left = b[i] - (*itr);
		ll tmp = a[b[i]] * left*right;
		ans += tmp;
		s.insert(b[i]);
	}
	cout << ans << endl;

}

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

inline int read()
{
	int x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

const int MAXN = 600005;
const int mod = 924844033;
std::vector<int> G[MAXN];
int fac[MAXN],ifac[MAXN],cnt[MAXN],sz[MAXN];
int f[MAXN],g[MAXN],rev[MAXN];
int n;

inline void addedge(int u,int v)
{
	G[u].push_back(v);
	G[v].push_back(u);
}

inline int qpow(int x,int k)
{
	int res=1;
	for(int i=k; i; i>>=1,x=1ll*x*x%mod)
		if(i&1) res=1ll*res*x%mod;
	return res;
}

inline void init(int n)
{
	for(int i=fac[0]=1; i<=n; ++i)
		fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=qpow(fac[n],mod-2);
	for(int i=n; i; --i)
		ifac[i-1]=1ll*ifac[i]*i%mod;
}

inline int cat(int n,int k)
{return 1ll*fac[n]*ifac[k]%mod*ifac[n-k]%mod;}

inline void dfs(int x,int fa)
{
	sz[x]=1;
	for(int y : G[x])
		if(y^fa) dfs(y,x),sz[x]+=sz[y],++cnt[sz[y]];
	++cnt[n-sz[x]];
}

inline void ntt(int *a,int n,int type)
{
    for(int i=0; i<n; ++i)
        if(i<rev[i]) swap(a[i],a[rev[i]]);
    for(int i=1; i<n; i<<=1)
    {
        int rt=qpow(5,(mod-1)/(i<<1));
        if(type==-1) rt=qpow(rt,mod-2);
        for(int j=0; j<n; j+=(i<<1))
            for(int k=0,w=1; k<i; ++k,w=1ll*w*rt%mod)
            {
                int x=a[j+k],y=1ll*w*a[j+k+i]%mod;
                a[j+k]=(x+y)%mod,a[j+k+i]=(x-y+mod)%mod;
            }
    }
    if(type==1) return;
    int inv=qpow(n,mod-2);
    for(int i=0; i<n; ++i)
        a[i]=1ll*a[i]*inv%mod;
}

int main(int argc, char const *argv[])
{
	n=read();
	for(int i=1; i<n; ++i) addedge(read(),read());
	dfs(1,0); init(n);
	for(int i=1; i<=n; ++i) f[i]=1ll*cnt[i]*fac[i]%mod;
	for(int i=(reverse(f,f+n+1),0); i<=n; ++i) g[i]=ifac[i];
	int lim=1,l=0;
	for(; lim<=n<<1; lim<<=1,++l);
	for(int i=0; i<lim; ++i)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	ntt(f,lim,1),ntt(g,lim,1);
	for(int i=0; i<lim; ++i)
		f[i]=1ll*f[i]*g[i]%mod;
	ntt(f,lim,-1); reverse(f,f+n+1);
	for(int i=1; i<=n; ++i)
	{
		int t=1ll*ifac[i]*f[i]%mod;
		printf("%lld\n",(1ll*n*cat(n,i)%mod-t+mod)%mod);
	}
	return 0;
}

Measured memory_bytes: 46492
<?php
fscanf(STDIN, "%s", $str);

$map = str_split($str);
$length = count($map);
$half = intdiv($length, 2);

for($i=0;$i<$half;$i++){
    if($map[$i] != $map[$length - $i -1]){
        echo "No";
        exit;
    }
}
$quoter = intdiv($half, 2);
for($i=0; $i<$quoter; $i++){
    if($map[$i] != $map[$length - $i -1]){
        echo "No";
        exit;
    }

}
$start = ($length + 3) / 2;
$endhalf = $length - intdiv(($length - $start), 2);
for($i=$start;$i<$endhalf;$i++){
    if($map[$i-1] != $map[$length - ($i - $start) -1]){
        echo "No";
        exit;
    }
}

echo "Yes";

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

int main(void)
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;

    for (int i = 0; i < n; ++i)
    {
      int math, englith, japanese;
      cin >> math >> englith >> japanese;

      if (math == 100 or englith == 100 or japanese == 100
          or 180 <= math + englith
          or 240 <= math + englith + japanese)
      {
        cout << 'A' << endl;
      }
      else if (210 <= math + englith + japanese
               or (150 <= math + englith + japanese 
                   and ( 80 <= math or 80 <= englith )
                  )
              )
      {
        cout << 'B' << endl;
      }
      else
      {
        cout << 'C' << endl;
      }
    }
  }
  return 0;
}

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

int main()
{
    int A, B;
    cin >> A >> B;

    int a = 0, b = 0;

    for( int i = 0; i < 16; ++i ){
        if( i % 2 ){
            if( a < A ) ++a;
        } else {
            if( b < B ) ++b;
        }
    }

    if( a == A && b == B ) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)

def dfs(index, visited, cycle):
    visited[index] = True
    cycle.append(index)
    for i in edges[index]:
        if visited.get(i):
            return cycle[cycle.index(i):]
        ret = dfs(i, visited, cycle)
        if ret:
            return ret
    visited[index] = False
    cycle.pop(-1)
    return None

def find_local_minimum(cycle):
    n = len(cycle)
    ind = {v: i for (i, v) in zip(range(n), cycle)}
    ret = []
    i = 0
    while True:
        ret.append(i)
        nxt = 0
        for j in [ind[v] for v in edges[cycle[i]] if v in ind]:
            if j < i:
                j += n
            nxt = max(nxt, j)
        if nxt >= n:
            ret = ret[ret.index(nxt % n):]
            break
        i += 1
        while i < nxt:
            del ind[cycle[i]]
            i += 1
    return [cycle[i % n] for i in ret]

cycle = None
visited = {}
for start in range(n):
    if start not in visited:
        cycle = dfs(start, visited, [])
        if cycle:
            break

if cycle:
    ret = find_local_minimum(cycle)
    print(len(ret))
    for i in ret:
        print(i + 1)
else:
    print(-1)



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

int main() {
    int64_t K, A, B;
    cin >> K >> A >> B;
    for (int64_t i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}

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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  sort(a.begin(), a.end());
  if(a.at(0) == 5 && a.at(1) == 5 && a.at(2) == 7) {
    cout << "YES";
  }
  else {
    cout << "NO";
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int n;cin>>n;int k;cin>>k;
      int arr[n];
      for(int i=0;i<n;i++) cin>>arr[i];
      sort(arr,arr+n);
      int sum=0;
      for(int i=0;i<k;i++)
      {
        sum+=arr[i];
      }
      cout<<sum;
      return 0;
    }

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
    ll h, w;
    cin >> h >> w;
    if(h == 1 && w == 1) {
        cout << 1 << endl;
        return 0;
    } 
    if(h > w) swap(h, w);
    if(h == 1) {
        cout << w - 2 << endl;
    }
    else if(h == 2) {
        cout << 0 << endl;
    }
    else {
        cout << (h-2)*(w-2) << endl;
    }
    return 0;
}

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

using namespace std;
const int MAXN = 1e3 + 15;
int h, w, sx, sy, tx, ty, cnt;
char a[MAXN][MAXN];
int idx[MAXN][MAXN];
vector <int> g[MAXN * MAXN];
bool vis[MAXN * MAXN];

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
void dfs(int x, int y, int col) {
    idx[x][y] = col;
    for(int i = 0; i <= 3; i++) {
        int fx = x + dx[i];
        int fy = y + dy[i];
        if(fx < 1 || fx > h || fy < 1 || fy > w) continue;

        if(a[fx][fy] == '#') continue;

        if(idx[fx][fy] == 0) dfs(fx, fy, col);
    }

}
void find_way(int x, int y) {
    for(int i = -2; i <= 2; i++) {
        for(int j = -2; j <= 2; j++) {
            int fx = x + i;
            int fy = y + j;
            if(fx < 1 || fx > h || fy < 1 || fy > w) continue;

            if(a[fx][fy] == '#') continue;

            g[idx[x][y]].push_back(idx[fx][fy]);
        }
    }    
}
int bfs() {
    vis[idx[sx][sy]] = true;
    queue< pair<int, int> > que;
    que.push(make_pair(idx[sx][sy], 0));

    while(!que.empty()) {
        pair<int, int> it = que.front();
        que.pop();

        if(it.first == idx[tx][ty]) return it.second;

        for(int i = 0; i < g[it.first].size(); i++) {
            int v = g[it.first][i];
            if(!vis[v]) {
                vis[v] = true;
                pair<int, int> nxt = make_pair(v, it.second + 1);
                que.push(nxt);
            }
        }
    }

    return -1;
}
int main() {

    scanf("%d %d", &h, &w);
    scanf("%d %d", &sx, &sy);
    scanf("%d %d", &tx, &ty);

    for(int i = 1; i <= h; i++) {
        scanf("%s", a[i] + 1);
    }
    
    cnt = 0;
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if(a[i][j] == '.' && idx[i][j] == 0) {
                cnt++;
                dfs(i, j, cnt);
            }
        }
    }

    // for(int i = 1; i <= h; i++) {
    //     for(int j = 1; j <= w; j++) {
    //         printf("%d ", idx[i][j]);
    //     }
    //     printf("\n");
    // }

    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if(a[i][j] == '.') {
                find_way(i, j);
            }
        }
    }

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

    return 0;
}

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

int main(){
	int A[4];
	int B[4];
	int hit;
	int blow;
	while(cin >> A[0] >> A[1] >> A[2] >> A[3]){
		hit = 0;
		blow = 0;
		cin >> B[0] >> B[1] >> B[2] >> B[3];
		for(int i=0;i<4;i++){
			if(A[i] == B[i]){
				hit += 1;
			}
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(i != j && A[i] == B[j]){
					blow += 1;
				}
			}
		}
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y;
  int a[101],b[101];
  cin>>n>>m>>x>>y;
  a[0]=x;
  b[0]=y;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=1;i<=m;i++){
    cin>>b[i];
  }
  sort(a,a+n+1);
  sort(b,b+m+1);
  if(a[n]>=b[0]) cout<<"War"<<endl;
  else cout<<"No War"<<endl;
  return 0;
}


Measured memory_bytes: 256
//Zory-2018
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<stack>
using namespace std;
 
namespace mine
{
	const int MAX_N=60;
	const int INF=0x3f3f3f3f;
	typedef long long ll;
 
	struct LJB
	{
		int hou[MAX_N];
		struct Edge{int y,g;}e[MAX_N];
		int ln;void ins(int x,int y) {e[++ln]=(Edge){y,hou[x]};hou[x]=ln;}
		LJB() {ln=0;memset(hou,0,sizeof hou);}
	}E;
 
	struct Nod
	{
		ll w,v;
		ll num;
	}p[MAX_N];
	bool cmp(Nod a,Nod b) {return a.w*b.v>b.w*a.v;}
	//规避除法，已知都是非负数
 
	void dfs(int x,int fa)
	{
		p[x].w=1;
		for(int k=E.hou[x];k>0;k=E.e[k].g)
		{
			int y=E.e[k].y;if(y==fa) continue;
			dfs(y,x);
			p[x].w+=p[y].w;p[x].v+=p[y].v;
		}
	}
 
	ll f[50005];
	void main()
	{
		int n;ll mxV,D;scanf("%d%d%d",&n,&mxV,&D);
		scanf("%lld",&p[1].v);
		for(int i=2;i<=n;i++)
		{
			int fa;scanf("%lld%d",&p[i].v,&fa);
			E.ins(fa,i);
		}
		dfs(1,0);
 
		memset(f,63,sizeof f);f[0]=0;
		for(int i=1;i<=n;i++)
		{
			ll num=mxV/p[i].v;
			if(i>1) num=min(num,(ll)D);
 
			if(num>n) p[i].num=num-n,num=n;
			else p[i].num=0;
 
			ll now=1;
			while(num>0)
			{
				ll w=now*p[i].w,v=now*p[i].v;
				for(int ww=50000;(ll)ww>=w;ww--) f[ww]=min(f[ww],f[ww-w]+v);
				num-=now;
				now=min(now<<1,num);
			}
		}
 
		sort(p+1,p+n+1,cmp);
		ll ans=0;
		for(int ww=0;ww<=50000;ww++)
		{
			if(f[ww]>mxV) continue;
			ll ret=ww,left=mxV-f[ww];
			for(int i=1;i<=n;i++)//debug 注意此时不是原编号
			{
				ll num=min(left/p[i].v,p[i].num);
				left-=num*p[i].v;ret+=num*p[i].w;
			}
			ans=max(ans,ret);
		}
		printf("%lld",ans);
	}
};
 
int main()
{
	mine::main();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

//uses natural mod 2^64 , assume 0 based indexing everywhere
struct PolynomialHashing {
   int N;
   string s;
   char offset = 0;
   long long prime;
   long long *fHash, *rHash, *pk;

   //declare two instances with different primes as base to be more certain of not falling for anti hash cases
   void init(string str, long long pri = 257){
      s = str;
      prime = pri;
      N = s.size();
      fHash = new long long[N], rHash = new  long long[N], pk = new  long long[N];
      fHash[0] = s[0] - offset + 1;
      pk[0] = 1;
      rHash[N - 1] = s[N - 1] - offset + 1;
      //Complexity : O(n)
      for(int i = 1; i < N; i++) {
         fHash[i] = ((fHash[i - 1] * prime) % mod + s[i] - offset + 1) % mod;
         pk[i] = (pk[i - 1] * prime) % mod;
         rHash[N - 1 - i] = ((rHash[N - i] * prime)%mod + s[N - i - 1] - offset + 1) % mod;
      }
   }
   //front hash of subtring from (l,r)
   long long getFrontHash (long long l, long long r) {
      if(l == 0) return fHash[r];
      if(l > r) return 0;
      return (fHash[r] - (fHash[l - 1] * pk[r - l + 1]) % mod + mod) % mod;
   }
   //reverse hash of subtring from (l,r)
   long long getReverseHash(long long l, long long r) {
      if(r == N - 1) return rHash[l];
      if(l > r) return 0;
      return (rHash[l] - (rHash[r + 1] * pk[r - l + 1]) % mod + mod) % mod;
   }
};

string s;
PolynomialHashing S;
PolynomialHashing T;

bool f(int len){
   int n = sz(s);
   for (int i = 0; i+len-1 < n; ++i)
   {
      //[i, i+len-1]
      //[j, j+len-1]
      for (int j = i+len; j+len-1 < n; ++j)
      {
         if (S.getFrontHash(i, i+len-1) == S.getFrontHash(j, j+len-1) and 
            T.getFrontHash(i, i+len-1) == T.getFrontHash(j, j+len-1))
            return 1;
      }
   }

   return 0;
}

void solve0(){
   int n;
   cin >> n;

   cin >> s;

   S.init(s);
   T.init(s, 97861);

   int low = 0, high = n, ans = 0;
   while(low <= high){
      int mid = (low + high) >> 1;
      if(f(mid)){
         ans = mid;
         low = mid + 1;
      }
      else{
         high = mid - 1;
      }
   }
   cout<<ans;
}

int32_t main(){_

   int q = 1;
   // cin >> q;

   while(q--){
      solve0();
   }

   return 0;
}

Measured memory_bytes: 640
# include <iostream>
using namespace std; 
int main(){
  int n, i, j, w; 
  cin>>n>>w; 
  int ar[n];
  long long int val[n];
  for(i=0;i<n;i++){
    cin>>ar[i]>>val[i];
  }
  long long int dp[n][w+1];
  for(i=0;i<n;i++){
    dp[i][0]=0;
  }
  for(j=0;j<=w; j++){
    if(ar[0]>j){
      dp[0][j]=0;
    }
    else{
      dp[0][j]=val[0];
    }
  }
  for(i=1;i<n;i++){
    for(j=0;j<=w; j++){
      if(ar[i]>j){
        dp[i][j]=dp[i-1][j];
      }
      else{
        dp[i][j]=max(dp[i-1][j],(val[i]+dp[i-1][j-ar[i]]));
      }
    }
  }
/*  for(i=0;i<n;i++){
    for(j=0;j<=w; j++){
      cout<<dp[i][j]<<" ";
    }
    cout<<"\n";
  }*/
  cout<<dp[n-1][w];
  return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define M 998244353
const int inf=4e18;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	vector<pair<int,int> > v,v1;
	for(int i=0;i<n;i++)
	{
		int x,y;cin>>x>>y;
		v.emplace_back(x,y);
	}
	v1=v;
	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end(),[&](const pair<int,int> &x,const pair<int,int> &y){return x.second<y.second;});
	if(n&1)
	{
		int x=n/2;
		cout<<v1[x].second-v[x].first+1<<'\n';
	}
	else
	{
		int x=n/2-1;
		int y=x+1;
		double l=(v[x].first+v[y].first)/2.0;
		double r=(v1[x].second+v1[y].second)/2.0;
		cout<<(int)((r-l)*2)+1<<'\n';
	}
}

Measured memory_bytes: 9444
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(m)]
mi=1
ma=n
for i in range(m):
  mi=max(mi,a[i][0])
  ma=min(ma,a[i][1])

if mi>ma:
  print("0")
else:
  print(ma-mi+1)



Measured memory_bytes: 27332
#include<stdio.h>

int main(void){

	int n,m,i,j,num,tmp;
	int *B,**A;

	scanf("%d %d",&n,&m);	/* n??m?????????A?????\??? */
		B = (int *)malloc(sizeof(int)*m);
		A = (int **)malloc(sizeof(int *)*n);

	for(i=0;i<n;i++){	/* ??????A?????????????¨???? */
		A[i] = (int *)malloc(sizeof(int )*m);
	}

	for(i=0;i<n;i++){	/* m??1??????????????????b????????????i?????????????´?(i=1,2,...,m) */
		for(j=0;j<m;j++){	/* i???j?????????????´?aij(i=1,2,...,n,j=1,2,...,m) */
			scanf("%d",&A[i][j]);
		}
	}

	for(i=0;i<m;i++){		/* ????????????b?????????????¨????  */
		scanf("%d",&B[i]);	/*  m??1??????????????????B */
	}

	for(i=0;i<n;i++){
		tmp = 0;
			for(j = 0;j<m;j++){
				tmp = tmp + A[i][j] * B[j];		/* c???i?????????????´?ci */
	}
			printf("%d\n",tmp);		/* A???????´?aij */
		}							/* ????????????c???????´?ci */
	for(i=0;i<n;i++){
		free(A[i]);
	}
	free(A);

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<vector>
int main()
{
	std::vector<bool>is_prime(50020, true);
	const int root = static_cast<int>(floor(sqrt(50021)));
	for (int i = 0; i <= root - 2; i++)
	{
		if (is_prime[i])
		{
			for (int j = i + 2; (i + 2) * j < 50021; j++)
			{
				is_prime[(i + 2) * j - 2] = false;
			}
		}
	}
	while (true)
	{
		int n;
		std::cin >> n;
		if (n == 0)
		{
			break;
		}
		int cnt = 0;
		for (int i = 0; i < n; i++)
		{
			if (is_prime[i] && is_prime[n - i - 4])cnt++;
			if (i + 2 >= n / 2)break;
		}
		std::cout << cnt << std::endl;
	}
	return 0;
}


Measured memory_bytes: 2972
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var y = int.Parse(line[1]);
        var z = int.Parse(line[2]);
        var K = int.Parse(line[3]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var c = Array.ConvertAll(line, long.Parse);
        Array.Sort(a); Array.Sort(b); Array.Sort(c);
        Array.Reverse(a); Array.Reverse(b); Array.Reverse(c);
        getAns(a, b, c, x, y, z, K);
    }
    static void getAns(long[] a, long[] b, long[] c, int x, int y, int z, int K)
    {
        var t = new List<long>();
        for (int i = 0; i < x; i++)
            for (int j = 0; j < y; j++)
                for (int k = 0; k < z; k++)
                {
                    long w = (i + 1) * (long)(j + 1) * (k + 1);
                    if (w <= K) t.Add(a[i] + b[j] + c[k]);
                }
        Console.WriteLine(string.Join("\n", t.OrderByDescending(p => p).Take(K)));
    }
}

Measured memory_bytes: 17760
// https://www.youtube.com/watch?v=6og8YHd3Itw&list=PLn8m49B2OVF4kVTE0TK1PT-R0R9QhTVyS&index=2
#include<bits/stdc++.h>
using namespace std;
#define inf 1e18
#define ll long long
int W , w[100] , v[100];
ll dp[100][100001], n;

// dp[id][j] = minumum weight using i values;
// id = value

int32_t main()
{
    cin>>n>>W;
    for(int i=0 ; i<100 ; i++)
        for(int j=0; j<=100000 ; j++)
        dp[i][j] = inf;

    for(int i=0 ; i<n ; i++)
        cin>>w[i]>>v[i];

    dp[0][0] = 0;
    dp[0][v[0]] = w[0];

    for(int id = 1 ; id<n ; id++){
        dp[id][0] = 0;
        for(int j=1 ; j<= 100000 ; j++){
            dp[id][j] = dp[id-1][j];

            if(j >= v[id])
                dp[id][j] = min(dp[id][j] , w[id]+dp[id-1][j-v[id]]);

        }
    }
    ll ans;

    for(int val = 100000 ; val>=0 ; val--){
        if(dp[n-1][val] <= W){
            ans = val;
            break;
        }
    }
    cout<<ans;
}






















Measured memory_bytes: 81724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
struct unionfind{
    vector<int> par,rank;
    unionfind(int x){
        par.resize(x);
        rank.resize(x);
        for(int i=0; i<x; i++)par[i]=-1,rank[i]=0;
    }
    int root(int x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    void uni(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return;
        if(rank[x]<rank[y]){par[y]+=par[x];par[x]=y;}
        else{
            par[x]+=par[y];par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k,l; cin>>n>>k>>l;
    unionfind  uf1(n), uf2(n);

    rep(i,k){
        ll p,q;cin>>p>>q;
        uf1.uni(p-1, q-1);
    }
    rep(i,l){
        ll r,s;cin>>r>>s;
        uf2.uni(r-1, s-1);
    }
    map<P, ll> m;
    rep(i,n){
        m[{uf1.root(i), uf2.root(i)}]++;
    }
    for(int i=0; i<n; i++){
        cout<<m[{uf1.root(i),uf2.root(i)}]<<" ";
    }
    return 0;
}

Measured memory_bytes: 17532
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, L: int, S: "List[str]"):
    S.sort()
    ret = ''.join(S)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, L, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main ()
{
    int k,s,x,y,z,b=0;
    scanf ("%d %d", &k ,&s);
    for (x=0;x<=k;x++)
        for (y=0;y<=k;y++){
            z=s-x-y;
            if (z>=0 && z<=k) 
                b++;


        }
    printf("%d", b);





    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve(){
	string s,t;
	cin>>s>>t;
	int n=s.size(),m=t.size(),ans=m;
	for(int i=0;i<n-m+1;i++){
		int cnt=0;
		for(int j=0,k=i;j<m;j++,k++)
			if(s[k]!=t[j])cnt++;
		ans=min(ans,cnt);

	}
	cout<<ans;

}
int main()
{
	Start;

	int t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
		cout << "\n";
	}
	return 0;
} 

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

int main() {
    int a, b;
    string res;
    cin >> a >> b;
    if (a*b % 2 == 0) {
        res = "Even";
    } else {
        res = "Odd";
    }
    cout << res << endl;
    return 0;
}

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

int main() {
  char S[2000000];
  char T[2000000];
  scanf("%s %s", &S, &T);
  int counter = 0;
  for(int i = 0; i < strlen(S); i++){
    if(S[i] != T[i]){
      counter++;
    }
  }
  printf("%d", counter);
}

Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
 ll a,b,flag=0;
 cin>>a>>b;
 ll aa[a];
 for(ll i=0;i<a;i++)
  {
    cin>>aa[i];
  }

  sort(aa,aa+a);

  for(ll i=0;i<b;i++)
  flag+=aa[i];

  cout<<flag<<endl;
return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

bool p[200005];

int main(){
    fill(p,p+200000,true);
    for(int i=2;i<=200000;i++){
        if(p[i]){
            for(int j=i+i;j<=200000;j+=i){
                p[j]=false;
            }
        }
    }
    int x;
    cin>>x;
    for(int i=x;;i++){
        if(p[i]){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

using namespace std;
#define int long long
#define N 666666
int arr[N],sum1[N],sum2[N];
signed main(){
	int a,b;
	cin>>a>>b;
	if(a==b){
		cout<<"0";return 0;
	}
	if(abs(a)==abs(b)){
		cout<<"1";return 0;
	}
	if(a==0){
		if(b>=0) cout<<b-a;else cout<<abs(b)+1;
		return 0;
	}
	if(b==0){
		if(a<=0) cout<<abs(a);
		else cout<<a+1;
		return 0;
	}
	if(a>0&&b>0){
		if(a>b){
			cout<<a-b+2;
		}else{
			cout<<b-a;
		}
		return 0;
	}
	if(a*b<0){
		cout<<abs(abs(a)-abs(b))+1;return 0;
	}
	if(a<0&&b<0){
		if(a>b){
			cout<<abs(a-b)+2;
		}else{
			cout<<abs(a-b);
		}
	} 
	
	return 0;
}
/*
2 -4
4 -2

-4 2
-4  -9
*/

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }


int main(){

    lli N;
    cin>>N;

    priority_queue<pair<lli,lli>,vector<pair<lli,lli>>,greater<pair<lli,lli>>> q;

    REP(i,0,N){
        lli x,l;
        cin>>x>>l;
        q.push({x+l,x-l});
    }

    lli now=-INF;
    lli cnt=0;
    while(q.size()){
        pair<lli,lli> p = q.top();
        LOG2(p.first,p.second);
        q.pop();
        if(now>p.second)continue;
        now = p.first;
        cnt++;
    }
    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>

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

using namespace std;
using ll = long long;

const long long INF = 1e18;

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

    sort(A,A+N);

    if(A[0]==0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    rep(i,N){
        if(INF/A[i] < ans){
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4384
int main(void)
{
    int N;
    int *A, *B, *C;
    scanf("%d", &N);
    A = (int *)malloc(sizeof(int) * N);
    B = (int *)malloc(sizeof(int) * N);
    C = (int *)malloc(sizeof(int) * (N - 1));

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &B[i]);
    }
    for (int i = 0; i < N - 1; i++)
    {
        scanf("%d", &C[i]);
    }
    int degm = 0;
    for (int i = 0; i < N; i++)
    {
        degm += B[A[i]-1];
    }
    for (int i = 1; i < N; i++)
    {
        if(A[i-1]==A[i]-1){
        degm += C[A[i]-2];
        }
    }

    printf("%d",degm);
    return 0;
}

Measured memory_bytes: 128