akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char a = sc.nextLine().charAt(0);
        sc.close();

        if(Character.isUpperCase(a)) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int tmp = 0;
    for (int i = 1; i < b-a; i++){
        tmp += i;
    }
    cout << tmp - a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n;
	string s;
	cin >> s;
	n=s.size();
	int mn=n;
	for(char x='a'; x<='z'; x++)
	{
		int tmp=0;
		int mx=0;
		rep(i, n)
		{
			if(s[i]==x)
			{
				mx=max(mx, tmp);
				tmp=0;
			}
			else tmp++;
		}
		mx=max(mx, tmp);
		mn=min(mn, mx);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		int N = scan.nextInt();

		long ans = 0L;

		for (int i = 1; i <= N; i++) {
			ans += (N-1) / i;
		}

		//結果出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define INF 1000000001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n, dp[MAX_N];

signed main(){
	cin >> n;
	dp[0] = 0;
	for(int i=1; i<=n; i++){
		dp[i] = INF;
		int j = 1;
		while(i >= j){
			dp[i] = min(dp[i-j] + 1, dp[i]);
			j *= 6;
		}
		j = 1;
		while(i >= j){
			dp[i] = min(dp[i-j] + 1, dp[i]);
			j *= 9;
		}
	}
	cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
int main(){
  int A;
  int B;
  rd(A);
  rd(B);
  wt_L(max_L(0, A-2*B));
  wt_L('\n');
  return 0;
}
// cLay varsion 20191012-1

// --- original code ---
// {
//   int A, B;
//   rd(A,B);
//   wt(max(0, A-2B));
// }


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	while(cin >> n , n){
		pair<int,int> ans;
		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			ans = max( ans , make_pair(b+c,a));
		}
		cout << ans.second << " " << ans.first << endl;
	}
}

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

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

  int x;
  cin >> x;

  if (x == 3 || x == 5 || x == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;
using T = tuple<int, int, lint>;

int main(void) {
  vector<int> dx {1, 1, 0, -1, -1, -1, 0, 1};
  vector<int> dy {0, 1, 1, 1, 0, -1, -1, -1};
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        cout << '#';
        continue;
      }
      int ans = 0;
      for (int k = 0; k < 8; ++k) {
        int x = j + dx[k];
  	    int y = i + dy[k];
        if (x < 0 || x >= w) continue;
        if (y < 0 || y >= h) continue;
        if (s[y][x] == '#') ++ans;
          //dump(j); dump(i); dump(k); dump(x); dump(y); dump(ans); el;
      }
      cout << ans;
    }
    cout << endl;
  }
}
          

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
ll two[50+5],s;
int a[210],b[50+5],c[210];
int i,j,k,l,t,n,m,mx,tot,top,now;
int main(){
	//freopen("data.out","w",stdout);
	scanf("%lld",&s);
	two[0]=1;
	fo(i,1,50) two[i]=(ll)two[i-1]*2;
	mx=50;
	while (two[mx]>s) mx--;
	s-=two[mx];
	m=mx;
	tot=2*m;
	now=m;
	c[++top]=now+1;
	c[++top]=now+1;
	now++;
	tot+=2;
	while (s){
		while (two[mx]>s) mx--;
		s-=two[mx];
		b[mx]=++now;
		c[++top]=now;
		tot+=2;
	}
	printf("%d\n",tot);
	fo(i,0,m){
		if (i) printf("%d ",i);
		if (b[i]) printf("%d ",b[i]);
	}
	fo(i,1,m) printf("%d ",i);
	fo(i,1,top) printf("%d ",c[i]);
}

Measured memory_bytes: 128
S = input()
L = [S[i] for i in range(int((len(S)-1)/2))]
R = [S[-i-1] for i in range(int((len(S)-1)/2))]
def kaibun(A):
    is_flag = True
    for i in range(int((len(S)-1)/2)):
        if A[i] != A[-i-1]:
            is_flag = False
            break
        else:
            continue
    if is_flag == True:
        return True
    else:
        return False

is_flag = kaibun(S)
if is_flag == False:
    print("No")
else:
    if kaibun(L)==True and kaibun(R)==True:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

ll mod = static_cast<ll>(1e9+7);

int main()
{
    ll n, k;
    cin >> n >> k;
    vl nums(n+2, 0);
    for(ll i=1; i<=n+1; i++)
    {
        ll nin = (0 + i-1) * i / 2;
        nin %= mod;
        ll nax = (n + n - i + 1) * i / 2;
        nax %= mod;
        if(nax > nin)
        {
            nums.at(i) = nax - nin + 1;
        }
        else
        {
            nums.at(i) = nax - nin + 1 + mod;
        }
    }
    ll ans = 0;
    for(ll i=k; i<=n+1; i++)
    {
        ans += nums.at(i);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4752
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int W, a, b;
  ci(W, a, b);
  if(b + W < a){
    co(a - (b + W));
  }
  else if(a + W < b){
    co(b - (a + W));
  }
  else{
    co(0);
  }
}

Measured memory_bytes: 256
N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A)
M=max(A)
count=A.count(M)
for i in range(N):
  if count>1:
    print(M)
  elif A[i]!=M:
    print(M)
  else:
    print(B[-1-count])

Measured memory_bytes: 18964
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

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

int main()
{
	int n;
	ll m;
	cin>>n>>m;
	ll a[20];
	double p[20];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=0; i<n; i++){
		cin>>p[i];
	}
	ll c[1048576];
	c[0]=0;
	for(int i=1; i<(1<<n); i++){
		ll lcm=1;
		for(int j=0; j<n; j++){
			if(i&(1<<j)){
				ll g=gcd(lcm, a[j]);
				if(lcm/g>m/a[j]){
					lcm=-1;
					break;
				}
				lcm=lcm/g*a[j];
			}
		}
		if(lcm==-1){
			c[i]=0;
		}else{
			c[i]=m/lcm;
		}
	}
	for(int k=0; k<n; k++){
		for(int i=(1<<n)-1; i>=1; i--){
			if(i&(1<<k)) c[i]-=c[i^(1<<k)];
		}
	}
	double ans=0;
	for(int i=0; i<(1<<n); i++){
		double p0=1;
		for(int j=0; j<n; j++){
			if(i&(1<<j)) p0*=(p[j]/100);
			else p0*=(1-p[j]/100);
		}
		ans+=((double)(abs(c[i]))*p0);
	}
	printf("%.9lf\n", ans);
	return 0;
}


Measured memory_bytes: 11488
N, M = gets.chomp.split(" ").map(&:to_i)
SW = Hash.new
M.times{|i|
  k = gets.chomp.split(" ").map(&:to_i)
  SW[i] = k[1..-1]
}
P = gets.chomp.split(" ").map(&:to_i)

A = []
def make_all_pattern(i, &b)
  if i == 0 then
    b.call(A)
    return
  end
  A << 0
  make_all_pattern(i - 1, &b)
  A.pop
  A << 1
  make_all_pattern(i - 1, &b)
  A.pop
end


ans = 0
make_all_pattern(N){|a|
  flg_all_light = true
  SW.each{|k, v|
    oncnt = a.select.with_index{|n, idx| v.include?(idx+1)}.inject(:+)
    if (oncnt + P[k]).odd? then
      flg_all_light = false
      break
    end
  }
  ans += 1 if flg_all_light
}

puts ans


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

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a; i <= b; i++) {
		
		if ((i / 10000 % 10 == i % 10) && (i / 1000 % 10 == i / 10 % 10)) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

using namespace std;

int main()	{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b <= c || d <= a)	{
    cout << 0 << endl;
  }
  else	{
  	cout << abs(max(a, c) - min(b, d)) << endl;
  }
  return 0;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int x; cin >> x;
	rep1(i,1000000){
		x -= i;
		if(x<=0){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld a,c,r,j,l,x,y,m,b,n,s,f,q,i,z,p,k,d,t,u,e,g;string s1,s2,s3,s4;
vi v[10000001];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin>>n>>k;
  if(k==0)
  {
    cout<<n*n;return 0;
  }s=0;
  rep(i,k+1,n+1)
  {
    p=n%i,q=n/i;
    if(p<k)
    {
      s+=(q*((i-k)));
    }
    else
    {
      s+=(q*(i-k));
      s+=(p-k+1);
    }
    //cout<<s<<" "<<i<<endl;
  }
  cout<<s;
}

Measured memory_bytes: 234752
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    REP(i, 0, n){
        cin >> a.at(i);
    }

    ll max_d = 0;
    ll note = 0;
    REP(i, 0, n - 1){
        if(max_d < a.at(i + 1) - a.at(i)){
            max_d = a.at(i + 1) - a.at(i);
//            note = i;
        }
    }

    if(max_d < a.at(0) - (a.at(n - 1) - k)){
        max_d = a.at(0) - (a.at(n - 1) - k);
    }

    p(k - max_d);

}

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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    ll sum = 0;
    ll n;
    cin >> n;
    for(ll i = 1; i<=n; i++) {
        for(ll j = 1; j<=n; j++) {
            for(ll k = 1; k<=n; k++) {
                sum += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout << sum ;
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int len=s.size();
	/*for(int i=0;i<len;i++)
	{
		for(int j=i+1;j<len;j++)
		{
			if(s[j]==s[i])
			{
				n=j-i-1;
				if(n%2==0)
					cout<<"First";
				else
					cout<<"Second";
				return 0;
			}
		}
	}*/
	if(s[0]==s[len-1])
	{
		if(len%2)
			cout<<"Second";
		else
			cout<<"First";
	}
	else
	{
		if(len%2)
			cout<<"First";
		else
			cout<<"Second";
	}
	return 0;
}
//game

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int N, X[200000];

int main() {
    cin >> N;
    int tmp[200000];
    REP(i, N) {
        cin >> X[i];
        tmp[i] = X[i];
    }
    sort(tmp, tmp + N);
    int c1 = tmp[N / 2 - 1], c2 = tmp[N / 2];

    REP(i, N) {
        if (X[i] < c2) cout << c2 << endl;
        else cout << c1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>

using namespace std;

int main(){
	int n,a=10,b=100,c=1000,d=10000,e=100000,f=90,g=990,h=9990,k=99990;
	int ans=0;
	
	cin >> n;
	
	
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			int temp1 = 0,temp2;
			if(n>=i && i==j){
				temp1++;
				if( n >= a*i+j){
					temp1++;
				}
				
				if(n >= b*i+j){
					if( n >= b*i+j+f)temp1 += a;
					else {
						temp1 += (n-b*i)/a;
						if(n%a >= j) temp1++;
					}
				}
				
				if(n >= c*i+j){
					if( n >= c*i+j+g)temp1 += b;
					else {
						temp1 += (n-(c*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				
				if(n >= d*i+j){
					if( n >= d*i+j+h)temp1 += c;
					else {
						temp1 += (n-(d*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				
				if(n >= e*i+j){
					if( n >= e*i+j+k)temp1 += d;
					else {
						temp1 += (n-(e*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				ans += (temp1*temp1);
			}else{
				if( n >= a*i+j){
					temp1++;
				}
				
				if(n >= b*i+j){
					if( n >= b*i+j+f)temp1 += a;
					else {
						temp1 += (n-(b*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				
				if(n >= c*i+j){
					if( n >= c*i+j+g)temp1 += b;
					else {
						temp1 += (n-(c*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				
				if(n >= d*i+j){
					if( n >= d*i+j+h)temp1 += c;
					else {
						temp1 += (n-(d*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				
				if(n >= e*i+j){
					if( n >= e*i+j+k)temp1 += d;
					else {
						temp1 += (n-(e*i))/a;
						if(n%a >= j) temp1++;
					}
				}
				
				temp2 = temp1;
				temp1 = 0;
				
				if( n >= a*j+i){
					temp1++;
				}
				
				if(n >= b*j+i){
					if( n >= b*j+i+f)temp1 += a;
					else {
						temp1 += (n-(b*j))/a;
						if(n%a >= i) temp1++;
					}
				}
				
				if(n >= c*j+i){
					if( n >= c*j+i+g)temp1 += b;
					else {
						temp1 += (n-(c*j))/a;
						if(n%a >= i) temp1++;
					}
				}
				
				if(n >= d*j+i){
					if( n >= d*j+i+h)temp1 += c;
					else {
						temp1 += (n-(d*j))/a;
						if(n%a >= i) temp1++;
					}
				}
				
				if(n >= e*j+i){
					if( n >= e*j+i+k)temp1 += d;
					else {
						temp1 += (n-(e*j))/a;
						if(n%a >= i) temp1++;
					}
				}
				
				ans += (temp1*temp2);
			}
		}
	}
	
	cout << ans << endl;
	
		
		
	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    XY = [[int(i) for i in input().split()] for j in range(N)]
    from itertools import permutations
    from math import hypot
    ans = 0
    for p in permutations(range(N)):
        cur = 0
        pre = p[0]
        for i in p[1:]:
            cur += hypot(XY[pre][0] - XY[i][0], XY[pre][1] - XY[i][1])
            pre = i
        ans += cur
    fa = 1
    for i in range(2, N+1):
        fa *= i
    print(ans/fa)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40556
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan =new Scanner(System.in);
		while(true){
		int n=scan.nextInt();
		if(n==-1)break;
		int []a=new int[10];
		int len=0;
		while(n!=0){
			a[len]=n%4;
			n=n/4;
			len++;
		}
		if(len==0)System.out.println('0');
		else{
		for(int i=len-1;i>=0;i--){
			System.out.print(a[i]);
			}
		System.out.println();
		}
		}
	}
}

Measured memory_bytes: 23436
n,a,b = map(int, input().split())
s = input()


countA = 0
countB = 0
for i in s:
  if i == 'a' and countA + countB < a + b:
    print("Yes")
    countA += 1
  elif i == 'b' and countA + countB < a + b and countB < b:
    print("Yes")
    countB += 1
  else:
    print("No")


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			B();
		}

		public static void B()
		{
			Scanner cin = new Scanner();
			int a = cin.NextInt();
			int b = cin.NextInt();
			int k = cin.NextInt();

			List<int> values = new List<int>();
			for (int n = a; n > 0; --n) {
				if (a % n == 0) {
					if (b % n == 0) {
						values.Add(n);
					}
				}
			}

			Console.WriteLine(values[k - 1]);
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define y1 asdgh
#define int long long
#define double long double
#define endl '\n'
//mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
//#pragma warning(disable:4996)
//#pragma comment(linker, "/STACK:336777216")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*------------------------------<Debugging Stuff>---------------------------------*/

template<class L, class R> ostream& operator<<(ostream &os, pair<L , R> P) {
      return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R , class M> ostream& operator<<(ostream &os, tuple<L , R , M> P) {
      return os << "(" << get<0>(P) << "," << get<1>(P) << "," << get<2>(P) << ")";
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
      os << "{ "; for(auto v : V) os << v << " "; return os << "}";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*------------------------------</Debugging Stuff>--------------------------------*/
const int maxn = (int) 1e6 + 6;
const double EPS = 1e-9;
const int INF = (int) 1e18 + 18;
const int mod = (int) 1e9 + 7;

signed main() {
      
      fio;
      int n; cin >> n;
      vector<int> a(n);
      for(int &x : a) cin >> x;
      sort(a.begin() , a.end());
      
      int ans = 0;
      for(int i = 1; i <= (int) 1e5; i++){
            int small = lower_bound(a.begin() , a.end() , i) - a.begin();
            int big = n - small;
            if(small == big)
                  ans++;
      }
      
      cout << ans << endl;
      
      
      
      return 0;
}

// IMPORTANT -:
// check base cases n = 0 , n = 1
// max / min questions - check for binary search
// difference array might be interesting


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

int main(void)
{
	int i, j, x, num, same;
	int count[1000] = {0}, big, place;
	int l_count[1000] = {0}, l_place;
	char c;
	char words[1000][32], l_word[1000][32];
	
	j = 0;
	i = 0;
	num = 0;
	
	while (1){
		scanf("%c", &c);
		
		if (c == '\n'){
			break;
		}
		else if (c == ' '){
			if (num != 0){
				same = 0;
				for (x = 0; x < num; x++){
					if (strcmp(l_word[x], words[j]) == 0){
						l_count[x]++;
						same = 1;
						break;
					}
				}
				
				if (same != 1) {
					strcpy(l_word[num], words[j]);
					l_count[num]++;
					num++;
				}
				
			}
			else {
				strcpy(l_word[0], words[0]);
				l_count[num]++;
				num++;
			}
			
			i = 0;
			j++;
			
		}
		else {
			words[j][i] = c;
			i++;
			count[j]++;
		}
		
	}
	
	big = 0;
	place = 0;
	
	for (i = 0; count[i] != 0; i++){
		if (count[i] > big){
			big = count[i];
			place = i;
		}
	}
	
	big = 0;
	l_place = 0;
	
	for (i = 0; l_count[i] != 0; i++){
		if (l_count[i] > big){
			big = l_count[i];
			l_place = i;
		}
	}
	
	printf("%s %s\n", words[l_place], words[place]);
	
	return (0);
}

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

int main () {
  string S;
  cin >> S;
  int count = 0;
  
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (S.at(i) == S.at(j)) {
        count ++;
      }
    }
  }
  if (count == 8) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

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

	Int cnt = 0;

	for (int i = 0; i < n; i++) {
		if (i == 0) cnt = k;
		else cnt *= k - 1;
	}
	cout << cnt;


	cout << endl;
	return 0;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
    int h, w;
    cin >> h >> w;
    string s[h][w];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if(s[i][j] == "snuke"){
                printf("%c%d\n", 'A' + j , i+1);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, r int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}
	p := 1
	var w []int
	for i := 0; i < N; i++ {
		if a[i] == p {
			w = append(w, p)
			p++
		} else {
			r++
		}
	}
	if len(w) == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(r)
	}
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main() {
  lli A,B,C,D,E,F,N,M,K,sum=0,num=0,ans=0;
  cin >> N;
  vector<double>P(N,0);
  rep(i,0,N)cin >> P[i];
  Sort(P);
  rep(i,1,N){
    P[i]=(P[i]+P[i-1])/2;
  }
  HpOut(P[N-1]);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i, n - 1) {
        if(s[i] != s[i + 1]) ans ++;
    }
    cout << ans + 1 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    
    int num=1;
    int i=0;
    while(num<b){
        num+=a-1;
        i++;
    }
    printf("%d\n", i);
    return 0;
}


Measured memory_bytes: 1732
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<i32>();
    let a = v[0];
    let b = v[1];

    let ans = std::cmp::max(std::cmp::max(a+b, a-b), a *b);
    println!("{}", ans);
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(begin(h), end(h));
  int ans = 1e9;
  for (int i = 0; i < N - K + 1; i++) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;

int r,g,b,n;
string s;

int main() {
	cin >>r>>g>>b>>n;
	int ans = 0;
	for (int i = 0; i <=n/r; i++)
	{
		for (int j = 0; j <= n/g; j++)
		{
			if (((n - i * r - j * g) % b == 0) && n - i * r - j * g >= 0)ans++;
		}
	}
	cout << ans<<endl;


}

Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int INF = Integer.MAX_VALUE;

        while(true){

            int n = sc.nextInt();
            if(n==0) break;

            int[] p = new int[n];
            int[] t = new int[n];
            for(int i=0; i<n; i++){
                p[i] = sc.nextInt();
                t[i] = sc.nextInt();
            }

            int[][] dp = new int[n][4];
            for(int i=0; i<n; i++) Arrays.fill(dp[i], INF);

            int NG = -1;
            if(p[0]<=t[0]) dp[0][1] = p[0];
            else NG = 1;

            for(int i=1; i<n; i++){
                if(NG!=-1) break;
                if(dp[i-1][3]!=INF && p[i-1]*4+p[i]<=t[i]-t[i-1]){
                    dp[i][1] = dp[i-1][3] + p[i-1] + p[i];
                }
                if(dp[i-1][2]!=INF && p[i-1]*3+p[i]<=t[i]-t[i-1]){
                    dp[i][1] = Math.min(dp[i][1], dp[i-1][2] + p[i-1] + p[i]);
                }
                if(dp[i-1][1]!=INF && p[i-1]*2+p[i]<=t[i]-t[i-1]){
                    dp[i][1] = Math.min(dp[i][1], dp[i-1][1] + p[i-1] + p[i]);
                }                
                if(dp[i-1][1]!=INF && Math.abs(p[i-1]-p[i])*2<=t[i]-t[i-1]){
                    dp[i][2] = dp[i-1][1] + Math.abs(p[i-1]-p[i]);
                }
                if(dp[i-1][2]!=INF && Math.abs(p[i-1]-p[i])*3<=t[i]-t[i-1]){
                    dp[i][3] = dp[i-1][2] + Math.abs(p[i-1]-p[i]);
                }
                if(dp[i][1]==INF && dp[i][2]==INF && dp[i][3]==INF){
                    NG = i+1;
                    break;
                }
            }


            if(NG!=-1) System.out.println("NG " + NG);
            else{
                int d1 = INF, d2 = INF, d3 = INF;
                if(dp[n-1][1]!=INF) d1 = dp[n-1][1] + p[n-1];
                if(dp[n-1][2]!=INF) d2 = dp[n-1][2] + p[n-1];
                if(dp[n-1][3]!=INF) d3 = dp[n-1][3] + p[n-1];
                System.out.println("OK " + Math.min(d1 ,Math.min(d2, d3)));
            }
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 25364
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();

		HashMap<Integer, Integer> remMap = new HashMap<>();

		int bef=0;
		int modsum;
		for (int i=0; i<n; i++){
			int a = scanner.nextInt();
			modsum = (bef+a)%m;
			remMap.put(modsum, remMap.getOrDefault(modsum,0)+1);
			bef = modsum;
		}

		long ans = remMap.getOrDefault(0, 0);
		for (int rem: remMap.values()){
			if (rem<=1) continue;
			ans += rem*(rem-1L)/2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 64772
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  s = ns() + "0"
  k = ni()
  n = len(s) - 1

  if n * s[0] == s[:-1]:
    print((n * k) // 2)
    return

  isSame = True if s[0] == s[-2] else False

  cnt = 1
  w = []
  w_cnt = []
  pre = s[0]
  ans = 0
  tmp = 0
  for i in range(1, n + 1):
    if pre == s[i]:
      cnt += 1
    else:
      w_cnt.append(cnt)
      tmp += cnt // 2
      cnt = 1
      w.append(pre)
      pre = s[i]

  if isSame:
    joins = (w_cnt[0] + w_cnt[-1]) // 2
    ans = 0
    for c in w_cnt[1:-1]:
      ans += c // 2
    print(ans * k + joins * (k - 1) + w_cnt[0] // 2 + w_cnt[-1] // 2)
  else:
    ans = tmp
    print(ans * k)
  # print(w_cnt[1:-1])
  
  # print(isSame)

main()

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

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

void solve()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * c, max(a * d, max(b * c, b * d)));
}

signed main()
{

    solve();

    return 0;
}


Measured memory_bytes: 3636
MAX_SUM = 4000
MAX_I = 1000
K = 4
 
$sn_cache = Array.new(K + 1) {[]}
 
def check_sum(k, n)
  unless $sn_cache[k][n]
    count = 0
    max_i = [MAX_I, n].min
 
    (0..max_i).each do |i|
      count += check_sum(k - 1, n - i)
    end
 
    $sn_cache[k][n] = count
  end
  
  $sn_cache[k][n]
end
 
$sn_cache[1] = Array.new(MAX_I + 1, 1) + Array.new(MAX_SUM - MAX_I, 0)
 
while (line = gets)
  n = line.chomp.to_i
  puts check_sum(K, n)
end


Measured memory_bytes: 7088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;

int H,W;
char a[105][105];

int main(){
 
cin>>H>>W;

for(int i=1; i<=H; i++) scanf("%s",&a[i]);

for(int i=0; i<=H+1; i++){
    printf("#"); 
    for(int j=0; j<W; j++){
        if(i==0||i==H+1){
            printf("#"); 
        }
        else printf("%c",a[i][j]); 
    }
    printf("#"); 
    printf("\n"); 
}


}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

P calc(int lhs,int rhs){
  int sum = lhs + rhs;
  int carry = 0;
  int cost = 0;
  for(int i = 0; i < 9; i++){
    cost += (lhs % 10) * (rhs % 10) + carry;
    carry = (lhs % 10 + rhs % 10 + carry >= 10 ? 1 : 0);
    lhs /= 10;
    rhs /= 10;
  }
  return P(sum,cost);
}

int main(){
  int N;
  while(~scanf("%d",&N)){
    vector<int> numbers;
    for(int i = 0; i < N; i++){
      int number;
      scanf("%d",&number);
      numbers.push_back(number);
    }
    P dp[301][301];
    for(int i = 0; i < numbers.size(); i++) {
      dp[i][i].first = numbers[i];
      dp[i][i].second = 0;
    }

    for(int d = 1; d < numbers.size(); d++){
      for(int i = 0; i < numbers.size() - d; i++){
        int j = i + d;
        dp[i][j].second = INF;
        for(int k = i; k < j; k++){
          P tmp = calc(dp[i][k].first,dp[k+1][j].first);
          dp[i][j].first = tmp.first;
          dp[i][j].second = min(dp[i][j].second,
                                tmp.second + dp[i][k].second + dp[k+1][j].second);
        }
      }
    }

    printf("%d\n",dp[0][numbers.size()-1].second);
  }
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    ll res = 0;
    cin >> n;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i != 0) continue;
        ll j = n / i - 1;
        ll k = i - 1;
        if (k != 0 && n / k == n % k) res += k;
        if (j != 0 && n / j == n % j) res += j;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuffer sb = new StringBuffer(s.substring((s.length() + 1) / 2));
        String r = sb.reverse().toString();
        int cnt = 0;
        for (int i = 0; i < r.length(); i++) {
            if (r.charAt(i) != s.charAt(i)) {
                cnt++;
            }
        }

        System.out.println(cnt);
        sc.close();
    }
}

Measured memory_bytes: 22996
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
tot = 0
c = 0
for i in range(N):
    a = A[i]
    b = B[i]
    if a>=c:
        a -= c
        tot += c
        if a>=b:
            tot += b
            c = 0
        else:
            tot += a
            c = b-a
    else:
        tot += a
        c = b
a = A[N]
tot += min(a,c)
print(tot)

Measured memory_bytes: 90684
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int64_t f(int64_t x){
  if(x==0){return 0;}
  if((x+1)%2!=0){if((x+1)/2%2!=0){return x^1;}
                 else{return 0^x;}
  }
  else{if((x+1)/2%2!=0){return 1;}
       else{return 0;}
  }
}

int main() {
  int64_t A,B;
  cin>>A>>B;
  int64_t a=f(B)^f(A-1);
  cout<<a<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
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; }

const long long INF = 1LL << 60;

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

    if(k<a)cout<<k<<endl;
    if(a<=k&&k<a+b)cout<<a<<endl;
    if(a+b<=k)cout<<a-(k-a-b)<<endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int main(int argc, char* argv[])
{
	char S[64];
	scanf("%s", S);
	S[3]++;
	printf("%s\n", S);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair <int,int> P;

ll N,K;

int main()
{
	cin >> N >> K;
	ll ans = 0;
	if(K == 0){
		cout << N*N << endl;
		return 0;
	}
	for(ll b=K+1;b<=N;b++){
		ll n = N/b;
		ll c = N%b;
		ans += max(0LL,(b-K)*n);
		ans += max(0LL,c-K+1);
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256