akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll a[2],b[2];
		ll mi=-1*1e18;
		cin>>a[0]>>a[1]>>b[0]>>b[1];
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				mi=max(mi,a[i]*b[j]);
			}
		}
		cout<<mi;
	}
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	static boolean dp[] = new boolean[20*2000];	
	static int [] A;
	public static void main(String[] args) {
		int n = sc.nextInt();
		A = new int[n];
		for(int i=0;i<n;i++) A[i] = sc.nextInt();
		Arrays.fill(dp, false);
		int q = sc.nextInt();
		rec(0,0,n);
		for(int i=0;i<q;i++){
			int m = sc.nextInt();
			if(dp[m]==true){
				cout("yes");
			}else{
				cout("no");
			}
		}
	}
	
	
	public static void rec(int d,int now,int b){
		dp[now] = true;
		if(d==b) return;
		rec(d+1,now,b);
		rec(d+1,now+A[d],b);
	}
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
}

Measured memory_bytes: 26596
#include <iostream>
using namespace std;
int main(){
  int n,x,y,z,ans=0;
  cin>>n;
  cin>>x>>y;
  for(int i=2;i<n;i++){
    cin>>z;
    if( ((x<y)&&(y<z)) || ((x>y)&&(y>z)) )ans++;
    x=y;y=z;
  }
  cout << ans << endl;
  return 0;
} 

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

int searchkk(vector<int> &b)
{
    int val = -1;
    for (int i = b.size() - 1; i >= 0; i--)
    {
        if (b[i] == i + 1)
        {
            val = b[i];
            b.erase(b.begin() + i);
            return val;
        }
    }
    return val;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    int N = 0;
    cin >> N;

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

    vector<int> a(0);
    for (int i = 0; i < N; i++)
    {
        int val = searchkk(b);
        if (val == -1)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            a.push_back(val);
        }
    }

    for (int i = a.size() - 1; i >= 0; i--)
    {
        cout << a[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
 
int main(){
    int card[4][13] = { 0 };
    int n;  //枚数
    char k; //絵柄
    int t;  //数字
    int p;  //絵柄操作用変数
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> k >> t;
        if (k == 'S') p = 0;
        if (k == 'H') p = 1;
        if (k == 'C') p = 2;
        if (k == 'D') p = 3;
        card[p][t-1] = 1;
    }
     
    for (int i = 0; i < 4; i++){
        if (i == 0) k = 'S';
        if (i == 1) k = 'H';
        if (i == 2) k = 'C';
        if (i == 3) k = 'D';
        for (int j = 0; j < 13; j++){
            if (card[i][j] == 0){
                cout << k <<" "<< j + 1<< endl;
            }
        }
    }
     
    return 0;
}

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

int main(){
	double v;

	while ( cin >> v ){
		double y = ( v * v ) / ( 2.0 * 9.8 );
		int f = y / 5 + ( y / 5 - static_cast< int >( y / 5 ) == 0.0 ? 0 : 1 ) + 1;

		cout << f << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  string ans;
  if(a + b > c + d) ans = "Left";
  else if(a + b < c + d) ans = "Right";
  else ans = "Balanced";
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

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

    int N, K;
    cin >> N >> K;
    int R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;

    int ans = 0;
    Vi status(N);
    for (int i = 0; i < N; i++) {
        int points;
        if (T[i] == 'r')
            points = P;
        else if (T[i] == 's')
            points = R;
        else
            points = S;

        if (i >= K) {
            if (T[i - K] == T[i] && status[i - K] == 0) {
                points = 0;
                status[i] = 1;
            }
        }
        ans += points;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 848
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

constexpr static int MOD = 1e9 + 7;

int64_t mpow(int64_t a, int64_t e) {
    int64_t r = 1, p = a;
    while (e) {
        if (e & 1)
            r = (r * p) % MOD;
        p = (p * p) % MOD;
        e >>= 1;
    }
    return r;
}

int64_t cnt[1 << 16];

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

    vector <int> divs;
    for (int i = 1; i * i <= n; i++)
        if (n % i == 0) {
            divs.push_back(i);
            if (i * i != n)
                divs.push_back(n / i);
        }
    sort(divs.begin(), divs.end());

    int64_t total = 0;
    for (int i = 0; i < divs.size(); i++) {
        cnt[i] = mpow(k, (divs[i] + 1) / 2);
        for (int j = 0; j < i; j++)
            if (divs[i] % divs[j] == 0)
                cnt[i] = (cnt[i] - cnt[j] + MOD) % MOD;
        if (divs[i] % 2)
            total += cnt[i] * divs[i];
        else
            total += cnt[i] * (divs[i] / 2);
        total %= MOD;
    }
    cout << total << endl;
}


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

using namespace std;

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  int **A = new int*[n];
  int **B = new int*[m];
  long **C = new long*[n];
  for (int i = 0; i < n; i++)
  {
    A[i] = new int[m];
    C[i] = new long[l];
    for (int j = 0; j < m; j++)
    {
      cin >> A[i][j];
    }
    for (int k = 0; k < l; k++)
    {
      C[i][k] = 0; 
    }
  }


  for (int i = 0; i < m; i++)
  {
    B[i] = new int[l];
    for (int j = 0; j < l; j++)
    {
      cin >> B[i][j];
    }
  }


  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      for(int k = 0; k < m; k++)
        C[i][j] += A[i][k] * B[k][j];
      if(j == l - 1)
        cout << C[i][j];
      else
        cout << C[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3264
#include <stdio.h>

int main(){
  char a,b;
  scanf("%c",&b);
  if(b == 'A') a = 'T';
  if(b == 'T') a = 'A';
  if(b == 'G') a = 'C';
  if(b == 'C') a = 'G';
  printf("%c\n",a);
  return 0;
}

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

int main() {
    int a,b;
    cin>>a>>b;
    int cnt=0;
    for(int i=a;i<=b;i++){
        int rev;
        rev=i%10*10000+(i/10)%10*1000+(i/100)%10*100+(i/1000)%10*10+i/10000;
        if(rev==i){
            cnt+=1;
        }

    }
    cout<<cnt<<endl;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;


#define pb push_back
#define ff first
#define ss second
#define INF int(3e9)
#define BIG_INF ll(9e18)
#define SIZE 200001
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define len(v) int((v).size())
#define BACK(v) ll((v).back())
#define sqr(x) (x) * (x)
#define cube(x) (x) * (x) * (x)
#define filein freopen("input.txt", "r", stdin)
#define fileout freopen("output.txt", "w", stdout);


ll binpow(ll a, ll b, ll MOD = BIG_INF)
{
    ll res = 1;

    while(b)
    {
        if(b & 1)
            res *= a;
        a *= a;
        b >>= 1;
        a %= MOD;
        res %= MOD;
    }

    return res % MOD;
}

const ll mod = 1e9 + 7;

int T = 1;
int n, m;
int a[SIZE];

string s;

void solve()
{
    cin >> s;

    ll sum = 0;
    for(char c: s)
    {
        sum += (c - '0');
    }


    if(sum % 9 == 0)
    {
        cout << "Yes\n";
    }else cout << "No\n";

    return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//    filein;fileout;

//    cin >> T;

    while(T--)
    {
        solve();
    }
    return 0;
}



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

#define int long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i, l, r) for(int i=(int)(l);i<=(int)(r);i++)
#define repi(i, l, r) for(int i=(int)(l);i>=(int)(r);i--)
const int inf = 1e18;

using namespace std;

const int MAX = 1000001;

// array to store prime factors
int factor[MAX] = { 0 };

// function to generate all prime factors
// of numbers from 1 to 10^6
void generatePrimeFactors()
{
    factor[1] = 1;

    // Initializes all the positions with their value.
    for (int i = 2; i < MAX; i++)
        factor[i] = i;

    // Initializes all multiples of 2 with 2
    for (int i = 4; i < MAX; i += 2)
        factor[i] = 2;

    // A modified version of Sieve of Eratosthenes to
    // store the smallest prime factor that divides
    // every number.
    for (int i = 3; i * i < MAX; i++) {
        // check if it has no prime factor.
        if (factor[i] == i) {
            // Initializes of j starting from i*i
            for (int j = i * i; j < MAX; j += i) {
                // if it has no prime factor before, then
                // stores the smallest prime divisor
                if (factor[j] == j)
                    factor[j] = i;
            }
        }
    }
}

// function to calculate number of factors
int calculateNoOFactors(int n)
{
    if (n == 1)
        return 1;

    int ans = 1;

    // stores the smallest prime number
    // that divides n
    int dup = factor[n];

    // stores the count of number of times
    // a prime number divides n.
    int c = 1;

    // reduces to the next number after prime
    // factorization of n
    int j = n / factor[n];

    // false when prime factorization is done
    while (j != 1) {
        // if the same prime number is dividing n,
        // then we increase the count
        if (factor[j] == dup)
            c += 1;

            /* if its a new prime factor that is factorizing n,
               then we again set c=1 and change dup to the new
               prime factor, and apply the formula explained
               above. */
        else {
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        }

        // prime factorizes a number
        j = j / factor[j];
    }

    // for the last prime factor
    ans = ans * (c + 1);

    return ans;
}

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

    int cnt = 0;
    generatePrimeFactors();
    rep(i,1,n-1){
        int x = calculateNoOFactors(n-i);
        cnt+=x;
    }

    cout << cnt << endl;

}


int32_t main() {
    fastIO
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}



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

int main(){
    int N;
    cin >> N;
    bool c = false;
    for (int a = 0; a <= N / 4; ++a){
        for (int b = 0; b <= N / 7; ++b){
            if (N == a * 4 + b * 7) c = true;
        }
    }
    if(c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

long long gcd(long long a, long long b);
int main() {
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    long long Cn = B / C - A / C;
    if(A % C == 0)
        Cn++;
    long long Dn = B / D - A / D;
    if(A % D == 0)
        Dn++;
    long long CD = C * D / gcd(C, D);
    long long CDn = B / CD - A / CD;
    if(A % CD == 0)
        CDn++;
    long long count = (B - A + 1) - Cn - Dn + CDn;
    cout << count << endl;
}
long long gcd(long long a, long long b) {
    if(a > b)
        swap(a, b);
    if(a == 0)
        return b;
    long long r = a % b;
    while(r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

Measured memory_bytes: 256
import Data.List

main = interact $ unlines . map (show . step_aerobics) . unfoldr read' . lines
 where read' (x:xs) = if x=="0" then Nothing else Just (words (head xs), tail xs)

step_aerobics = fst . foldl' (flip step) (0,[])
 where
  step "ru" (n,("lu":acc)) = (n+1,acc)
  step "lu" (n,("ru":acc)) = (n+1,acc)
  step "rd" (n,("ld":acc)) = (n+1,acc)
  step "ld" (n,("rd":acc)) = (n+1,acc)
  step "ld" (n,("lu":acc)) = (n,acc)
  step "rd" (n,("ru":acc)) = (n,acc)
  step "lu" (n,("ld":acc)) = (n,acc)
  step "ru" (n,("rd":acc)) = (n,acc)
  step s (n,acc) = (n,s:acc)

Measured memory_bytes: 4672
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int b,a,c;
    cin >> a >> b >> c;
    
    if(a > b) swap(a , b);
    if(b > c) swap(b , c);
    if(a > b) swap(a , b);
    
    cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define maxn 605
#define ll long long
#define db double
#define vi vector<int>
#define pb push_back
#define mod 1000000007
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
// head
ll dp[maxn][305][305];
int a[maxn];
int tot = 0;
int n;
int fl[maxn];
int main() {
	ll ans = 1;
	memset(fl, -1, sizeof(fl));
	cin >> n;
	int l = 2 * n;
	for (int i = 1; i <= l; i++)
		cin >> a[i];
	int cnt = 0;
	for (int i = 1; i < l; i += 2) {
		if (a[i] != -1 && a[i + 1] != -1)
			fl[a[i]] = fl[a[i + 1]] = 0;
		else if (a[i] == -1 && a[i + 1] == -1)
			cnt++, 
			ans = ans * cnt % mod;
		else {
			if (a[i] < a[i + 1]) swap(a[i], a[i + 1]);
			fl[a[i]] = 1;
		}
	}
/*	cout << ans << endl;
	for (int i = 1; i <= l; i++)
		if (fl[i] == 1)cout << i << ' ';
	cout << endl;
*/	for (int i = l + 1; i >= 1; i--)
		for (int j = 0; j <= n; j++)
			for (int k = 0; k <= n; k++) {
				if (i == l + 1) {
					if (j == 0 && k == 0) dp[i][j][k] = 1;
					else dp[i][j][k] = 0;
				}
				else {
					if (!fl[i]) dp[i][j][k] = dp[i + 1][j][k];
					else if (fl[i] == 1) {
						dp[i][j][k] = dp[i + 1][j + 1][k];
						if (k) 
							dp[i][j][k] += k * dp[i + 1][j][k - 1];
						dp[i][j][k] %= mod;
					}
					else {
						dp[i][j][k] = dp[i + 1][j + 1][k] + dp[i + 1][j][k + 1];
						if (j) 
							dp[i][j][k] += dp[i + 1][j - 1][k];
						
						dp[i][j][k] %= mod;
					}
				}
			//	if (dp[i][j][k] && j <= i) cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << endl;
			}
	ans = ans * dp[1][0][0] % mod;
	cout << ans << endl;
	return 0;
}
/*
3
5 -1 -1 -1 -1 -1
*/

Measured memory_bytes: 437760
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mod 1000000007
using namespace std;
int n;
int a[200005];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	ll sum=a[1],ans=0;
	for(int i=2;i<=n;i++){
		ans=(ans+sum*(ll)a[i]%mod)%mod;
		sum=(sum+(ll)a[i])%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

vector<ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
	ll n;cin >> n;
	vector<ll> a = divisor(n),b = divisor(n-1);
	ll ans = 0;
	for(auto i:a)
	{
		ll N = n;
		if(i==1)continue;
		while(N>=i)
		{
			if(N%i==0)N/=i;
			else N%=i;
		}
		if(N==1)ans++;
	}

	//cout<<ans<<endl;
	for(auto i:b)
	{
		if(i==1)continue;
		ll N = n;
		while(N>=i)
		{
			if(N%i==0)N/=i;
			else N%=i;
		}
		if(N==1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#最大公約数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

#最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

#最大公約数（複数）
def gcds(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        n = len(l) // 2
        L = l[:n]
        R = l[n:]
        return gcd(gcds(L), gcds(R))

#最小公倍数(複数)
def lcms(l):
	if len(l) == 1:
		return l[0]
	elif len(l) == 2:
		return lcm(l[0], l[1])
	else:
		n = len(l) // 2
		L = l[:n]
		R = l[n:]
		return lcm(lcms(L), lcms(R))
      
n = int(input())
a = [int(i) for i in input().split()] 

def f(m, l):
  ans = 0
  for i in l:
    ans += m%i
  return ans

print(f(lcms(a)-1, a))
  


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    vector<string> s(n);
    REP(i,n){
        cin>>s[i];
        sort(ALL(s[i]));
    }

    sort(ALL(s));
    s.push_back(" ");

    ll v=0,t=0;
    REP(i,n){
        t++;
        if(s[i]!=s[i+1]){
            v+=t*(t-1)/2;
            t=0;
        }
    }

    cout<<v<<endl;

	return 0; 
}


Measured memory_bytes: 8064
/*
	ex3_2
	ruuu0048
*/
#include <stdio.h>
#include <math.h>
#define PI 3.14159265359 //πを定義
 
double radian_distance_cos(int hour,int minute); //時針と分針の間の角度の余弦を返す関数
 
int main(void){
 
 
    int hour_length,minute_length; //時針と分針の変数を宣言
    int hour,minute; //時間Hと分Mの変数を宣言
    double distance; //求める距離の変数を宣言
 
    scanf("%d %d %d %d",&hour_length,&minute_length,&hour,&minute); //それぞれ入力
    
    distance = sqrt(pow(hour_length,2) + pow(minute_length,2) - 2 * hour_length * minute_length * radian_distance_cos(hour,minute)); //余弦定理を使う
 
    printf("%.16f\n",distance); //答えを出力
 
    return 0; 
}
 
double radian_distance_cos(int hour,int minute){
 
    double hour_radian,minute_radian; //時針と分針の0時からの角度の変数を宣言
 
    hour_radian = ((double)hour + (double)minute / 60) / 12 * (2 * PI); //ラジアンに変換
 
    minute_radian = (double)minute / 60 * (2 * PI); //ラジアンに変換
 
    return cos(hour_radian - minute_radian); //差の余弦を返す
 
};


Measured memory_bytes: 2596
n,ma,mb = map(int, input().split())
abc = [list(map(int, input().split())) for i in range(n)]
INF = 10 ** 18
dp = [[[INF] * 500 for i in range(500)] for x in range(n+1)]
dp[0][0][0] = 0
for k,(a,b,c) in enumerate(abc):
  for i in range(400):
    for j in range(400):
      dp[k+1][i][j] = min(dp[k+1][i][j],dp[k][i][j])
      dp[k+1][i+a][j+b] = min(dp[k][i+a][j+b],dp[k][i][j]+c)
ans = INF
for i in range(1,500):
  Ma,Mb = i * ma, i * mb
  if Ma > 400 or Mb > 400:
    break
  ans = min(ans,dp[n][Ma][Mb])
if ans == INF:
  print(-1)
else:
  print(ans)
  

Measured memory_bytes: 122204
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	string S;
	cin >> S;

	vector<long long> count(3, 0);

	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'R')
		{
			count[0]++;
		}
		else if (S[i] == 'G')
		{
			count[1]++;
		}
		else if (S[i] == 'B')
		{
			count[2]++;
		}
	}

	long long no = 0;
	for (int i = 0; i < N; i++)
	{
		for (int d = 1; d < N; d++)
		{
			if (i + d * 2 < N)
			{
				if (S[i] != S[i + d] && S[i + d] != S[i + d * 2] && S[i] != S[i + d * 2]) no++;
			}
		}
	}

	cout << count[0] * count[1] * count[2] - no;

	return 0;
}


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

using namespace std;
 
#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
 
#define deb(x) {x}
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------
 

int n,arr[200005];
vi fac[200005];


int test[200005];

void fun(int r)
{
	if (r==0)return ;
	rep(i,r/2+1,r+1)
	{
		test[i]=arr[i];
		if (arr[i])
		{
			for (auto x:fac[i])arr[x]^=1;
		}
	}
	fun(r/2);
}

void solve()
{
	rep(i,1,200005)
	{
		for(int j=i;j<200005;j+=i)fac[j].pb(i);
		
	}
	cin>>n;
	rep(i,1,n+1)
	{
		cin>>arr[i];
	}
	memset(test,0,sizeof test);
	
	fun(n);
	vi op;
	rep(i,1,n+1)if (test[i])op.pb(i);
	cout<<op.size()<<"\n";for (auto x:op)cout<<x<<" ";
	
	
	
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
 
    #ifdef local
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    clock_t qwertyuiop = clock();
    #endif
 
 
    int t=1;
   // cin>>t;
    
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}

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

int main(){
	int k;
	for(int i = 1 ; i < 10 ; i++){
		for(int j = 1 ; j < 10 ; j++){
			k = i * j;
			cout << i << "x" << j << "=" << k << endl;
		}
	}
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    
    ll val1 = t1 * (a1 - b1);
    ll val2 = t2 * (a2 - b2);

    if (!((val1 > 0) ^ (val2 > 0))) {
        cout << 0 << "\n";
        return 0;
    }

    ll valval = val1 + val2;
    //cerr << val1 << " " << val2 << " " << valval << "\n";
    if (valval == 0) {
        cout << "infinity\n";
        return 0;
    }

    if (!((val1 > 0) ^ (valval > 0))) {
        cout << 0 << "\n";
        return 0;        
    }

    ll ans = (abs(val1)) / abs(valval) * 2 + 1;
    ans -= (abs(val1) % abs(valval) == 0);
    cout << ans << "\n";
    return 0;
}

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

int n, a[200004];
long long sum[200004];

long long rangeSum(int s, int e){
	return sum[e]-sum[s-1];
}
long long calGap(int lo, int mid, int hi){
	return	(max(max(rangeSum(1,lo),rangeSum(lo+1,mid)),max(rangeSum(mid+1,hi),rangeSum(hi+1,n)))-
	min(min(rangeSum(1,lo),rangeSum(lo+1,mid)),min(rangeSum(mid+1,hi),rangeSum(hi+1,n))));
}

int main() {
	cin>>n;
	sum[0] = 0;
	for(int i = 1 ; i <= n ; i++){
		cin>>a[i];
		sum[i] = sum[i-1]+a[i];
	}
	int mid, lo, hi;
	long long ans = 1e16;
	for(mid = 2;mid<=n-2;mid++){
		long long l = sum[mid]/2;
		lo = lower_bound(sum+1,sum+mid+1,l)-sum;
		long long h = (sum[n]+sum[mid])/2;
		hi = lower_bound(sum+mid+2,sum+n+1,h)-sum;
		ans = min(ans,calGap(lo,mid,hi));
		if(lo>1 && hi>mid+1)
			ans = min(ans,calGap(lo-1,mid,hi-1));
		if(lo>1)
			ans = min(ans,calGap(lo-1,mid,hi));
		if(hi>mid+1)
			ans = min(ans,calGap(lo,mid,hi-1));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
def main():

    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse = True)
    v = A[0]
    if N % 2 == 0:
        # print(v)
        v += sum(A[1:1+(N-2)//2]) * 2
        # print(v)
    else:
        v += sum(A[1:1+(N-2)//2]) * 2 + A[1+(N-2)//2]
    return v

if __name__ == '__main__':
    print(main())


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

#define rep(i,m) for(int i=0;i<m;i++)
typedef long long ll;
using namespace std;




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

	}

	int main() {
		int n; cin >> n;
		vector<int> a(n);
		rep(i, n)cin >> a[i];

		int gc = a[0];
		for (int i = 1; i < n; i++) {
			gc = gcd(gc, a[i]);
		}
		cout << gc << endl;
	}


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


int main(int argc, char *argv[]){

  int i;
  char w[101];
  int r;
  int a[26];
  int l = 0;

  scanf("%s", w);

  r = strlen(w);

  for(i=0; i<=25; i++){
    a[i] = 0;
  }

  for(i=0; i<=r-1; i++){
    if(w[i] == 'a'){
      a[0]++;
    }else if(w[i] == 'b'){
      a[1]++;
    }else if(w[i] == 'c'){
      a[2]++;
    }else if(w[i] == 'd'){
      a[3]++;
    }else if(w[i] == 'e'){
      a[4]++;
    }else if(w[i] == 'f'){
      a[5]++;
    }else if(w[i] == 'g'){
      a[6]++;
    }else if(w[i] == 'h'){
      a[7]++;
    }else if(w[i] == 'i'){
      a[8]++;
    }else if(w[i] == 'j'){
      a[9]++;
    }else if(w[i] == 'k'){
      a[10]++;
    }else if(w[i] == 'l'){
      a[11]++;
    }else if(w[i] == 'm'){
      a[12]++;
    }else if(w[i] == 'n'){
      a[13]++;
    }else if(w[i] == 'o'){
      a[14]++;
    }else if(w[i] == 'p'){
      a[15]++;
    }else if(w[i] == 'q'){
      a[16]++;
    }else if(w[i] == 'r'){
      a[17]++;
    }else if(w[i] == 's'){
      a[18]++;
    }else if(w[i] == 't'){
      a[19]++;
    }else if(w[i] == 'u'){
      a[20]++;
    }else if(w[i] == 'v'){
      a[21]++;
    }else if(w[i] == 'w'){
      a[22]++;
    }else if(w[i] == 'x'){
      a[23]++;
    }else if(w[i] == 'y'){
      a[24]++;
    }else if(w[i] == 'z'){
      a[25]++;
    }
  }

  for(i=0; i<=25; i++){
    if(a[i] % 2 == 1){
      l++;
    }
  }

  if(l == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define WHITE '#'
#define BLACK '.'
#define NEWLINE '\n'

void
draw(int, int);

int
main(void)
{
    int h, w;
    while (scanf("%d %d", &h, &w) && h && w)
        draw(h, w);
    return 0;
}

void
draw(int h, int w)
{
    int i, j;
    char ch = WHITE;
    char s = WHITE;
    for (i = 0; i < h; i++) {
        ch = s;
        for (j = 0; j < w; j++) {
            putchar(ch);
            ch = ch ^ WHITE ^ BLACK;
        }
        putchar(NEWLINE);
        s = s ^ WHITE ^ BLACK;
    }
    putchar(NEWLINE);
}


Measured memory_bytes: 2044
n,m = map(int,input().split())
e = [list(map(int,input().split())) for i in range(n)]
f = [list(map(int,input().split())) for i in range(m)]
d_cnt = [[] for i in range(n)]
for j in range(n):
  for i in range(m):
    d_cnt[j].append(abs(e[j][0]-f[i][0])+abs(e[j][1]-f[i][1]))
for i in range(n):
  print(d_cnt[i].index(min(d_cnt[i]))+1)


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, ans = 0;
  string s, t;
  cin >> n >> s >> t;
  ans = s.length();

  for (int i = 0; i < s.length(); ++i) {
    bool flg = true;
    for (int j = 0; j < t.length() && i + j < s.length(); ++j) {
      if (s[i + j] == t[j])
        continue;
      else {
        flg = false;
        break;
      }
    }
    if (flg) break;
    ans++;
  }

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


Measured memory_bytes: 256
x,k,d=map(int,input().split())

x=x if x>0 else -x

if k*d<x:
    print(x-k*d)
else:
    rma=(k*d-x+2*d-1)//(2*d)
    rmi=(k*d-x)//(2*d)

    print(min(abs(x-(k-2*rmi)*d),abs(x-(k-2*rma)*d)))

Measured memory_bytes: 61792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

struct UnionFind {
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) :
            par(n), sizes(n, 1) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int find(int x) {
        if (x == par[x]) return par[x];
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        sizes[x] += sizes[y];
        par[y] = x;
    }

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

    int getSizes(int x) {
        return sizes[x];
    }

};

int main() {

    int N, M;
    cin >> N >> M;

    vector<int> p(N);
    for (int i = 0; i < N; i++)cin >> p[i], p[i]--;

    UnionFind UF(N);

    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        UF.unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (UF.same(i, p[i])) ans++;
    }


    cout << ans << endl;

}














































Measured memory_bytes: 1408
import sys

input = sys.stdin.readline

foods = [int(input()) for _ in range(5)]

exist_remainder_list = [(food, food % 10) for food in foods if food % 10 != 0]

if len(exist_remainder_list) != 0:
    last = min(exist_remainder_list, key=lambda value: value[1])
    foods.remove(last[0])

    ans = 0

    for index, food in enumerate(foods):
        ans += food
        while True:
            if ans % 10 == 0:
                break
            else:
                ans += 1

    print(ans + last[0])
else:
    ans = 0

    for index, food in enumerate(foods):
        ans += food
        while True:
            if ans % 10 == 0:
                break
            else:
                ans += 1

    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;
  cin >> n >> k;
  if(k %2 == 1){
    ll a = n/k;
    cout << a*a*a << endl;
  }else{
    ll a = n/k;
    ll b = (n + (k/2))/k;
    cout << a*a*a + b*b*b <<endl;
  }
  return 0;
}


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

int sum_keta(int n){
  int sum = 0;
  while (n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int n, a, b;
  int ans = 0;
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) {
    int sum = sum_keta(i);
    if (a <= sum && sum <= b) {
      ans += i;
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
	int a,b,c,d,e,f,g,h,i;
	cin >> a >> b >> e;
	g=a+b-e;
	f=a+g-e;
	c=a+e-f;
	d=b+c-g;
	h=a+e-g;
	i=b+e-g;
	
	cout << a << " " << b << " " << c << endl;
	cout << d << " " << e << " " << f << endl;
	cout << g << " " << h << " " << i << endl;
	return 0;
}

Measured memory_bytes: 384
N = int(input())
A_str = input().split()
A = [int(a) for a in A_str]
B_str = input().split()
B = [int(b) for b in B_str]

battle = 0
for i in range(len(B)):
    if A[N - i] + A[N - i - 1] >= B[N - i - 1]:
        battle += B[N - i - 1]
        if A[N - i] <= B[N - i - 1]:
            A[N - i - 1] -= B[N - i - 1] - A[N - i]
    else:
        battle += A[N - i] + A[N - i - 1]
        A[N - i - 1] = 0

print(battle)


Measured memory_bytes: 26580
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,L;
vector<ll> W,V;
void input(){
    fast_io();
    cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        ll w,v; cin >> w >> v;
        W.push_back(w);
        V.push_back(v);
    }
}

int solve(){
    // vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
    vector<map<ll,ll>> dp(N+1);
    dp[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        for(auto p:dp[i]){
            int w = p.first;
            if(w+W[i]<=L) dp[i+1][w+W[i]] = max(dp[i][w+W[i]],dp[i][w]+V[i]);
            if(w<=L) dp[i+1][w] = max(dp[i+1][w],dp[i][w]);
        }
        dp[i].clear();
    }
    ll ans = 0;
    for(auto p:dp[N]){
        ans = max(ans,p.second);
    }
    cout << ans << endl;
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
	ll n,m;
	cin >> n >> m;
	ll i,j,t,k;
	ll a[4]={0};
	bool ch[4]={false};
	while(m--){
		cin >> t >> k;
		if(ch[t]==true&&a[t]!=k){
			cout << -1 << endl;
			return 0;
		}
		else{
			a[t]=k;
			ch[t]=true;
		}
	}
	if(ch[1]==true&&a[1]==0&&n!=1){
		cout << -1 << endl;
		return 0;
	}
	if(n==1&&ch[1]==true&&a[1]==0){
		cout << 0 << endl;
		return 0;
	}
	if(n==1){
		cout << a[1] << endl;
	}
	else if(n==2){
		if(ch[1]==false){
			cout << 1 << a[2] << endl;
		}
		else{
			cout << a[1] << a[2] << endl;
		}
	}
	else if(n==3){
		if(ch[1]==true){
			cout << a[1] << a[2] << a[3] << endl;
		}
		else{
			cout << 1 << a[2] << a[3] << endl;
		}
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define int long long
using namespace std;
const int P=998244353;
const int M=1000000;

int powmod(int x, int p) {
	if (p == 0) return 1;
	int y = powmod(x, p/2);
	y = y * y % P;
	if (p&1) {
		y = y * x % P;
	}
	return y;
}

int inv(int x) {
	return powmod(x, P - 2);
}

int n;
vector<int> cnt(M + 1);
vector<int> D(M + 1);
vector<int> S(M + 1);

signed main() {
	
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		cnt[x]++;
	}
	
	for (int i = 1; i <= M; ++i) {
		int sum = 0;
		int sum2 = 0;
		for (int j = i; j <= M; j += i) {
			sum = (sum + cnt[j] * j) % P;
			sum2 = (sum2 + cnt[j] * j % P * j) % P;
		}
		D[i] = ((sum * sum % P - sum2 + P) % P) * ((P + 1) / 2) % P;
	}
	
	for (int i = M; i >= 1; --i) {
		S[i] = D[i];
		for (int j = 2 * i; j <= M; j += i) {
			S[i] -= S[j];
			//S[i] = (S[i] - S[j] + P) % P;
		}
		S[i] = (S[i] % P + P) % P;
	}
	
	int res = 0;
	
	for (int i = 1; i <= M; ++i) {
		res = (res + inv(i) * S[i]) % P;
	}
	
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 25728
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;
    int left = 0, right = S.size() - 1, ans = 0;
    while (left < right) {
        if (S[left] == 'x') {
            if (S[right] != 'x') {
                ans++; left++;
            } else {
                left++; right--;
            }
        } else if (S[right] == 'x') {
            if (S[left] != 'x') {
                ans++; right--;
            } else {
                left++; right--;
            }
        } else {
            if (S[left] != S[right]) {
                cout << -1 << endl;
                return 0;
            }
            left++; right--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

int cal(int x) {
  string s = to_string(x);
  int ret = 0;
  for (auto &i : s) {
    ret += i - '0';
  }
  return ret;
}

void MAIN() {
  int n; cin >> n;
  int ans = 2e9;
  for (int i = 1; i <= n / 2; i++) {
    int j = n - i;
    ans = min(ans, cal(i) + cal(j));
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3776
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int s[100], c[100];

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

	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> s[i] >> c[i];
		s[i]--;
	}

	for (int i = 0; i < 1000; i++) {
		string S = to_string(i);
		if (S.size() != N)continue;
		int ok = 1;
		for (int j = 0; j < M; j++) {
			if (S[s[j]] - '0' != c[j])ok = 0;
		}
		if (ok) { puts(i); return 0; }
	}
	puts(-1);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ans = [0]*10050
for i in range(1,105):
    for j in range(1,105):
        for k in range(1,105):
            v = i*i + j*j + k*k + i*j + i*k + j*k
            if v<10050:
                ans[v]+=1
for i in range(1,n+1):
    print(ans[i])


Measured memory_bytes: 73756
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;

long long N, M;

string S, T;

bool check(long long n, long long div){
    bool ok = false;
    div = abs(div);
    n = abs(n);
    for(int i=0; i<32; ++i){
        if(n%div==0) ok = true;
        div*=2;
    }
    return ok;
}
void solve(){
    vector<int> v;
    if(N==0){
        cout << 0 << endl;
        return;
    }
    if(N%2!=0) {
        v.push_back(1);
        N--;
    }else{ 
        v.push_back(0);
    }
    long long base=-2;
    while(abs(N)>0){
        if(check(N+base, base*(-2))){ //trueなら
            v.push_back(1);
            N-=base;
        }else{
            v.push_back(0);
        }
        base*=(-2);
    }
    reverse(v.begin(), v.end());
    for(auto e: v) cout << e;
    cout << endl;
}
int main() {
    cin >> N;
    solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	while (b <= a) {
		b *= 2;
		ans++;
	}
	while (c <= b) {
		c *= 2;
		ans++;
	}
	if (ans <= k) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_N 50

using namespace std;

int n, p;
int d[MAX_N];

void solve() {
	for (int i = 0; i < n; i++)
	{
		d[i] = 0;
	}
	int w = p;
	while(1){
		for (int i = 0; i < n; i++)
		{
			if(w > 0){
				d[i]++;
				w--;
				if(w == 0 && d[i] == p){
					cout << i << endl;
					return;
				}
			}else{
				w = d[i];
				d[i] = 0;
			}
		}
	}
}

int main(){
	while(1){
		cin >> n >> p;
		if(n == 0 && p == 0) break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

using ll = long long;

int main()
{
    int N;
    scanf("%d\n", &N);
    vector<ll> A;
    vector<ll> B;
    ll result = 0;
    for (int i = 0; i < N; ++i){
        ll Ai, Bi;
        scanf("%lld %lld\n", &Ai, &Bi);
        A.emplace_back(Ai);
        B.emplace_back(Bi);
    }

    for (int i = N - 1; i >= 0; --i){
        auto& Bi = B[i];
        const ll rest = (A[i] + result) % Bi;
        result += (Bi - rest) % Bi;
    }
    printf("%lld\n", result);
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = max<int> ({
    A * 10 + B + C,
    A + B * 10 + C,
    A + B + C * 10,
  });
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int ret;
string s;

void solve(int i, int ac, int sum){
  if(i == s.size()){
    ret = max(ret, sum);
    return;
  }

  if(ac == 1){
    solve(i+1, 1, sum + 9);
  }else{
    int x = s[i]-'0';
    if(x>0){
      solve(i+1, 0, sum + x);
      solve(i+1, 1, sum + x-1);
    }else{
      solve(i+1, 0, sum + x);
    }
  }
}


int main(){
  cin >> s;

  ret = 0;
  solve(0, 0, 0);

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;

  string l_str, r_str;
  int max_count = 0;
  for(int i=1;i<(int)S.size();i++){
    // cut string
    l_str = S.substr(0, i);
    r_str = S.substr(i, S.size()-i);
    // cout << l_str << endl << r_str << endl;

    set<string> l_str_set;
    for(int j=0;j<l_str.size();j++){
      l_str_set.insert(l_str.substr(j,1));
    }
    set<string> r_str_set;
    for(int j=0;j<r_str.size();j++){
      r_str_set.insert(r_str.substr(j,1));
    }

    set<string>::iterator l_itr;
    set<string>::iterator r_itr;
    int count=0;
    for(l_itr=l_str_set.begin();l_itr!=l_str_set.end();++l_itr){
      for(r_itr=r_str_set.begin();r_itr!=r_str_set.end();++r_itr){
        // cout << *l_itr << " " << *r_itr << endl;
        if(*l_itr == *r_itr){
          count++;
        }
      }
    }
    if (count > max_count){
      max_count = count;
    }
  }


  cout << max_count << endl;
  // cout << N << endl << S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

#define ll long long
constexpr ll inf = 1e9+7;

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

    ll N, M;
    cin>>N>>M;
    vector<ll> v(N+1, 0);
    map<ll, set<ll>> edge;
    for (ll m = 0; m < M; m++) {
        ll a, b;
        cin>>a>>b;
        edge[a].insert(b);
        edge[b].insert(a);
    }

    ll v_num[3] = {0};
    function<bool(ll)> dfs = [&](ll at) {
        if (edge.count(at) > 0) {
            for (ll next : edge[at]) {
                if (v[next] == 0) {
                    v[next] = v[at] * -1;
                    v_num[v[next]+1]++;
                    if (dfs(next)) return true;
                } else if (v[next] == v[at]) return true;
            }
        }
        return false;
    };
    v_num[2]++;
    v[1] = 1;
    if (dfs(1) == false) cout<<(v_num[0]*v_num[2]-M)<<endl;
    else cout<<(N*(N-1)/2-M)<<endl;
    return 0;
}

Measured memory_bytes: 20096
#include <iostream>
#include <iomanip>
#include <cassert>

#include <utility>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
using namespace std;

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

constexpr int INF = numeric_limits<int>::max();

void Main()
{
	int N;
	cin >> N;
	int min_a = 1000;
	int max_a = -1;

	rep(i, N)
	{
		int a;
		cin >> a;
		min_a = min(min_a, a);
		max_a = max(max_a, a);
	}

	cout << max_a - min_a << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);

int cnt;

ll ans;

string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'B') {
            ++cnt;
        } else {
            ans += cnt;
        }
    }
    cout << ans;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
ll n,m;
ll ans;
priority_queue<int>q;
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        ans+=x;
        q.push(x);
    }
    for(int i=0;i<m;i++)
    {
        int x=q.top();
        q.pop();
        ans=ans-x+x/2;
        q.push(x/2);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3876