akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <set>
using namespace std;
int N;
char St[200005];
int Val[(1 << 26) + 5];
set <int> S;
void Read()
{
    cin.getline(St + 1, 200005);
    N = strlen(St + 1);
}

void Solve()
{
    int number = 0;
    S.insert(0);
    for(int i = 1; i <= N; i++)
    {
        int ch = St[i] - 'a';
        int ans = N + 1;
        number = (number ^ (1 << ch));
        for(int j = 0; j < 26; j++)
        {
            int conf = (number ^ (1 << j));
            if(S.find(conf) == S.end())
                continue;
            ans = min(ans, Val[conf] + 1);
        }

        int conf = number;
        /*if(S.find(conf) == S.end())
            continue;*/
        if(S.find(conf) != S.end())
            ans = min(ans, Val[conf] + 1);
        if(S.find(number) != S.end())
            Val[number] = min(Val[number], ans);
        else
        {
            Val[number] = ans;
            S.insert(number);
        }
        if(i == N)
            cout << ans << "\n";
    }
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 271104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =1e6+10;
const int mod=1e9+7;
int a[maxn];
int mp[maxn];
int vis[1010];

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


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    vector<int>cnt;
    int f=0;
    for(int i=1;i<=n;i++)
    {
        f=gcd(f,a[i]);
    }
    if(f!=1)
    {
        cout<<"not coprime"<<'\n';
        return 0;
    }
    for(int i=2;i<1005;i++)
    {
        if(vis[i])
            continue;
        cnt.pb(i);
        for(int j=i;j<1005;j+=i)
        {
            vis[j]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(auto &v:cnt)
        {
            if(a[i]%v==0)
            {
                mp[v]++;
                if(mp[v]>1)
                {
                    cout<<"setwise coprime"<<'\n';
                    return 0;
                }
                while(a[i]%v==0)
                    a[i]/=v;
            }
        }
        if(a[i]>1)
            mp[a[i]]++;
        if(mp[a[i]]>1)
        {
            cout<<"setwise coprime"<<'\n';
            return 0;
        }
    }
    cout<<"pairwise coprime"<<'\n';

}


Measured memory_bytes: 7764
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

#@pysnooper.snoop()
n=int(stdin.readline().rstrip())
m=0
for i in range(n):
    a=int(stdin.readline().rstrip())
    for j in range(2,int(a**0.5)+1):
        if a%j==0:
            break
    else:
        #print(a)
        m+=1
print(m)


Measured memory_bytes: 5704
#include<stdio.h>
int a,b,c;
int main() {

	scanf("%d%d%d",&a,&b,&c);
	if(a+b==c||a+c==b||b+c==a) printf("Yes\n");
	else printf("No\n");
	
	/*
	for(i=1;i<=19;i++) {
		scanf("%c",&c);
		if(c!=',') printf("%c",c);
		else printf(" ");
	}
	printf("\n");
	*/

	
}

Measured memory_bytes: 128
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	int x;
	while(cin >> x, x){
		int ans = 0;
		for(int i = 1; i < x/2 + 1; ++i){
			int sum = 0;
			for(int j = i; sum < x; ++j){
				sum += j;
				if(sum == x){
					++ans;
					break;
				}
			}	
		}

		cout << ans << endl;
	}
}

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int N;
    cin >> N;
    bool isexist = false;
    int ans = 0;
    for(int i=1;i<=N;i++){
        if(floor(i*1.08)==N){
            isexist = true;
            ans = i;
            break;
        }
    }

    if(isexist){
        cout << ans << endl;
    }else{
        cout << ":(" << endl;
    }

}



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

int main() {
  int A,B;
  cin>>A>>B;
  if(A==B){
    cout<<2*A<<endl;
  }
  if(A-1>B){
    cout<<2*A-1<<endl;
  }
  if(A-1==B){
    cout<<A+B<<endl;
  }
  if(B-1>A){
    cout<<2*B-1<<endl;
  }
  if(B-1==A){
    cout<<A+B<<endl;
  }
}
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> in(N);
  vector<pair<int, int>> vp(N-1);
  vector<vector<int>> graph(N);
  REP(i, N-1){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
    in[u]++; in[v]++;
    vp[i] = {u, v};
  }

  int K = 0;
  REP(i, N) chmax(K, in[i]);
  cout << K << "\n";

  map<pair<int, int>, int> ans;
  vector<int> cs(N, 0);

  vector<bool> used(N, false);
  used[0] = true;

  queue<int> q;
  q.push(0);
  
  while(!q.empty()){
    int v = q.front(); q.pop();
    int cur = 1;
    for(auto u : graph[v]){
      if(used[u]) continue;
      if(cur == cs[v]) cur++;
      cs[u] = ans[{u, v}] = ans[{v, u}] = cur++;
      used[u] = true;
      q.push(u);
    }
  }

  for(auto p : vp) cout << ans[p] << "\n";

  return 0;
}

Measured memory_bytes: 22272
n=int(input())
i=1
while i<=n :
    x=i
    if x%3==0  :
        print("",i,end="")
    else:
        if x%10==3 :
            print("",i,end="")
        else :
            while 0<x :
                f=0
                x=x//10
                if x>=1 :
                    if x % 10 ==3 :
                        print("",i,end="")
                        f=1
                if f==1:
                    break
    i=i+1
print("")

Measured memory_bytes: 8108
#include<cstdio>
#include<cmath>
#include<climits>
#include<cfloat>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<utility>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;
typedef long long ll;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll MAX = 3e5+1;
const ll INF = 1e20;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string N;
    in(N);
    int n = N.size();
    char c = N[n-1];
    if (c == '3') out("bon");
    else if (c == '0' || c == '1' || c == '6' || c == '8') out("pon");
    else out("hon");


    return 0;
}


Measured memory_bytes: 3652
package main

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

var sc = bufio.NewScanner(os.Stdin)

// var rdr = bufio.NewReaderSize(os.Stdin, 100000)
var rdr *bufio.Reader

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	in := nextInt
	A, B, Q := in(), in(), in()

	s := make([]int64, A+1)
	for i := 0; i < int(A); i++ {
		s[i] = nextI64()
	}
	s[A] = -2 << 40
	t := make([]int64, B+1)
	for i := 0; i < int(B); i++ {
		t[i] = nextI64()
	}
	t[B] = -2 << 40

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	for i := 0; i < Q; i++ {
		x := nextI64()
		var dist int64 = 2 << 50

		for i := 0; i < 2; i++ {
			var first []int64
			var second []int64
			if i == 0 {
				first = s
				second = t
			} else {
				first = t
				second = s
			}
			for j := 0; j < 2; j++ {
				pos1 := binarySearch(first, x) + j
				ax := first[pos1]
				for k := 0; k < 2; k++ {
					pos2 := binarySearch(second, x) + k
					bx := second[pos2]

					a := absi64(x - ax)
					b := absi64(ax - bx)
					dist = mini64(dist, a+b)
				}
			}
		}

		fmt.Fprintln(out, dist)
	}
}

func binarySearch(table []int64, key int64) int {
	left := 0
	right := len(table) - 1

	return loop(table, key, left, right)
}

func loop(table []int64, key int64, left int, right int) int {
	if right-left < 2 {
		return left
	}

	mid := (left + right) / 2
	if table[mid] <= key {
		return loop(table, key, mid, right)
	}
	return loop(table, key, left, mid)
}

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

func readLine() string {
	buf := make([]byte, 0, 100000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextI64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func maxi64(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func updateMax(a *int, b int) {
	if *a < b {
		*a = b
	}
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func mini64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func updateMin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func absi64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func anser(b bool, y string, n string) string {
	if b {
		return y
	}
	return n
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll h,w;cin>>h>>w;
  vector<string>a(h);
  rep(i,0,h)cin>>a[i];
  rep(i,0,h)rep(j,0,w){
    if(a[i][j]=='#'){
      res++;
      if(i!=h-1||j!=w-1){
        bool sw=false;
        if(i<h-1&&a[i+1][j]=='#')sw=true;
        if(j<w-1&&a[i][j+1]=='#')sw=true;
        if(!sw)judge=false;
      }
    }
  }
  ans(res==h+w-1&&judge,"Possible","Impossible");
  return 0;
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int main(int argc, const char * argv[]) {
    // source code
    int a ,b;
    cin >> a >> b;
    cout << std::max(0, a - b * 2);
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

signed main(){
	cout<<fixed<<setprecision(7);
	int n = 0, m = 0;
	int a = 0, b = 0, c = 0, d = 0, e = 0;
	bool f = false, flag = true;
	string S;
	cin>>S;
	if(S[0] == '9' || S[1] == '9') f = true;
	//cin>>n;
	
	//for(int i = 0; i < n; i++){
	//}
	
	cout<<yn(f)<<endl;
	// cout<<YN(f)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);

  int i;
  for(i=0; i<n; ++i){

    double x1,y1,x2,y2,x3,y3,x4,y4;
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);

    if((x2-x1)*(y4-y3)==(x4-x3)*(y2-y1)){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    if(n%k==0) cout << 0 << endl;
    else cout << 1 << endl;
}


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

using namespace std;

vector<vector<long long>> dp(105, vector<long long>(100005, 0));
vector <int> c(101), g(101);

int main()
{
    int n, w;

    cin >> n >> w;

    for (int i = 1; i <= n; i++)
    {
        cin >> g[i] >> c[i];
    }
    g[0] = 0;
    c[0] = 0;

    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= w; j++)
        {
            long long localBest = dp[i - 1][j];

            if (j >= g[i])
            {
                localBest = dp[i - 1][j - g[i]] + c[i];
                localBest = max(localBest, dp[i - 1][j]);
            }
            dp[i][j] = localBest;
        }

        cout << dp[n][w];
    return 0;
}


Measured memory_bytes: 83456
#include <bits/stdc++.h>
using namespace std;
struct N {
	int v, l, x, y, r;
};
bool operator<(const N &a, const N &b) {
	return a.v > b.v;
}
priority_queue<N> q;
int n, a[200020];
pair<int, int> f[400020][18];
pair<int, int> Q(int x, int y) {
	int l = 31 - __builtin_clz(y - x);
	return min(f[x][l], f[y - (1 << l)][l]);
}
void push(int l, int r) {
	if (l == r) {
		return;
	}
	pair<int, int> x = Q(l, r);
	pair<int, int> y = Q(x.second + 1, r + 1);
	q.push({x.first, l, x.second, y.second, r});
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		f[i][1] = make_pair(a[i], i);
	}
	for (int j = 1; j < 17; j++) {
		for (int i = 0; i < n; i++) {
			f[i][j + 1] = min(f[i][j], f[i + (1 << j)][j]);
		}
	}
	push(0, n);
	while (q.size()) {
		N u = q.top();
		q.pop();
		printf("%d %d ", a[u.x], a[u.y]);
		push(u.l, u.x);
		push(u.x + 1, u.y);
		push(u.y + 1, u.r);
	}
	return 0;
}


Measured memory_bytes: 31860
import java.util.Scanner;
public class Main{
	static int ans;
	static int[][] e;
	static int n;
	static int[] c;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int m = sc.nextInt();
		e = new int[n+1][n+1];
		c = new int[n+1];
		for(int i = 0; i < m; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			e[a][b]=1;
			e[b][a]=1;
		}
		c[1]=1;
		dfs(1,n);
		System.out.println(ans);
	}
	public static void dfs(int number,int q){
		if(q==1){
			ans++;
			return;
		}
		for(int i = 1; i <= n; i++){
			if(e[number][i]==1 && c[i]!=1){
				c[i]=1;
				dfs(i,q-1);
				c[i]=0;
			}
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int inversion(const vector<int>& A) // A: permutation of [1 .. A.size()]
{
    vector<int> B(A.size()+1);
    auto sum = [&](int i) {
        Int sum = 0;
        while (i > 0) sum += B[i], i -= i & -i;
        return sum;
    };
    auto add = [&](int i, int x) {
        while (i < B.size()) B[i] += x, i += i & -i;
    };
    Int ans = 0;
    for (int i = A.size()-1; i >= 0; i--) {
        ans += sum(A[i]-1);
        add(A[i], 1);
    }
    return ans;
}
Int swap_distance(const vector<int>& A, const vector<int>& B)
{
    map<int, queue<int>> M;
    for (int i = 0; i < A.size(); i++) {
        M[A[i]].push(i+1);
    }
    vector<int> C(B.size());
    for (int i = 0; i < B.size(); i++) {
        C[i] = M[B[i]].front();
        M[B[i]].pop();
    }
    return inversion(C);
}
Int solve(const string& S)
{
    int cnt[26] = {};
    for (auto c : S) cnt[c-'a']++;
    int mid = -1;
    for (int i = 0; i < 26; i++) {
        int &n = cnt[i];
        if (n % 2 && mid == -1) mid = i, n /= 2;
        else if (n % 2) return -1;
        else n /= 2;
    }
    vector<int> A(S.size()), B, X, Y;
    for (int i = 0; i < S.size(); i++) {
        int& c = cnt[S[i] - 'a'];
        if (c) A[i] = 0, c--, X.push_back(S[i]);
        else if (S[i] - 'a' == mid) A[i] = 1, mid = -1;
        else A[i] = 2, Y.push_back(S[i]);
    }
    B = A;
    sort(begin(B), end(B));
    reverse(begin(Y), end(Y));
    return swap_distance(A, B) + swap_distance(X, Y);
}
int main()
{
    string S;
    cin >> S;
    cout << solve(S) << endl;
}

Measured memory_bytes: 5244
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, l, r;
llong a[55];

bool is_u(llong x) {
    for (int i = 0; i < n; i++) {
        if (x % a[i] == 0) {
            return i % 2 == 0; 
        }
    }

    return n % 2 == 0;
}

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

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

        llong cnt = 0;
        for (int i = l; i <= r; i++) {
            if (is_u(i)) cnt++;
        }

        cout << cnt << '\n';

        cin >> n >> l >> r;
    }
    

    return 0;
}



Measured memory_bytes: 3100
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextInt();
        double g = sc.nextInt();

        System.out.println((int)(2*g - r));
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 23764
import math

N = int(input())
 
def divisor(N):
    '''
    create divisor_list < sqrt(N) from natural number
    '''
    divisor_list = []
    
    for num in range(1, math.ceil(math.sqrt(N)) + 1):
        if N % num == 0:
            divisor_list.append(num)
    
    return divisor_list
    
def F(A, B):
    return max(len(str(A)), len(str(B)))
  
def minimumF(N):
    factoring_list = divisor(N)
    
    candidate_list = []
    
    for A in factoring_list:
        B = N // A
        candidate_list.append(F(A, B))
        
    return min(candidate_list)
  
print(minimumF(N))

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

int main() {
  int n;
  cin>>n;
  vector<int> v(n);
  for (size_t i = 0; i < n; i++) {
    cin>>v[i];
  }
  sort(v.begin(), v.end());
  for (size_t i = 1; i < n-1; i++) {
    v[0]+=v[i];
  }
  if (v[0]>v[n-1]) {
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
N = gets.to_i
H = gets.split.map(&:to_i)

cnt = 0
ans = 0
hight = H.first

H[1..-1].each do |h|
  if hight >= h
    cnt += 1
  else
    cnt = 0
  end

  ans = cnt if ans < cnt
  hight = h
end

puts ans


Measured memory_bytes: 8580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

ll cnt[26] = {};

int main() {
	IOS();
	ll h, w;
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < w; ++j) { cnt[s[j] - 'a']++; }
	}
	ll a1 = 0, a2 = 0, a4 = 0;
	for (int i = 0; i < 26; ++i) {
		if (cnt[i] % 4 == 0)
			a4++;
		else if (cnt[i] % 2 == 0)
			a2++;
		else
			a1++;
	}
	if (h % 2 == 1 && w % 2 == 1) {
		dump(a1 == 1 && a2 <= h / 2 + w / 2 ? "Yes" : "No");
	} else if (h % 2 == 1) {
		dump(a1 == 0 && a2 <= w / 2 ? "Yes" : "No");
	} else if (w % 2 == 1) {
		dump(a1 == 0 && a2 <= h / 2 ? "Yes" : "No");
	} else
		dump(a1 + a2 == 0 ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

class position
{
public:
    int y, x;
    bool left;
    position(int y0, int x0, bool left0){
        y = y0;
        x = x0;
        left = left0;
    }
};

void solve(int w, int h, vector<vector<int> > block)
{
    int dy[9] = {-2,-1,-1,0,0,0,1,1,2};
    int dx[9] = {1,1,2,1,2,3,1,2,1};

    multimap<int, position> m;
    for(int i=3; i<w+3; ++i){
        if(block[h+1][i] == -1){
            m.insert(make_pair(0, position(h+1, i, true)));
            m.insert(make_pair(0, position(h+1, i, false)));
        }
    }

    vector<vector<vector<bool> > > check(h+4, vector<vector<bool> >(w+6, vector<bool>(2, false)));
    while(!m.empty()){
        multimap<int, position>::iterator it = m.begin();
        int t = it->first;
        int y = it->second.y;
        int x = it->second.x;
        bool left = it->second.left;
        m.erase(it);

        if(block[y][x] == 0){
            cout << t << endl;
            return;
        }
        if(check[y][x][left?1:0])
            continue;
        check[y][x][left?1:0] = true;

        if(left){
            for(int i=0; i<9; ++i){
                if(block[y+dy[i]][x+dx[i]] >= 0 && !check[y+dy[i]][x+dx[i]][0])
                    m.insert(make_pair(t+block[y+dy[i]][x+dx[i]], position(y+dy[i], x+dx[i], 0)));
            }
        }else{
            for(int i=0; i<9; ++i){
                if(block[y+dy[i]][x-dx[i]] >= 0 && !check[y+dy[i]][x-dx[i]][1])
                    m.insert(make_pair(t+block[y+dy[i]][x-dx[i]], position(y+dy[i], x-dx[i], 1)));
            }
        }

    }

    cout << -1 << endl;
}

int main()
{
	for(;;){
		int w, h;
		cin >> w >> h;
		if(w == 0 && h == 0)
			break;

		vector<vector<int> > block(h+4, vector<int>(w+6, -2));
		for(int i=2; i<h+2; ++i){
			for(int j=3; j<w+3; ++j){
				char tmp;
				cin >> tmp;
				if(tmp == 'S')
                    block[i][j] = -1;
                else if(tmp == 'T')
                    block[i][j] = 0;
                else if(tmp != 'X')
					block[i][j] = tmp - '0';
			}
		}

		solve(w, h, block);
	}

	return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int main() {
  string n;
  cin >> n;
  if(n == "SUN") {
    cout << 7;
  } else if(n == "MON") {
    cout << 6;
  } else if(n == "TUE") {
    cout << 5;
  } else if(n == "WED") {
    cout << 4;
  } else if(n == "THU") {
    cout << 3;
  } else if(n == "FRI") {
    cout << 2;
  } else if(n == "SAT") {
    cout << 1;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <thread>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

ll k;
vector<ll> ans;

void bfs() {
  queue<ll> que;
  rep1(i, 9) que.push(i);
  while (ans.size() < k) {
    ll p = que.front(); que.pop();
    for (int i=-1; i<=1; i++) {
      if (p%10+i < 0 || p%10+i > 9) continue;
      ll newNum = p * 10 + p%10 + i;
      ans.push_back(newNum);
      que.push(newNum);
    }
  }
}

int main() {
  cin >> k;
  rep1(i, 9) ans.push_back(i);
  if (k <= 9) {
      cout << ans[k-1] << endl;
      return 0;
  }
  bfs();
  //rep(i, k) {
  //  cout << ans[i] << endl;
  //}
  cout << ans[k-1] << endl;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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 pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int solve(int n){
	n=1000-n;
	int ans=0;

	int change[6]={500,100,50,10,5,1};

	for(int i=0;i<6;++i) while(n>=change[i]) n-=change[i],ans++;
		
	return ans;
}

int main(void){
	int n;
	while(cin >>n,n){
		cout << solve(n) << endl;
	}
	return 0;
}

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

int main()
{
	int N,ans;
	cin >> N;
	if (N % 2 == 0) ans = N;
	else ans = 2*N;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "test"
using namespace std;
const ll N = 1e5 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

string s;
ll n,i,dp[N][2],k;
ll f(ll pos,ll prv){
    if (pos < 1) return 0;
    if (dp[pos][prv] != -1) return dp[pos][prv];
    ll ans;
    if (prv == 1) ans = min(1 + f(pos - 1,1),f(pos - 1,0));
    else{
        if (s[pos] == s[pos + 1]) ans = 1 + f(pos - 1,1);
        else ans = min(1 + f(pos - 1,1),f(pos - 1,0));
    }
    return dp[pos][prv] = ans;
}
ll Count1(){
    ll res = 0;
    for (i = 1;i <= n;i++){
        if (s[i] == s[1]) res++;
        else break;
    }
    return res;
}
ll Count2(){
    ll res = 0;
    for (i = n;i >= 1;i--){
        if (s[i] == s[n]) res++;
        else break;
    }
    return res;
}
bool chkcond(){
    for (i = 2;i <= n;i++) if (s[i] != s[i - 1]) return false;
    return true;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>s>>k; n = s.size(); s = " " + s;
    memset(dp,-1,sizeof(dp));
    if (chkcond()){
        cout<<(n*k)/2; return 0;
    }
    ll p = min(f(n - 1,1) + 1,f(n - 1,0)),ans;
    //cout<<f(n - 1,1) + 1<<"\n";
    if (f(n - 1,1) + 1 == p) ans = p*k;
    else{
        if (s[1] == s[n]){
            ll x = Count1(),y = Count2();
            ans = p*k - (x/2 + y/2 - (x + y)/2)*(k - 1);
        }
        else ans = p*k;
    }
    ll q = k/2;
    cout<<ans;
}


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

// m桁の短歌数の総数
ll total(int m){
    return 81*(bit(m-1)-1);
}

string rec(ll n,int m,int f){
    rep(x,10){
        ll block = (f != x ? bit(m-1) : (bit(m-1)-1)*9);
        if(n >= block){
            n -= block;
        }else{
            string str = to_string(x);
            if(f == x){
                str += rec(n,m-1,f);
            }else{
                if(f < x) swap(f,x);
                for(int k = m-2; k >= 0; k--){
                    str += to_string(n&bit(k) ? f : x);
                }
            }
            return str;
        }
    }
    assert(false);
}

int main(){
    ll n;
    while(cin>>n, n){
        n--;
        int m = 2;
        while(n >= total(m)){
            n -= total(m);
            m++;
        }
        ll block = total(m)/9;
        int f = 1 + n/block;
        n %= block;
        cout<<to_string(f)<<rec(n,m-1,f)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int h1,m1,h2,m2;
	cin>>h1>>m1>>h2>>m2;
	int k;
	cin>>k;
	m1+=60*h1;
	m2+=60*h2;
	cout<<max(0,m2-m1-k)<<"\n";
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e+9 + 7;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  int x;
  bool flag = false;
  cin >> x;
  while(true){
    flag = IsPrime(x);
    if(flag) break;
    else ++x;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string s[n],x;
    int t[n];
    for(int i=0;i<n;i++){
        cin>>s[i]>>t[i];
        if(i)t[i]+=t[i-1];
    }
    cin>>x;
    for(int i=0;i<n;i++){
        if(s[i]==x){
            cout << t[n-1]-t[i] <<endl;
            return 0;
        }
    }

    return 0;
}


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

int main(void){
    char s[200001];
    char t[200001];
    gets(s);
    gets(t);

    int rs[26];
    int rt[26];
    for(int i = 0; i < 26; i++){rs[i] = -1; rt[i] = -1;}

    int n = strlen(s);
    int a, b;
    for(int i = 0; i < n; i++){
        a = s[i] - 'a';
        b = t[i] - 'a';
        
        if(rs[a] != -1 || rt[b] != -1)
        {
            if(rs[a] != b || rt[b] != a)
            {
                printf("No\n");
                return 0;
            }
        }
        
        rs[a] = b;
        rt[b] = a;
    }

    printf("Yes\n");
    return 0;
}


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

int main(){
  int n,i,j,c1,c2,c3,c4,ans=0;
  cin >> n;
  n=min(n,777777753);
  if(n>100000000){
   for(i=333333357; i<=n; i+=2){
    c1=0;c2=0;c3=0;c4=0;
    j=i;
    while(j>0){
      if(j%10==3){c1++;}
      else if(j%10==5){c2++;}
      else if(j%10==7){c3++;}
      else {c4++;break;}
      j/=10;
    }
    if(c1>0 && c2>0 && c3>0 && c4==0){
      ans++;
    }
   }
   cout << ans+8334; return 0;
  }else{
    for(i=357; i<=n; i+=2){
    c1=0;c2=0;c3=0;c4=0;
    j=i;
    while(j>0){
      if(j%10==3){c1++;}
      else if(j%10==5){c2++;}
      else if(j%10==7){c3++;}
      else {c4++;break;}
      j/=10;
    }
    if(c1>0 && c2>0 && c3>0 && c4==0){
      ans++;
    }
   }
   cout << ans; return 0;
  }
}


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

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

using namespace std;

int main(){
	int m,k; scanf("%d%d",&m,&k);

	if(m==1){
		puts(k==0?"0 0 1 1":"-1");
		return 0;
	}

	if(k>=(1<<m)){
		puts("-1");
	}
	else{
		for(int i=0;i<=(1<<m)-1;i++) if(i!=k) printf("%d ",i);
		printf("%d ",k);
		for(int i=(1<<m)-1;i>=0;i--) if(i!=k) printf("%d ",i);
		printf("%d\n",k);
	}

	return 0;
}

// experimentation
/*
	int m; scanf("%d",&m);

	vector<int> p(2*m);
	rep(i,m) p[2*i]=p[2*i+1]=i+1;
	bool f[100]={};
	do{
		int a=-1;
		rep(i,m){
			vector<int> I;
			rep(j,2*m) if(p[j]==i+1) I.emplace_back(j);
			int x=0;
			for(int j=I[0];j<=I[1];j++) x^=p[j];
			if(a==-1) a=x;
			else if(a!=x){ a=-1; break; }
		}
		if(a!=-1 && f[a]) continue;
		if(a!=-1){
			f[a]=true;
			printf("%d is found!\n  ",a);
			for(int i:p) printf("%d ",i); puts("");
		}
	}while(next_permutation(p.begin(),p.end()));
*/


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Main main = new Main();
		Robot A[] = new Robot[N];
		for (int i=0;i<N;i++) {
			Robot r = main.new Robot();
			r.x = sc.nextInt();
			r.l = sc.nextInt();
			A[i] = r;
		}
		Arrays.sort(A);
		int count =0;
		int now =Integer.MIN_VALUE;
		for (int i=0;i<N;i++) {
			if (now<=A[i].x-A[i].l) {
				count ++;
				now = A[i].x+A[i].l;
			}
		}
		System.out.println(count);
	}

	public class Robot implements Comparable<Robot> {
		int x;
		int l;
		@Override
		public int compareTo(Robot o) {
			return this.x+this.l-o.x-o.l;
		}
	}
}

Measured memory_bytes: 62368
def rename(st):
    letnow=st[0]
    letnum=0
    retst=""
    for letter in range(len(st)):
        if letnow==st[letter]:
            letnum=letnum+1
        else:
            retst=retst+str(letnum)+letnow
            letnow=st[letter]
            letnum=1
    retst=retst+str(letnum)+letnow
    return retst

while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        st=raw_input() #type str
        for i in range(n):
            st=rename(st)
        print st
        

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

using namespace std;

typedef long long int64;

vector< int > prime;

void init()
{
  bool isprime[2201] = {};
  for(int64 i = 2; i < 2201; i++) {
    if(!isprime[i]) {
      prime.push_back(i);
      for(int64 j = i + i; j < 2201; j += i) isprime[j] = true;
    }
  }
}

int64 getNorm(int64 val)
{
  for(int k : prime) {
    int64 div = 1LL * k * k * k;
    while(val % div == 0) val /= div;
  }
  return (val);
}

int main()
{
  init();

  int N, ret = 0;
  map< int64, int > Norm;

  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    int64 S;
    scanf("%lld", &S);
    int64 norm = getNorm(S);
    if(norm == 1) ret = true;
    else ++Norm[norm];
  }

  for(auto& it : Norm) {
    int64 norm = getNorm(it.first * it.first);
    ret += max(it.second, Norm[norm]);
    it.second = 0;
    Norm[norm] = 0;
  }

  printf("%d\n", ret);
}


Measured memory_bytes: 18688
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#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>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(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-10;
const double PI  = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int N;
	int M = sqrt(32768);
	while(cin >> N, N) {
		int ans = 0;
		REP(i, M) {
			FOR(j, i, M) {
				FOR(k, j, M) {
					FOR(l, k, M) {
						if(i*i+j*j+k*k+l*l > N) {
							break;
						}
						if(i*i+j*j+k*k+l*l == N) {
							ans++;
						}
					}
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
public class Main {
    public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      int size = Integer.parseInt(scan.nextLine());
      String heights = scan.nextLine();
      String[] hstr = heights.split(" ");
      int[]hs = new int[hstr.length];
      for (int i = 0 ; i<hstr.length ; i++) {
        hs[i] = Integer.parseInt(hstr[i]);
      }
      
      scan.close();
      
      int[] res = new int[size];
      res[0] = 0;
      res[1] = Math.abs(hs[1]-hs[0]);
        
      for (int i = 2 ; i < size ; i++) {
        res[i] = Math.min(Math.abs(hs[i] - hs[i-1]) + res[i-1],Math.abs(hs[i] - hs[i-2]) + res[i-2]);
      }
      
      System.out.print(res[size-1]);
    }
}

Measured memory_bytes: 36624
#include <stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	if(a > b+1)
		printf("%d\n", 2*a - 1);
	else
		if(b > a+1)
			printf("%d\n", b*2 - 1);
		else
			printf("%d\n", a+b);

	return 0;
}

Measured memory_bytes: 128
# coding:utf-8

A_pairs = []
bs = []

for _ in range(3):
    As = list(map(int, input().split(' ')))
    A_pairs.append(As)
N = int(input())
for _ in range(N):
    b = int(input())
    bs.append(b)

for idx in range(3):
    A_pairs.append([A_pairs[0][idx], A_pairs[1][idx], A_pairs[2][idx]])

A_pairs.append([A_pairs[0][0], A_pairs[1][1], A_pairs[2][2]])
A_pairs.append([A_pairs[2][0], A_pairs[1][1], A_pairs[0][2]])

for As in A_pairs:
    if As[0] in bs and As[1] in bs and As[2] in bs:
        print('Yes')
        exit(0)
print('No')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	int cnt = 0;
	for (; ;)
	{
		bool odd = false;
		for (int i = 0; i < n; i++)
		{
			if (a.at(i) % 2 != 0)
			{
				odd = true;
				break;
			}

			a.at(i) /= 2;
		}

		if (odd)
		{
			break;
		}
		else
		{
			cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define all(v) v.begin(),v.end()
#define boost ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
const int mod = 1e9+7;
/*
#define bigint __int128
__int128 abss(__int128 x){if(x>0)return x;
    return -x;
    }
*/
void solve() {
int x;cin>>x;cout<<(!(x))<<endl;
    
}
int main()
{boost;
int t;t = 1;//cin>>t;
while(t--){solve();}
}


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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;

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

int main() {
    string S,aim="AKIHABARA";
    cin>>S;
    bool f=true;
    int insert=0;
    for(int i=0;i<aim.length();i++){
        if(S[i-insert]==aim[i]) continue;
        if(aim[i]=='A'){
            insert++;
            continue;
        }
        f=false;
        break;
    }
    if(S.length()>aim.length()-insert) f=false;
    cout<<(f?"YES":"NO")<<endl;
    return 0;
}



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

using namespace std;

int main(int argc, char *argv[]) {
    int A, B;
    cin >> A >> B;

    int ans = 0;
    if (A <= 5) {
        ans = 0;
    } else if (A >= 6 && A <= 12) {
        ans = B / 2;
    } else {
        ans = B;
    }

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


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	ll s; cin >> s;
	map<ll,ll> m;
	ll ans = 1;
	while (m.find(s)==end(m)) {
		m[s] = 1;
		if (s % 2 == 0) s /= 2;
		else s = 3 * s + 1;
		ans += 1;
	}
	cout << ans << endl;
}

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

int main(){
        int card[4][13];
        for(int i=0;i<4;i++){
                for(int j=0;j<13;j++){
                        card[i][j]=0;
                }
        }
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++){
                char s;
                int x;
                scanf("%s %d",&s,&x);
                if(s=='S'){
                        card[0][x-1]=1;
                }else if(s=='H'){
                        card[1][x-1]=1;
                }else if(s=='C'){
                        card[2][x-1]=1;
                }else if(s=='D'){
                        card[3][x-1]=1;
                }
        }
        for(int j=0;j<4;j++){
                for(int k=0;k<13;k++){
                        if(card[j][k]==0){
                                if(j==0)
                                    printf("S %d\n",k+1);
                                if(j==1)
                                    printf("H %d\n",k+1);
                                if(j==2)
                                    printf("C %d\n",k+1);
                                if(j==3)
                                    printf("D %d\n",k+1);
                        }

                }
        }

        return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<string>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int a;
    a = N%10;
  	if(a == 3){
      cout << "bon" << endl;
    }else if((a == 0)||(a == 1)||(a == 6)||(a == 8)){
      cout << "pon" << endl;
    }else{
      cout << "hon" << endl;
    }
  	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  vll aa(n+1);
  rep(i,n){
    aa[a[i]]++;
  }
  if(n%2==0){
    for(int i=0;i<n+1;i++){
      if(i%2==0){
        if(aa[i]!=0){
          COUT(0);
          return 0;
        }
      }
      else{
        
        if(aa[i]!=2){
          COUT(0);
          return 0;
        }
      }
    }
    ll ans=1;
    rep(i,n/2){
      ans*=2;
      ans%=MOD;
    }
    COUT(ans);
  }
  else{
    if(aa[0]!=1){
          COUT(0);
          return 0;
        }
    for(int i=0;i<n+1;i++){
      
      if(i%2==1){
        if(aa[i]!=0){
          COUT(0);
          return 0;
        }
      }
      else{
        if(i==0) continue;
        if(aa[i]!=2){
          COUT(0);
          return 0;
        }
      }
    }
    ll ans=1;
    rep(i,n/2){
      ans*=2;
      ans%=MOD;
    }
    COUT(ans);
  }
}


Measured memory_bytes: 1792
n, a, b = map(int, input().split())
ans = 0
tmp = 0
frag10000 = 0
frag1000 = 0
frag100 = 0
frag10 = 0
frag1 = 0
for i in range(n + 1):
    tmp = i
    frag10000 = int(tmp / 10000)
    tmp %= 10000
    frag1000 = int(tmp / 1000)
    tmp %= 1000
    frag100 = int(tmp / 100)
    tmp %= 100
    frag10 = int(tmp / 10)
    tmp %= 10
    frag1 = int(tmp)
    tmp = frag10000 + frag1000 + frag100 + frag10 + frag1
    if a <= tmp <= b:
        ans += i
print(ans)


Measured memory_bytes: 9124