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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}

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

  int K=360/gcd(X,360);

  cout<<K<<endl;
}


Measured memory_bytes: 3580
//
// Created by kuribohkute on 20/04/2019.
//
#include <iostream>
#include <vector>
using namespace std;
#define mp make_pair
#define X first
#define Y second
int n;
vector <int> a, b;
int main () {
    cin >> n;
    a.resize(n + 1);
    b.resize(n);
    for (int i = 0; i < n + 1; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    long long res = 0;
    int pre = 0;
    for (int i = 0; i < n + 1; i++) {
        int mons = a[i];
        res += min(mons, pre);
        mons -= min(mons, pre);
        int cur = 0;
        if (i < n) {
            cur = b[i];
        }
        res += min(cur, mons);
        cur -= min(mons, cur);
        pre = cur;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
std::map<T, int> prime_factorize(T x) {
  std::map<T, int> primes;
  for (T factor = 2; factor * factor <= x; factor++) {
    if (x % factor == 0) {
      T count = 0;
      while (x % factor == 0) {
          count++;
          x /= factor;
      }
      primes[factor] = count;
    }
  }
  if (x != 1) primes[x] = 1;
  return primes;
}

int main() {
  int N; cin >> N;
  int cnt = 0;
  for (int i = 1; i <= N; i += 2) {
    auto m = prime_factorize(i);
    int j = 1;
    for (auto& p : m) {
      j *= p.second + 1;
    }
    if (j == 8) ++cnt;
  }
  cout << cnt << endl;
}


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


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

bool isPrime(int x){
  int i;
  if(x < 2)return 0;
  else if(x == 2) return 1;
  if(x%2 == 0) return 0;
  for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
  return 1;
}

int binary(vector<int> a,lint key) {
  lint left = 0;
  lint right = a.size();
  while(left<right){
    lint mid = (left+right)/2;
    if(a[mid] == key){
      return 1;
    }
    else if(key<a[mid]){
      right = mid;
    }
    else{
      left = mid+1;
    }
  }
  return 0;
}


int main(){
  int m,a,n;
  cin>>m>>a>>n;
  if(m>=n){
    cout<<"0"<<endl;
  }
  else if(m+a<n){
    cout<<"NA"<<endl;
  }
  else {
    cout<<n-m<<endl;
  }
}



Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>
#include<bitset>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const double EPS = 0.000000000001;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


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

	vector<int> rate(9);
	for (int i = 0; i < 9; i++) {
		rate[i] = 0;
	}

	for (int i = 0; i < N; i++) {
		rate[min(A[i] / 400 , 8)] ++;
	}

	int origin = 0;
	for (int i = 0; i < 8; i++) {
		origin += (rate[i] != 0);
	}

	int plus = rate[8];
	
	
	cout << max(origin, 1) << " " <<(origin + plus);



}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int q;
  cin >> q;
  int rev = 1;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1)
      rev = -rev;
    else {
      int f;
      cin >> f;
      string c;
      cin >> c;
      if ((f == 1 && rev == 1) || (f == 2 && rev == -1)) {
        s.insert(0, c);
      } else {
        s.append(c);
      }
    }
  }
  if (rev == -1) reverse(s.begin(), s.end());
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 3884
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define Run(i,l,r) for(int i=l;i<=r;i++)
#define Don(i,l,r) for(int i=l;i>=r;i--)
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
#define mk make_pair
#define fir first
#define sec second
#define il inline
#define rg register
#define pb push_back
using namespace std;
const int N=410;
int n,m,sz1[N*N],sz2[N*N],tot,fa[N*N],id[N][N];
char s[N][N]; 
int dx[4]={0,-1};
int dy[4]={-1,0};
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
	scanf("%d%d",&n,&m);
	Run(i,1,n){
		scanf("%s",s[i]+1);
		Run(j,1,m){
			id[i][j]=++tot;
			fa[tot]=tot;
			sz1[tot] = s[i][j]=='#';
			sz2[tot] = !sz1[tot];
			int x = i, y = j;
			Run(k,0,1){
				int nx=dx[k]+x,ny=dy[k]+y;
				if(nx>=1&&ny>=1){
					if(s[nx][ny]!=s[x][y]){
						int fx = find(id[nx][ny]),fy = find(tot);
						if(fx!=fy){
							sz1[fx] += sz1[fy];
							sz2[fx] += sz2[fy];
							fa[fy] = fx;
						}
					}
				}
			}
		} 
	} 
	ll ans = 0;
	for(int i=1;i<=tot;++i)if(fa[i]==i){
		ans += (ll)sz1[i] * sz2[i]; 
	}
	cout << ans << endl; 
	return 0;
}//by tkys_Austin;


Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
  char a,b;
  cin>>a>>b;
  if(a=='D'){
    if(b=='D')cout<<'H'<<endl;
    else cout<<'D'<<endl;
  }
  else{
    if(b=='D')cout<<'D'<<endl;
    else cout<<'H'<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
const int N = 1e4 + 7;
char s[N];
int a[N];
int b[N];
int c[N];
int main()
{
    memset(a, 0, sizeof a);
    memset(b, 0, sizeof b);
    memset(c, 0, sizeof c);
    int n;
    ll ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> s[i];
    for(int i = n; i >= 1; i--)
    {
        a[i] += a[i + 1] + (s[i] == 'R');
        b[i] += b[i + 1] + (s[i] == 'G');
        c[i] += c[i + 1] + (s[i] == 'B');
    }
//    for(int i = 1; i <= n; i++)
//        cout << a[i] << " ";
//    cout << endl;
//    for(int i = 1; i <= n; i++)
//        cout << b[i] << " ";
//    cout << endl;
//    for(int i = 1; i <= n; i++)
//        cout << c[i] << " ";
//    cout << endl;
    for(int i = 1; i <= n; i++)
    {
        if(s[i] == 'R')
        {
            for(int j = i + 1; j <= n; j++)
            {
                if(s[j] == 'G')
                {
                    ans += c[j + 1];
                    if(s[j * 2 - i] == 'B' && j * 2 - i <= n)
                        ans --;
                }
                else if(s[j] == 'B')
                {
                    ans += b[j + 1];
                    if(s[j * 2 - i] == 'G' && j * 2 - i <= n)
                        ans --;
                }
            }
        }
        if(s[i] == 'G')
        {
            for(int j = i + 1; j <= n; j++)
            {
                if(s[j] == 'R')
                {
                    ans += c[j + 1];
                    if(s[j * 2 - i] == 'B' && j * 2 - i <= n)
                        ans --;
                }
                else if(s[j] == 'B')
                {
                    ans += a[j + 1];
                    if(s[j * 2 - i] == 'R' && j * 2 - i <= n)
                        ans --;
                }
            }
        }
        if(s[i] == 'B')
        {
            for(int j = i + 1; j <= n; j++)
            {
                if(s[j] == 'R')
                {
                    ans += b[j + 1];
                    if(s[j * 2 - i] == 'G' && j * 2 - i <= n)
                        ans --;
                }
                else if(s[j] == 'G')
                {
                    ans += a[j + 1];
                    if(s[j * 2 - i] == 'R' && j * 2 - i <= n)
                        ans --;
                }
            }
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3752
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}

module Main where

import qualified Data.ByteString.Char8 as B8
import Data.Maybe (fromJust)
import Data.Char (toUpper,isDigit)
import Data.List
import qualified Data.Map as M
import Data.Array.IO
import Data.IORef
import Data.Ix (range)
import Control.Monad
import Control.Applicative
import Text.Printf
import Data.Time.Calendar
import Debug.Trace

readDigits = map read <$> words <$> getLine :: IO [Int]
readDigits' = map read <$> lines <$> getContents :: IO [Int]

solve :: [Int] -> [Int]
solve ns = [minimum ns, maximum ns, sum ns]

--
main :: IO ()
main = do
    _ <- readLn :: IO Int
    putStrLn . unwords . map show . solve =<< readDigits

Measured memory_bytes: 11308
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scan(&S)

	result := ""
	for i := 0; i < 26 && len(result) == 0; i++ {
		if !strings.Contains(S, string(97+i)) {
			result = string(97 + i)
		}
	}

	if len(result) == 0 {
		fmt.Println("None")
	} else {
		fmt.Println(result)
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	int a[6], head, down;
	rep(i,6) {
		cin >> a[i];
	}
	int s[6][6];
	s[0][0] = -1, s[0][1] = 2, s[0][2] = 4, s[0][3] = 1, s[0][4] = 3, s[0][5] = -1;
	s[1][0] = 3, s[1][1] = -1, s[1][2] = 0, s[1][3] = 5, s[1][4] = -1, s[1][5] = 2;
	s[2][0] = 1, s[2][1] = 5, s[2][2] = -1, s[2][3] = -1, s[2][4] = 0, s[2][5] = 4;	
	rep2(i,3,6) {
		rep(j,6) {
			s[i][j] = s[5 - i][5 - j];
		}
	}
	int q;
	cin >> q;
	rep(i,q) {
		cin >> head >> down;
		int b, c;
		rep(i,6) {
			if(a[i] == head) b = i;
			else if(a[i] == down) c = i;
		}
		cout << a[s[b][c]] << endl;
	}
	return 0;
}
	

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

long long a, b, c;

int main()
{
  cin >> a >> b >> c;
  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
    cout << 0, exit(0);
  cout << min(min(a * b, b * c), c * a);
}

Measured memory_bytes: 256
/**
    AUTHOR:JUNSH
    TIME:19/6/2
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a,b,c,d;
string s;
void go(int fr,int to){
    int p=s[fr];
    s[fr]='.';
    s[to]=p;
}
bool movb(){
    if(b==-1||b>d)
        return false;
    if(b==d){
        s[b]='#';
        b=-1;
        return false;
    }
    if(b<d){
        if(s[b+1]=='.'){
            go(b,b+1);
            b++;
            return true;
        }
        else if(s[b+1]=='#'){
            if(s[b+2]=='.'){
                go(b,b+2);
                b+=2;
                return true;
            }
            else if(s[b+2]=='#'){
                return false;
            }
            else return false;
        }
        else return false;
    }
}
bool mova(){
    if(a==-1||a>c)
        return false;
    if(a==c){
        s[a]='#';
        a=-1;
        if(b==d)return true;
        else while(movb()){};
        if(b==-1)return true;
        else return false;
    }
    if(a<c){
        if(s[a+1]=='.'){
            go(a,a+1);
            a++;
            mova();
        }
        else if(s[a+1]=='B'){
            if(c>d){
                if(s[a+2]=='.'){
                    go(a,a+2);
                    a+=2;
                    mova();
                }
                else if(movb()){
                    go(a,a+1);
                    a++;
                    mova();
                }
                else return false;
            }
            else if(movb()){
                go(a,a+1);
                a++;
                mova();
            }
            else return false;
        }
        else if(s[a+1]=='#'){
            if(s[a+2]=='.'){
                go(a,a+2);
                a+=2;
                mova();
            }
            else if(s[a+2]=='B'){
                if(movb())mova();
                else return false;
            }
            else return false;
        }
        else return false;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>a>>b>>c>>d;
    cin>>s;
    a--;
    b--;
    c--;
    d--;
    s[a]='A';
    s[b]='B';
    if(c>=n||d>n||c==d){
        cout<<"No"<<endl;
        return 0;
    }
    if(mova())
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int s[10],k,flag=0;
    for(int i=0;i<5;i++)
        scanf("%d",&s[i]);
    scanf("%d",&k);
    sort(s,s+5);
    if(s[4]-s[0]>k)
        flag=1;
    if(flag==0)
        printf("Yay!\n");
    else
        printf(":(\n");
    return 0;
}


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

const int INF = 1001001001;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, -1, 0, 1};

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(si, h)rep(sj, w){
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x){
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j));
        };
        update(si, sj, 0);
        while(!q.empty()){
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir,4){
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if(ni < 0 || nj < 0|| ni >= h||nj >= w) continue;
                if(s[ni][nj] =='#') continue;
                update(ni, nj, dist[i][j] + 1);
            }
        }
        rep(i, h)rep(j, w){
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> p(h,vector<char>(w));
    rep(i,h)rep(j,w)cin >> p[i][j];
    cout << string(w+2,'#') << "\n";
    rep(i,h)rep(j,w+2){
        if(j == 0)cout << '#';
        else if(j == w+1)cout << "#\n";
        else cout << p[i][j-1];
    }
    cout << string(w+2,'#') << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long MOD=1e9+7;
const long long LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXN=200050;

ll times[MAXN],sum1[MAXN],sum2[MAXN];
ll euler(int n) {
    ll ans=n;
    for(int i=2;i*i<=n;i++) {
        if(n%i==0) {
            ans=ans/i*(i-1);
            while(n%i==0)n/=i;
        }
    }
    if(n>1)ans=ans/n*(n-1);
    return ans;
}
ll mpow(ll a,ll n,ll MOD)
{
	if(a==1||n==0)return 1;
	ll ans=1;
	a%=MOD;
	while(n!=0)
	{
		if(n&1)ans=(ans*a)%MOD;
		n>>=1;
		a=(a*a)%MOD;
	}
	return ans%MOD;
}
void solve(int T){
	ll n,x,m,ans=0,tmp,phi,pphi;
	scanf("%lld %lld %lld",&n,&x,&m);
	if(n<=m){
		tmp=x;
		for(int i=1;i<=n;i++){
			ans+=x;
			x*=x;
			x%=m;
		}
		printf("%lld",ans);
		return;
	}
	phi=euler(m);
	pphi=euler(phi);
	for(int i=0;i<pphi&&i<=n-1;i++)times[i]=1;
	ll sy=(n-1)%pphi;
	for(int i=pphi;i<=2*pphi-1&&i<=n-1;i++){
		if(i%pphi<=sy)times[i]=(n-1)/pphi;
		else times[i]=(n-1)/pphi-1;
	}
	sum1[0]=1;
	int sta=0;
	for(int i=1;i<=2*pphi-1;i++){
		sum1[i]=(sum1[i-1]*2);
		if(sum1[i]>=phi){
			sta=1;
		}
		sum1[i]%=phi;
		if(sta)sum1[i]+=phi;
	}
	for(int i=0;i<=2*pphi-1;i++){
		ans+=times[i]*(mpow(x,sum1[i],m)%m);
	}
	printf("%lld",ans);
	
}
signed main(){
	int t=1;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//scanf("%d",&t); 
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

Measured memory_bytes: 5332
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/17/20 20:37:02
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

constexpr ll MOD = 1000000007;

ll modpow(ll x, ll p) {
  ll u = x;
  ll t = 1;
  while (p) {
    if (p&1)
      (t *= u) %= MOD;
    (u *= u) %= MOD;
    p>>=1;
  }
  return t;
}

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

  int n; cin>>n;
  map<pair<ll,ll>, int> AB;
  int zz = 0, ze = 0, ez = 0;
  for (int i = 0; i < n; i++) {
    ll a,b; cin>>a>>b;
    if (a!=0 and b!=0) {
      if (b < 0) {
        a *= -1;
        b *= -1;
      }
      auto g = gcd(abs(a),abs(b));
      a /= g; b /= g;
      AB[{a, b}]++;
    } else if (a==0 and b==0) {
      zz++;
    } else if (a==0) {
      ze++;
    } else {
      ez++;
    }
  }
  ll ans = 1;
  for (auto it = AB.begin(); it != AB.end(); ++it) {
    auto [k,c] = *it;
    if (c == 0) continue;
    auto [a,b] = k;
    ll p;
    auto invkey = make_pair(-b,a);
    if (a < 0) {
      invkey.first *= -1;
      invkey.second *= -1;
    }
    auto inv = AB.find(invkey);
    if (inv != AB.end()) {
      p = ((modpow(2, c) + modpow(2, inv->second))%MOD+MOD - 1)%MOD;
      inv->second = 0;
    } else {
      p = modpow(2, c);
    }
    (ans *= p) %= MOD;
  }
  (ans *= ((modpow(2, ze) + modpow(2, ez))%MOD+MOD - 1)%MOD) %= MOD;
  cout << (ans+zz-1+MOD)%MOD << endl;

  return 0;
}


Measured memory_bytes: 16016
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)
    

Measured memory_bytes: 9124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//bit全探索
ll bit_search(ll n, ll h, ll w, ll k, vector<vll> &grid) {
  vll bits(n, 0);
  ll lim = pow(2, n);
  ll ans = inf;
  for (ll i = 0; i < lim; i++) {

    ll cnt = 0;
    vll to_check(0);
    for (ll j = 0; j < n; j++) {
      if (bits[j] == 1) {
        cnt++;
        to_check.push_back(j);
      }
    }
    cnt++;
    to_check.push_back(h - 1);
    vector<vll> vv = grid;
    for (ll j = 0; j < w; j++) {
      for (ll l = 1; l < cnt; l++) {
        vv[to_check[l]][j] -= grid[to_check[l - 1]][j];
      }
    }
    vll v(cnt, 0);
    bool flag = false, flag2 = false;
    ll subans = cnt - 1;
    for (ll j = 0; j < w; j++) {
      flag = false;
      for (ll l = 0; l < cnt; l++) {
        ll hoge = vv[to_check[l]][j] - v[l];
        if (hoge > k) {
          if (j > 0 && !flag2) {
            flag = true;
            flag2 = true;
            subans++;
            break;
          }
          else {
            j = w;
            subans = inf;
            break;
          }
        }
        if (l == cnt - 1) flag2 = false;
      }
      if (flag) {
        for (ll l = 0; l < cnt; l++) v[l] = vv[to_check[l]][j - 1];
      }
      if (flag2) j--;
    }
    ans = min(ans, subans);

    if (i == lim - 1) return ans;
    ll x = 0;
    while (bits[n - 1 - x] == 1) {
      bits[n - 1 - x] = 0;
      x++;
    }
    bits[n - 1 - x] = 1;
  }
}

int main() {
  ll h, w, k;
  cin >> h >> w >> k;
  vector<vll> grid(h, vll(w));
  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      char c;
      cin >> c;
      grid[i][j] = c - '0';
      if (j > 0) grid[i][j] += grid[i][j - 1];
    }
  }
  for (ll i = 0; i < w; i++) {
    for (ll j = 1; j < h; j++) {
      grid[j][i] += grid[j - 1][i];
    }
  }

  /*for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w - 1; j++) {
      cout << grid[i][j] << " ";
    }
    cout << grid[i][w - 1] << endl;
  }*/

  ll ans = bit_search(h - 1, h, w, k, grid);
  cout << ans << endl;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

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

int N, C, D[32][32], c[512][512];

int main() {


	scanf("%d%d", &N, &C);
	rep(i, C) rep(j, C) scanf("%d", &D[i][j]);
	rep(i, N) rep(j, N) scanf("%d", &c[i][j]);

	ll Dsum[3][32] = {};
	rep(i, N) rep(j, N) rep(k, C) {
		Dsum[(i + j) % 3][k] += D[c[i][j] - 1][k];
	}

	ll ans = 287654321;
	rep(i, C) rep(j, C) rep(k, C) {
		if (i != j && j != k && k != i) {
			ans = min(ans, Dsum[0][i] + Dsum[1][j] + Dsum[2][k]);
		}
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main() {
    int64_t N, j;
    int64_t ans_fin;
    cin >> N;
    int64_t ans = N;
    for (int i = 1; i <= sqrt(N); i++){
        
        if (N % i == 0){
            j = N / i;
            if (j <= ans){
                string jj = to_string (j);
                ans_fin = jj.size();
                ans = j;
            }
            
        }
    }
    cout << ans_fin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
 
 
//#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
 
 
#define boost ios::sync_with_stdio(false); cin.tie(nullptr);
#define MOD 1000000007
#define sd(x) scanf("%d", &(x))
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ones(x) __builtin_popcount(x)
#define sz(x) int (x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define f1(i,a,b) for(int i=a; i<=b; i++)
#define rep(i,a,b) for(int i=a; i<b; i++)
#define NFOR(i,a,b) for(int i=(a);i>=(b);--i)
 
 
using ll = unsigned long long ;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;  
typedef double ld;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
 
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
 
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
 
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
 
bool chk(string a){
	string b(a);
	reverse(all(b));
	if(a==b) return true;
	else return false;
}

void solve(){
	int a , b ;
	int cnt=0;
	cin>>a>>b;
	for(int i =a ; i<=b ;++i){
		if(chk(to_string(i))) cnt++;
	}
	cout<<cnt<<endl;
}
 
signed main(){
	int T =1 ; 
	//sd(T);
	while(T--){
		solve();
	}
 
#ifdef np
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long ans=0;
long long a,b,c;
cin>>a>>b>>c;
if((c-a-b)<=0){
  ans=1;
}
else{
long long temp1=4*a*b;
long long temp2=(c-a-b)*(c-a-b);
if(temp1>=temp2){
  ans=1;
}
}
if(ans==1){
  cout<<"No"<<endl;
}
else{
  cout<<"Yes"<<endl;
}
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
int n;
int main()
{
  scanf("%d",&n);
  for (int i=1;i<=9;i++)
  for (int j=1;j<=9;j++)
  if (i*j==n) 
  {
  	cout<<"Yes"<<endl;
  	return 0;
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(3*N);
    REP(i,3*N) cin>>a[i];
    sort(ALL(a),greater<int>());

    int ans=0;
    REP(i,N) ans+=a[2*i+1];
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, Z, W = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = abs(a[-1] - W)
if N >= 2:
    ans = max(ans, abs(a[-1] - a[-2]))
print ans

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
vector<int> d;
vector<int> f;
vector<bool> used;
vector< vector<int> > v;
int n;
int cnt = 1;
 
void dfs(int pos){
  d[pos] = cnt; cnt++;
  used[pos] = true;
  for(int i = 0; i < n; i++){
    if(v[pos][i] && !used[i]){
      dfs(i);
    }
  }
  f[pos] = cnt; cnt++;
}
 
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  cin >> n;
  d = f = vector<int>(n, -1);
  used = vector<bool>(n, false);
  v = vector< vector<int> >(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      a--;
      v[u][a] = 1;
    }
  }
  for(int i = 0; i < n; i++)
    if(!used[i]) dfs(i);
  for(int i = 0; i < n; i++){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n;
int a[200100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
		if(a[i]==a[i-1]){
			cout<<"NO"<<endl;
			return 0;
		}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

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

    cout << (800 * n - (n / 15 * 200)) << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
int n,x,t;
bool a=false;
cin>>n>>x>>t;
if (n%x==0)
{
    cout<<n/x*t<<endl;
    goto owari;
}

cout<<(n/x+1)*t<<endl;
owari:
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
hi = list(map(int, input().split()))
count = 0
maxcount = 0
for i in range(N - 1):
    if hi[i] >= hi[i + 1]:
        count += 1
    else:
        maxcount = max(count,maxcount)
        count = 0
if count > maxcount:
    maxcount = count
print(maxcount)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    FOR(i, L, R + 1){
        if (i % d == 0) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	if (N == 2) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	
	int i, j, k, l, r;
	char ans[10][10][10] = {{}, {}, {},
		{".aa", "a..", "a.."},
		{"abcc", "abdd", "ccab", "ddab"},
		{"abbcc", "a.aab", "ca..b", "ca..a", "bbcca"},
		{"abb.aa", "a.ca..", "bbca..", ".aacbb", "a..c.a", "a..bba"},
		{".aa.aab", "a..a..b", "a..a..c", ".aa.aac", "a..a..b", "a..a..b", "bbccbb."},
		{"abcc....", "abdd....", "ccab....", "ddab....", "....abcc", "....abdd", "....ccab", "....ddab"}
	};
	if (N % 3 == 0) {
		k = N / 3;
		for (l = 0; l < k; l++) {
			for (i = 0; i < 3; i++) {
				for (j = 0; j < k; j++) printf("%s", ans[3][i]);
				printf("\n");
			}
		}
	} else {
		k = (N - 4) / 6;
		r = (N - 4) % 6 + 4;
		for (l = 0; l < k; l++) {
			for (i = 0; i < 6; i++) {
				for (j = 0; j < k; j++) {
					if (j == l) printf("%s", ans[6][i]);
					else printf("......");
				}
				for (j = 0; j < r; j++) printf(".");
				printf("\n");
			}
		}
		for (i = 0; i < r; i++) {
			for (j = 0; j < k * 6; j++) printf(".");
			printf("%s\n", ans[r][i]);
		}
	}	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1736
/************************
*                       *
* Nothing Is Impossible *
*                       *
************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld; 
using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << (n*n) << endl;
	return 0;
}

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

int main()
{
    int N, M;
    cin>>N>>M;

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

    int ans = 0;
    multiset<int> S;
    for (int i=0; i<M; i++)
    {
        for (int b: B[i+1])
            S.insert(-b);
        if (!S.empty())
        {
            ans += -*S.begin();
            S.erase(S.begin());
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = n;
	for (int k = 0; k < n - 1; k++) {
		if (s[k] != s[k + 1]) {
			ans = min(ans, max(k + 1, n - (k + 1)));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

int main()
{
    std::map<char, int> mp;
    std::string s;

    while (getline(std::cin, s)) {
        std::transform(s.cbegin(), s.cend(), s.begin(), tolower);
        for (int i = 0; i < s.size(); i++) {
            mp[s[i]]++;
        }
    }
    for (char i = 97; i < 123; i++) {
        std::cout << i << " : " << mp[i] << std::endl;
    }
}


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

int main() {
  int N;cin>>N;
  vector<int> X(N);
  for(int i=0;i<N;i++) cin>>X.at(i);
  
  vector<int> Y(100);
  for(int p=1;p<=100;p++){
    for(int i=0;i<N;i++){
      int z=X.at(i)-p;
      Y.at(p-1) +=z*z;
    }
  }
  sort(Y.begin(),Y.end());
  cout<<Y.at(0)<<endl;
      
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ullong = unsigned long long;

void fnInput(int& rnStair, vector<int>& rvnBroken)
{
  int nBrokenSiz;
  cin >> rnStair >> nBrokenSiz;
  rvnBroken.resize(nBrokenSiz);

  for (int& rnBroken : rvnBroken)
    cin >> rnBroken;
}

void fnDPWaySet(int nStair, vector<ullong>& rvnDPWays)
{
  rvnDPWays.resize(nStair + 1);
  rvnDPWays[0] = 1;

  for (int i = 1; i < rvnDPWays.size(); i++)
  {
    rvnDPWays[i] += rvnDPWays[i - 1];
    if (i > 1)
      rvnDPWays[i] += rvnDPWays[i - 2];

    rvnDPWays[i] %= 1000000007;
  }
}

bool fnUseFulStairSet(int nStair, vector<int>& rvnUseful, const vector<int>& cnrvnBroken)
{
  for (int i = 0; i < cnrvnBroken.size(); i++)
    if (i == 0)
      if (cnrvnBroken[i] == 1);
      else
        rvnUseful.push_back( cnrvnBroken[i] - 1 );
    else
      if (cnrvnBroken[i] - cnrvnBroken[i - 1] == 1)
        return false;
      else
        rvnUseful.push_back( (cnrvnBroken[i] - 1) - (cnrvnBroken[i - 1] + 1) );

  if (cnrvnBroken.size())
    rvnUseful.push_back( nStair - (cnrvnBroken[cnrvnBroken.size() - 1] + 1) );
  else
    rvnUseful.push_back( nStair );
  return true;
}

ullong fnNumOfWays(int nStair, const vector<int>& cnrvnBroken)
{
  vector<ullong> vnDPWays;
  fnDPWaySet(nStair, vnDPWays);

  vector<int> vnUseful;
  if (!fnUseFulStairSet(nStair, vnUseful, cnrvnBroken))
    return 0;

  ullong nNumOfWays = 1;

  for (int nUseful : vnUseful)
  {
    nNumOfWays *= vnDPWays[ nUseful ];
    nNumOfWays %= 1000000007;
  }
  
  return nNumOfWays;
}
  
int main()
{
  int nStair;
  vector<int> vnBroken;

  fnInput(nStair, vnBroken);
  cout << fnNumOfWays(nStair, vnBroken) << endl;

  return 0;
}

Measured memory_bytes: 4532
N = int(input())
count = 0
keta_list = [9, 0, 900, 0, 90000, 0]
genkai_list = [9, 0, 999, 0, 99999, 0]
keta = len(str(N))
for target_list in range(keta):
    if N > genkai_list[target_list]:
        count = count + keta_list[target_list]
    else: 
        count = count + N - 10 ** (target_list)+1
print(count)


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

int main(){
	while(true){
		int m,nmin,nmax;
		cin>>m>>nmin>>nmax;

	if(m==0 && nmin==0 && nmax==0){
		break;
	}

	int P[200];
	for(int i=0;i<m;i++){
			cin>>P[i];
	}

	int gap = -1;
	int n = -1;
	
	for(int i=nmin;i<=nmax;i++){
		int g = P[i-1]-P[i];

		if(gap<=g){
			gap =g;
			n=i;
		}
	}
	cout<< n<<endl;
	}

	return 0;
}

 


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

class disjointset{

  public:

    vector<int>rank,parent,sz;//木xの高さはrank[x]以下，parentは親ノードの番号，sz[頂点]はその集合の要素の数を指す

    disjointset(int size){//0,1,2,...size　　←注意
        rank=parent=sz=vector<int>(size+1);
        for(int i=0;i<=size;i++)rank[i]=0,parent[i]=i,sz[i]=1;
    }
      //注意 parent配列はrootを呼ばないと更新されない
    int root(int n){return (parent[n]==n?n:parent[n]=root(parent[n]));}//経路圧縮

    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return;
        (rank[x]>rank[y])?parent[y]=x,sz[x]+=sz[y]:parent[x]=y,sz[y]+=sz[x];//低い木が高い木に属する
        rank[root(x)]+=(rank[x]==rank[y]);//同じ高さの場合　頂点の高さを1足す
    }

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

    int size(int n){return sz[root(n)];}
};

int N,M,A,B,ans;
int main(){
    cin>>N>>M;
    disjointset ds(N);
    for(int i=0;i<M;i++){
        cin>>A>>B;
        ds.unite(A-1,B-1);
    }
    map<int,int>m;
    for(int i=0;i<N;i++){
        m[ds.root(i)]++;
    }
    for(auto x:m){
        ans=max(ans,x.second);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14812
N, M = map(int, input().split())
cnt = 0
K = list()
L = list()
for m in range(M):
    l = list(map(int, input().split()))
    k = l.pop(0)
    K.append(k)
    L.append(l)
P = list(map(int, input().split()))
for i in range(1<<N):
    flag = True
    for j in range(M):
        c = 0
        for l in range(K[j]):
            if i & (1<<L[j][l]-1):
                c += 1
        if c % 2 != P[j]:
            flag = False
    if flag:
        cnt += 1
print(cnt)

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

ll gcd(ll a, ll b) {
    if (a < b) {
        return gcd(b, a);
    }
    ll c = a % b;
    while (c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> n >> m;
    vl x(n);
    IPT(x, n)

    sort(ALL(x));
    if (n == 1) {
        END(abs(m - x[0]))
    }

    ans = abs(m - x[0]);
    NREP() {
        ans = gcd(ans, abs(m - x[i]));
    }
    MSG(ans)
}


Measured memory_bytes: 3948
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
//     let s = read1::<String>();
//     s.split(delimiter)
//         .map(|e| e.parse().ok().unwrap())
//         .collect::<Vec<T>>()
// }

fn main() {
    let s = read1::<String>().to_string();
    let odd = "RUD";
    let even = "LUD";

    for (i, c) in s.as_str().chars().enumerate() {
        if (i + 1) % 2 == 0 {
            if !even.contains(c) {
                return println!("No");
            }
        } else {
            if !odd.contains(c) {
                return println!("No");
            }
        }
    }

    println!("Yes")
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

struct th {
    int a, b, c;
    const bool operator<(const th& t) const {
        return a != t.a ? a < t.a : b != t.b ? b < t.b : c < t.c;
    }
};

int nxt(int x, int dig) {
    string s = to_string(x);
    while (s.length() < dig) s = '0' + s;
    sort(all(s));
    int a = stoi(s), b = stoi(string(s.rbegin(), s.rend()));
    return b - a;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    while (true) {
        int n, m; cin >> n >> m;
        if (!n && !m) break;
        map<int, int> mp;
        mp[n] = 0;
        for (int i = 1;; i++) {
            n = nxt(n, m);
            if (mp.find(n) == mp.end()) {
                mp[n] = i;
            } else {
                cout << mp[n] << " " << n << " " << i - mp[n] << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX =  1e6+6;
int N, a[MAX], mp[MAX];
int factors[MAX];

bool fat(int N) {
	bool pri = 1;
	while (N % 2 == 0) {
		if(factors[2] && pri) return false;
		++factors[2];
		N >>= 1;
		pri = 0;
	}
	for(ll PF = 3; PF * PF <= N; PF += 2) {
		pri = 1;
		while(N % PF == 0) {
			if(factors[PF] && pri) return false;
			N /= PF; factors[PF]++;
			pri = 0;
		}
	}
	if(N > 1) {
		if(factors[N]) return false;
		factors[N] = 1;
	}
	return true;
}

int main(int argc, char ** argv) {
	int cnt = 0;
	scanf("%d", &N);
	rep(i, 0, N) scanf("%d", a+i);
	rep(i, 0, N)
		cnt += fat(a[i]);
	int g = a[0];
	if(cnt == N) puts("pairwise coprime"), exit(0);
	rep(i, 0, N) g = __gcd(g, a[i]);
	if(g == 1) puts("setwise coprime");
	else puts("not coprime");
	return 0;
}


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

const int mod = 998244353;

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

    if(d0 != 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> d(100005);
    d.at(0) = 1;
    int max_d = 0;
    for(int i = 1; i < n; ++i) {
        int di;
        cin >> di;
        max_d = max(max_d, di);
        d.at(di)++;
    }

    if(d.at(0) != 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    int i = 1;
    while(i < n) {
        if(d.at(i) == 0) break;
        rep(j, d.at(i)) {
            ans *= d.at(i-1);
            ans %= mod;
        }
        ++i;
    }
    if(i < max_d) cout << 0 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3796
import Control.Applicative
import Data.List
import Data.Int
import Debug.Trace

count :: [Integer] -> Integer
count [h, w] =
    let 
        calc :: Integer -> Integer
        calc ver =
            let left = h * ver
                top = (w - ver) * (div h 2)
                bottom = (w - ver) * (h - (div h 2))
                [a, _, b] = sort [left, top, bottom]
                in b - a
        calc_ :: Integer -> Integer
        calc_ ver =
            let top = w * ver
                left = (h - ver) * (div w 2)
                right = (h - ver) * (w - (div w 2))
                [a, _, b] = sort [left, right, top]
                in b - a
        cross :: Integer -> Integer
        cross ver
            | ver > div h 2 = h * w
            | otherwise = min (cross (ver + 1)) (calc_ ver)
        crossed :: Integer -> Integer
        crossed ver
            | ver > div w 2 = w * h
            | otherwise = min (crossed (ver + 1)) (calc ver)
        parallel :: Integer
        parallel = if (mod h 3) == 0 || (mod w 3) == 0 then 0 else w
        in min (cross 1) (min parallel $ crossed 1)
        

main = print =<< count . reverse . sort . (map (\a -> read a :: Integer)) . words <$> getLine


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


double GetMean(double x, double y) {
	
	return (x + y) / 2;
}

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

	vector<double> v(n);
	
	for (int i = 0; i < n; i++) { cin >> v[i]; }

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

	for (int i = 1; i < n; i++) {
		
		v[i] = GetMean(v[i - 1], v[i]);

	}

	cout << fixed << setprecision(11) << v[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    string s;
    cin >> s;
    int n = s.size() - 1;
    lint ans = 0;
    rep(i, 1 << n)
    {
        lint num = 0;
        lint cc = s[0] - '0';
        rep(j, n)
        {
            if ((i >> j) & 1)
            {
                num += cc;
                cc = s[j + 1] - '0';
            }
            else
            {
                cc *= 10;
                cc += s[j + 1] - '0';
            }
        }
        num += cc;
        ans += num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256