akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,n;
	cin>>h>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	cin>>a[i]>>b[i];
	int dp[h+1];
	dp[0]=0;
	for(int i=1;i<=h;i++)
	dp[i]=INT_MAX;
	for(int i=1;i<=h;i++)
	{
		for(int j=0;j<n;j++)
		{
			dp[i]=min(dp[i],dp[max(0,i-a[j])]+b[j]);
		}
	}
	cout<<dp[h];
}

Measured memory_bytes: 3672
#include<iostream>
#include<string>

using namespace std;

void go_plus(int& n, int& a, int& x){ x = (x+a>n ? n : x+a); }
void go_minus(int& a, int& x){ x = (x-a<1 ? 1 : x-a); }

int main(){
  int n, m, a;
  string str;
  while(cin >> n >> m && n && m){
    int x=1, y=1;
    char c = 'N';
    while(1){
      cin >> str;
      if(str == "STOP") break;
      if(str == "FORWARD"){
	cin >> a;
	if(c=='N') go_plus(m, a, y);
	else if(c=='S') go_minus(a, y);
	else if(c=='E') go_plus(n, a, x);
	else if(c=='W') go_minus(a, x);
      }else if(str == "BACKWARD"){
	cin >> a;
	if(c=='N') go_minus(a, y);
	else if(c=='S') go_plus(m, a, y);
	else if(c=='E') go_minus(a, x);
	else if(c=='W') go_plus(n, a, x);
      }else if(str == "RIGHT"){
	if(c=='N') c = 'E';
	else if(c=='S') c = 'W';
	else if(c=='E') c = 'S';
	else if(c=='W') c = 'N';
      }else if(str == "LEFT"){
	if(c=='N') c = 'W';
	else if(c=='S') c = 'E';
	else if(c=='E') c = 'N';
	else if(c=='W') c = 'S';
      }
    }
    cout << x << " " << y << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

int main(){
	int n;
	vector<pair<string,pii> > data;
	vector<pair<string,pii> > ans;
	while(scanf("%d",&n)){
		if(n==0)break;
		data.clear();
		ans.clear();
		string str;
		int w,s;
		int tmp2 =0;
		for(int i =0;i <n;i++){
			cin>>str;
			scanf("%d %d",&w,&s);
			data.push_back(mp(str,pii(w,s)));
			tmp2 +=data[i].second.first;
		}
		sort(data.begin(),data.end());
		double G =1145141;
		do{
			//cout <<"iei"<<endl;
			int sumw =0;
			int tmp1 =0;
			for(int i =n-1;i >=0;i--){
				tmp1 +=(i+1)*data[i].second.first;
			}
			double Gtmp =(double)((double)tmp1/(double)tmp2);
			if(Gtmp>G)continue;
			bool ok =true;
			for(int i =n-1;i >=0;i--){
				if(sumw>data[i].second.second){
					ok =false;
					break;
				}else{
					sumw +=data[i].second.first;
				}
			}
			//cout <<Gtmp<<endl;
			if(ok&&Gtmp <G){
				G =Gtmp;
				ans=data;
				//cout <<"ge"<<endl;
			}
		}while(next_permutation(data.begin(), data.end()));

		for(int i =0;i <n;i++){
			printf("%s\n",ans[i].first.c_str());
		}
	}
	return 0;
}

Measured memory_bytes: 1236
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long inf = 1ll << 62;

int s[100006];
bool isp[100006];
vector<int>prime;
map<int, int>spair,cnt;

int kake(int a, int b) {
	if (log10(a) + log10(b) > 12)return 0;
	return a*b;
}

void furui() {
	fill(isp, isp + 100001, true);
	isp[0] = isp[1] = false;
	for (int i = 2; i <= 100000; i++) {
		if (isp[i]) {
			for (int j = 2 * i; j <= 100000; j += i) {
				isp[j] = false;
			}
		prime.push_back(i);
		}
	}
}

signed main() {
	int n; cin >> n;
	furui();
	set<int>S;
	rep(X, n) {
		cin >> s[X];
		int ns = 1, nsd = 1;
		for (int i = 0; prime[i] < 2300; i++) {
			int x = prime[i] * prime[i] * prime[i];
			while (s[X] % x == 0)s[X] /= x;
		}
		ns = s[X];
		for (int i = 0; prime[i] < 2300; i++) {
			int x1 = prime[i], x2 = x1*x1;
			if (ns%x2 == 0) {
				ns /= x2; nsd =kake(nsd,x1);
			}
			else if (ns%x1 == 0) {
				ns /= x1; nsd =kake(nsd,x2);
			}
		}
		int sq = sqrt(ns);
		if (sq*sq == ns) {
			nsd =kake(nsd,sq);
		}
		else nsd =kake(nsd, kake(ns,ns));
		spair[s[X]] = nsd;
		spair[nsd] = s[X];
		cnt[s[X]]++;
		S.insert(s[X]);
	}
	int ans = 0;
	if (cnt[1])ans++;
	while (S.size()) {
		auto itr = S.begin();
		if (*itr == 1) {
			S.erase(1);
		}
		else {
			int x = *itr, y = spair[x];
			ans += max(cnt[x], cnt[y]);
			S.erase(x);
			S.erase(y);
		}
	}
	cout << ans << endl;
}

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

#define dbg(x) cerr << #x"=" << x << endl;


int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0); cin.tie(0);
	int a[4];
	for(int i = 0; i < 4; ++i) {
        cin >> a[i];
	}
	sort(a, a+4);
	int s[] = {1, 4, 7, 9};
	for(int i = 0; i < 4; ++i){
        if(s[i] != a[i]){
            cout << "NO" << endl;
            return 0;
        }
	}
	cout << "YES" << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  string s; cin >> s;
  ll k; cin >> k;
  // ll x, y, z; cin >> x >> y >> z;
  // vector<ll> a(n); REP(i, n) cin >> a[i];
  char ans;
  // bool ok = false;
  ll l;
  for(l = 0; s[l] == '1'; l++) {};
  if(k <= l) {
    ans = '1';
  } else {
    ans = s[l];
  }

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {

	int x, y, s;
	while(cin >> x >> y >> s, x, y, s){
		int ans = 0;
		REP(i, 1, s){
			int tmp1 = i;
			int tmp11 = i * (100 + x) / 100;
			if(tmp11 >= s) continue;
			int tmp2 = (s - tmp11 + 1) * 100 / (100 + x);
			if(((s - tmp11 + 1) * 100) % (100 + x) == 0) tmp2--;
			if(tmp2 <= 0) continue; 
			//cout << tmp1 << "\t" << tmp2 << "\t" << tmp1 * (100 + y) / 100 + tmp2 * (100 + y) / 100 << endl;
			if(tmp2 * (100 + x) / 100 + tmp11 != s) continue;
			ans = max(ans, tmp1 * (100 + y) / 100 + tmp2 * (100 + y) / 100);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3012
#include <stdio.h>
#define N 45

int main(){

  int fib[N],i,n;

  scanf("%d",&n);

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

    if(i == 0)fib[i] = 1;
    if(i == 1)fib[i] = 1;
    if(1 < i)fib[i] = fib[i - 2] + fib[i - 1];

    if(i == n)printf("%d\n",fib[i]);

  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int ans = 1;
    int i = 0;
    while(1)
    {
    	ans = i * i;
    	if(ans>N)
    	{
    		cout << (i-1)*(i-1) << endl;
    		return 0;
    	}
    	else if(ans==N)
    	{
    		cout << N << endl;
    		return 0;
    	}
    	i++;
    }
    
	return 0;
}

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


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

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (to_string(i).size() % 2 == 1) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll n , k ; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    for(int i=0;i<min(k,100ll);i++){
        vector<ll> b(n,0);
        for(ll i=0;i<n;i++){
            ll l = max(0ll,i-a[i]);
            ll r = i+a[i];
            b[l]++;
            if(r<=n-2) b[r+1]--;
        }
        for(int i=1;i<n;i++){
            b[i] += b[i-1];
        }
        a = b;
    }
    rep(i,n) cout << a.at(i) << " ";    
}

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

void outputV(vector<int>);
void outputV(vector<vector<int>>);

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  vector<int> dp(n+1,0);
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    int v1,v2;
    v1=dp[i-1]+abs(a[i]-a[i-1]);
    v2=dp[i-2]+abs(a[i]-a[i-2]);
    dp[i]=min(v1,v2);
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

void outputV(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) {
      cout << ' ';
    }
    cout << v[i];
  }
  cout << endl;
}

void outputV(vector<vector<int>> v) {
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v[i].size(); j++) {
      if (j) {
        cout << ' ';
      }
      cout << v[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=20+1,M=5e3+5,INF=1e9,mod=1000000007;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
int n,m,K,dir[N][N];
int f[2][22][(1<<20)+7];
#define pw(a) (1<<(a))
void ad(int&a,int b){a+=b;a%=mod;}
int lowbit(int a){return a&(-a);}
int main(){
	read(n,m,K);
	rep(i,0,max(n,m))rep(j,0,max(n,m))dir[i][j]=-1;
	rep(i,1,K){
		int x,y,z;read(x,y,z);
		dir[x][y]=z;
	}
	int now=1;
	f[now][0][0]=1;
	rep(i,1,m){
		clr(f[now^1]);
		re(j,0,n)re(k,0,pw(n-1))if(f[now][j][k]){
			if(j<n-1){
				if(dir[i][j+1]!=1)if(!(k&pw(j)))ad(f[now][j+1][k],f[now][j][k]);
				if(dir[i][j+1]!=0){
					if(k&pw(j))ad(f[now][j+1][k],f[now][j][k]);else
					ad(f[now][j+1][pw(j)|(k^(lowbit(k>>j)<<j))],f[now][j][k]);
				}
			}else ad(f[now^1][0][k],f[now][j][k]);
		}now^=1;
	}
	int res=0;re(k,0,pw(n-1))ad(res,f[now^1][n-1][k]);
	cout<<res<<endl;
}

Measured memory_bytes: 180480
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int[] x = new int[n];
    long[][] dp = new long[n][5001];
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextInt() - a;
    }
    dp[0][2500 + x[0]]++;
    dp[0][2500]++;
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < 5001; j++) {
        dp[i][j] += dp[i - 1][j];
        if((j >= x[i]) && ((j - x[i]) < 5001)) dp[i][j] += dp[i - 1][j - x[i]];
      }
    }
    System.out.println(dp[n - 1][2500] - 1);
  }
}


Measured memory_bytes: 38888
#include <stdio.h>

int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！

    char str[100];

    scanf("%s",str);

    if(str[2]==str[3] && str[4]==str[5]){
        puts("Yes");
    }else{
        puts("No");
    }
    
    return 0;
}

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

int main()
{
    int n,d;
    cin>>n>>d;
    long a,b;
    int result=0;
    double h;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        h=sqrt((a*a)+(b*b));
        // cout<<h<<endl;
        if(h<=d){
            result+=1;
        }
        
    }
    cout<<result;

    return 0;
}


Measured memory_bytes: 3672
import           Control.Applicative
import           Data.List

print' :: Int -> Int -> String -> String
print' a b xs = take (b - a + 1) $ drop a xs

reverse' :: Int -> Int -> String -> String
reverse' a b xs = l ++ m ++ r
  where
    l = take a xs
    m = reverse $ print' a b xs
    r = drop (b + 1) xs

replace' :: Int -> Int -> String -> String -> String
replace' a b ps xs = l ++ ps ++ r
  where
    l = take a xs
    r = drop (b + 1) xs

doCommands :: String -> [[String]] -> IO ()
doCommands _ [] = return ()
doCommands state ((x:ys):zss)
    | x == "print" = do
        let [a, b] = ys
        putStrLn $ print' (read a) (read b) state
        doCommands state zss
    | x == "reverse" = do
        let [a, b] = ys
        doCommands (reverse' (read a) (read b) state) zss
    | x == "replace" = do
        let [a, b, c] = ys
        doCommands (replace' (read a) (read b) c state) zss

main :: IO ()
main = do
    xs <- getLine
    getLine
    commands <- fmap words . lines <$> getContents
    doCommands xs commands



Measured memory_bytes: 5480
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;
vector<pair<int, double>>X[12000];
int N, M, a, b; double x[12000], y[12000], d[12000]; int g[12000];
int main() {
	cin >> N >> M; double S = 0;
	for (int i = 1; i <= N; i++)cin >> x[i] >> y[i];
	for (int i = 1; i <= M; i++) {
		cin >> a >> b;
		double c = pow((x[a] - x[b]), 2) + pow(y[a] - y[b], 2);
		c = sqrt(c); X[a].push_back(make_pair(b, c)); S += c;
		X[b].push_back(make_pair(a, c));
	}
	for (int t = 1; t <= N; t++) {
		if (g[t] >= 2)continue;
		d[t] = 0; g[t] = 1;
		while (true) {
			int OK = 1;
			for (int i = 1; i <= N; i++) {
				if (g[i] == 1)OK = 0;
			}
			if (OK == 1)break;
			double maxn = -1; int maxid = 0;
			for (int i = 1; i <= N; i++) {
				if (g[i] == 1 && maxn < d[i]) {
					maxn = d[i]; maxid = i;
				}
			}
			g[maxid] = 2;
			for (int i = 0; i < X[maxid].size(); i++) {
				int to = X[maxid][i].first; double dist = X[maxid][i].second;
				if (g[to] <= 1 && d[to] < dist) {
					d[to] = dist; g[to] = 1;
				}
			}
		}
	}
	double sum = 0;
	for (int i = 2; i <= N; i++) {
		sum += d[i];
	}
	printf("%.50f", S - sum);
	return 0;
}

Measured memory_bytes: 5020
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> f;
long long A, B, C, D;
long long go(long long n) {
	if (!n) return 0;
	if (n == 1) return D;
	if (f.find(n) != f.end()) return f[n];
	long long &res = f[n];
	res = 1ll << 60;
	res = min(res, llabs(n / 2 * 2 - n) * D + A + go(n / 2));
	res = min(res, llabs((n + 1) / 2 * 2 - n) * D + A + go((n + 1) / 2));
	res = min(res, llabs(n / 3 * 3 - n) * D + B + go(n / 3));
	res = min(res, llabs((n + 2) / 3 * 3 - n) * D + B + go((n + 2) / 3));
	res = min(res, llabs(n / 5 * 5 - n) * D + C + go(n / 5));
	res = min(res, llabs((n + 4) / 5 * 5 - n) * D + C + go((n + 4) / 5));
	if (n < res / D) res = n * D;
	return res;
}
int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		f.clear();
		long long n;
		scanf("%lld%lld%lld%lld%lld", &n, &A, &B, &C, &D);
		printf("%lld\n", go(n));
	}
	return 0;
}

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

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

template <typename T>
T ceilDiv(T a, T b) {
    return a > 0 && b > 0 ? (a + b - 1) / b : a / b;
}

template <typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template <int MaxN = 100000, long long mod = 1000000007LL>
class Modlib {
    long long _fact[MaxN + 1];

public:
    // ax + by = gcd(a, b)の解(x, y)を1つ求める.
    // 参考: https://qiita.com/drken/items/b97ff231e43bce50199a
    pair<long long, long long> exgcd(long long a, long long b) const {
        if (b == 0) {
            return {1, 0};
        } else {
            const auto &s = exgcd(b, a % b);
            return {s.second, s.first - a / b * s.second};
        }
    }

    // x^n
    long long pow(long long x, long long n) const {
        long long ret = 1LL;
        long long t = x % mod;
        while (n > 0) {
            if (n & 1LL) {
                ret *= t;
                ret %= mod;
            }
            t *= t;
            t %= mod;
            n >>= 1;
        }
        return ret;
    }
    // xの逆元
    long long inv(long long x) const {
        // x * s + mod * t = 1を満たす(s, t)のs
        return (exgcd(x, mod).first % mod + mod) % mod;
    }
    // n!
    long long fact(long long n) const {
        return _fact[n];
    }
    // nPk
    long long perm(long long n, long long k) const {
        return fact(n) * inv(fact(n - k)) % mod;
    }
    // nCk
    long long comb(long long n, long long k) const {
        return perm(n, k) * inv(fact(k)) % mod;
    }

    constexpr Modlib() : _fact{} {
        _fact[0] = _fact[1] = 1LL;
        for (int i = 2; i <= MaxN; ++i) {
            _fact[i] = _fact[i - 1] * i % mod;
        }
    }
};

constexpr ll mod = 998244353LL;
constexpr auto modlib = Modlib<300000, mod>();

int main() {
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    for (ll i = 0; i <= n; ++i) {
        ll j = k - a * i;
        if (j % b != 0)
            continue;
        j /= b;
        if (!(0 <= j && j <= n))
            continue;
        ans += modlib.comb(n, i) * modlib.comb(n, j) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<LLONG> as(N); for (auto &ai : as) cin >> ai;
	sort(as.begin(), as.end(), greater<LLONG>());
	// 各スポットで取得できる心地よさaとスポット数のマップ
	map<LLONG, int, greater<LLONG>> a2numMap{ {as.front(), 1} };
	LLONG ans = 0;
	for (int i = 1; i < N; ++i)
	{
		// 新しくaiを入れることでスポットが２箇所できる
		LLONG ai = as[i];
		a2numMap[ai] += 2;
		// スポットのうち最も心地よさが高くなるスポットを使う
		auto itr = a2numMap.begin();
		ans += itr->first;
		itr->second -= 1;
		// 最も心地よさが高いスポットが空になったらマップから削除
		if (itr->second == 0)
		{
			a2numMap.erase(itr);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a,b;
	cin >> a >> b;
	if(a>b){
		cout << ">" << endl;
	}else if(a<b){
		cout << "<" << endl;
	}else{
		cout << "=" << endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e10;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};


int main(){
    ll N; cin>>N;
    set<string> d;
    rep(i,N){
        string x; cin>>x;
        d.insert(x);
    }
    cout<<d.size()<<endl;
}

Measured memory_bytes: 19140
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lundi ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve(){
    int d, t, s;
    cin >> d>> t >> s;
    if(t*s < d){
        cout<<"No"<<endl;
    } else {
        cout<<"Yes\n";
    }
}

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

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

int main(){
  int N;
  cin >>N;
  vector<long int> a(N*3);
  for(int i=0;i<3*N;i++)
    cin >>a.at(i);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long int sum=0;
  for(int i=0;i<N*2;i++){
    if(i%2==1)
    sum+=a.at(i);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    map<int, int> num;

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

    int cnt = 0;
    for (const pair<const int, int>& item : num)
    {
        if (item.second % 2 == 1)
        {
            cnt++;
        }
        
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int n; cin >> n;
    ll ans = 0;
    rep(i,n+1){
        ans += i;
        if(ans>=n){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

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

int main() {
	long long Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	S = min({ 4 * Q,2 * H,S });
	if (2 * S < D) cout << N * S << endl;
	else cout << D * (N / 2) + S * (N % 2) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int a,b,c,d,n;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&n);
  b=MIN(a*2,b);
  c=MIN(b*2,c);
  d=MIN(c*2,d);
  printf("%lld\n",n/2LL*d+n%2*c);
  return 0;
}


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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool flag = true;
    while(a>0&&c>0)
    {
        if(flag)
        {
            c-=b;
            flag = false;
        }
        else
        {
            a-=d;
            flag = true;
        }
    }
    if(flag==false)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3520
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
using namespace std;
class Disjointset {
public:
	vector<int> p, ra;
	Disjointset() {};
	Disjointset(int i) {
		p.resize(i, 0);
		ra.resize(i, 0);
		for (int j = 0; j < i; j++) setp(j);
	}
	void setp(int i) { p[i] = i; }
	int findrep(int i) {
		if (i != p[i]) p[i] = findrep(p[i]);
		return p[i];
	}
	void merge(int a, int b) {
		int s = findrep(a);
		int t = findrep(b);
		if (ra[s] > ra[t]) p[t] = s;
		else if (ra[t] > ra[s]) p[s] = t;
		else { p[t] = s; ra[t]++; }
	}
	void same(int a, int b) {
		if (findrep(a) == findrep(b)) cout << 1 << endl;
		else cout << 0 << endl;
	}
};
int main() {
	int n, q, com;
	cin >> n >> q;
	Disjointset d(n);
	for (int i = 0; i < q; i++) {
		int a, b;
		cin >> com >> a >> b;
		if (com == 0) d.merge(a, b);
		if (com == 1) d.same(a, b);
	}
	return 0;
}

Measured memory_bytes: 3176
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1276
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
bool sieve[2000000];
int main(void)
{
    for (int i = 0; i < 2000000; ++i)
        sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for (int i = 2; i * i < 2000000; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; i * j < 2000000; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
    int n;
    while (cin >> n, n)
    {
        int cnt = 0;
        for (int i = n;; --i)
        {
            if (sieve[i])
                break;
            cnt++;
        }
        for (int i = n;; ++i)
        {
            if (sieve[i])
                break;
            cnt++;
        }
        if (sieve[n])
            cout << 0 << endl;
        else
            cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 5044
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T

main :: IO ()
main = do
  x <- unsafeTextToInt <$> T.getLine :: IO Int
  print $ 1 - x

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long t;
    t=1;
    // cin>>t;
    while(t--)
    {
        long n,i,j,x,y,flag=1,a,b,ans,count;
        string s;
        cin>>s;
        if(s[0]=='7' || s[1]=='7' || s[2]=='7')
        cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        
        
    }
    
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		double D=sc.nextDouble();
		double X[]=new double[N];
		double Y[]=new double[N];
		for(int i=0;i<N;i++) {
			X[i]=sc.nextDouble();
			Y[i]=sc.nextDouble();
		}
		sc.close();
		int count=0;
		double distance;
		for(int i=0;i<N;i++) {
			distance=Math.sqrt(X[i]*X[i]+Y[i]*Y[i]);
			if(distance<=D)
				count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 68960
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    ll n = 0, m = 0;
    cin >> n >> m;
    ll ans = 0;
    for (ll i=1; i<=sqrt(m); i++) {
        if (m%i == 0) {
            ll tmp = m/i;
            if (i >= n) {
                ans = max(ans, tmp);
            }
            else if (tmp >= n) {
                ans = max(ans, i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
 

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;
vector<long double> a, b;

int temp[8][8] = {0};
long double k[8][8];

//aとbの距離
long double dis(int x, int y)
{
    if (temp[x][y] == 0)
    {
        long double r2 = (a[x] - a[y]) * (a[x] - a[y]) + (b[x] - b[y]) * (b[x] - b[y]);
        k[x][y] = sqrt(r2);
        temp[x][y] = 1;
        return k[x][y];
    }
    else
    {
        return k[x][y];
    }
}

signed main()
{
    cin >> n;
    a.resize(n);
    b.resize(n);
    vector<int> v;
    rep(i, n)
    {
        cin >> a[i] >> b[i];
        v.pb(i);
    }

    long double s = 0;
    int roop = 1;
    rep(i, n)
    {
        roop *= (i + 1);
    }

    do
    {
        rep(i, n - 1)
        {
            s += dis(v[i], v[i + 1]);
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << fixed << setprecision(15) << (s / (long double)roop);
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
answer = []

for i in range(N):
    tmp_a, tmp_b = input().split(' ')
    tmp_array = [int(tmp_b), int(tmp_a)]
    answer.append(tmp_array)

answer.sort()

now_time = 0

for item in answer:
    now_time += item[1]
    if now_time > item[0]:
        print('No')
        break
else:
    print('Yes')




Measured memory_bytes: 35600
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0:
        break
    for h in range(H):
        for w in range(W):
            if h == 0 or w == 0 or h == H-1 or w == W-1:
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

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

int main() {
 
  char c;

  cin >> c;
  c += 1;
  cout << c << endl;

  return 0;
}

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

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (int i = 1;; i++) {
        if (i & 1) {
            c -= b;
            if (c <= 0) {
                cout << "Yes" << endl;
                return 0;
            }
        } else {
            a -= d;
            if (a <= 0) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3644
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0;i<100;i++){
        for(int j = 0;j<100;j++){
            if(4*i+7*j==n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3644
public class Main {

	public static void main(String[] args) {
		java.util.Scanner sc = new java.util.Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if (b - a == c - b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");

		}
	}
}


Measured memory_bytes: 23636
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        count=0
        while n % b == 0:
            n //= b
            count+=1
            if(count==1):
                fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

A,B=map(int,input().split())
g=gcd(A,B)
if(g==1):
    print("1")
else:
    print(len(factorize(g))+1)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
  int n;
  int pm, pe, pj;
  int i;

  while(1){
    scanf("%d", &n);

    if (n == 0){
      break;
    }

    for (i = 0;i < n;i++){
      scanf("%d %d %d", &pm, &pe, &pj);

      if (pm == 100 || pe == 100 || pj == 100){
        printf("A\n");
      }
      else if ((pm + pe) / 2 >= 90){
        printf("A\n");
      }
      else if ((pm + pe + pj) / 3 >= 80){
        printf("A\n");
      }
      else if ((pm + pe + pj) / 3 >= 70){
        printf("B\n");
      }
      else if ((pm + pe + pj) / 3 >= 50 && (pm >= 80 || pe >= 80)){
        printf("B\n");
      }
      else {
        printf("C\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

long DEVISOR = 1e9 + 7;
vector<long> factorial;

long pow(long x, long n) {
  long ret = 1;
  while (n) {
    if (n & 1) {
      ret = ret * x % DEVISOR;
    }
    n >>= 1;
    x = x * x % DEVISOR;
  }
  return ret;
}

long C(long n, long r) {
  // factorial(n) / factorial(n-r) / factorial(r)
  return factorial[n] * pow(factorial[n-r], DEVISOR-2) % DEVISOR * pow(factorial[r], DEVISOR-2) % DEVISOR;
}

int main () {
  long length, M;
  cin >> length >> M;
  long ans = 1;

  factorial.push_back(1);
  for (long i = 1; i <= 2 * 1e5; i++) {
    factorial.push_back(factorial[i-1] * i % DEVISOR);
  }

  unordered_map<long, long> map;
  for (long i = 2; i <= M; i++) {
    while (M % i == 0) {
      map[i]++;
      M /= i;
    }
  }

  for (auto it: map) {
    long tmp = C(length + it.second - 1, it.second);
    ans = (ans * tmp) % DEVISOR; 
  }

  cout << ans << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vb vector<bool>
#define vi vector<ll>
#define vs vector<string>
#define vvi vector<vi>
#define vii vector<pair<ll, ll>>
#define pii pair<ll, ll>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(a) (a).begin(), (a).end()
#define INF 1000*1000*1000
//#define mod (INF + 7)
#define mod1 (mod-1)
#define endl '\n'
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

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

    for(int i = 0; i <= n/4; i++)
    {
        int s = i*4;
        if((n-s)%7 == 0)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int n, k, x[110];

int f(int x, int y) {
	if (x - y < 0)return y - x;
	return x - y;
}

int main() {
	cin >> n >> k;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		ans += min(f(k, x[i]), x[i]) * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main() {
	int a, b;
	while (true) {
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			break;
		}
		if(a > b) {
			printf("%d %d\n", b, a);
		} else {
			printf("%d %d\n", a, b);
		}
	}
}


Measured memory_bytes: 2688
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int G[9];
int J[9];

const int sum = 19 * 9;

int dp[9][1<<9][sum];

int solve(int now, int rest, int gp){
  if(now == 9){
    if(gp + gp > sum) return 1;
    else return 0;
  }
  if(dp[now][rest][gp] != -1) return dp[now][rest][gp];
  if(gp + gp > sum){
    int r = 1;
    for(int i = 9-now; i>1; i--) r*=i;
    return dp[now][rest][gp] = r;
  }

  int ret = 0;
  REP(i,9) if(rest & (1 << i)){
    int g = G[i];
    int j = J[now];

    if(g > j) ret += solve(now+1, rest^(1<<i), gp + g + j);
    else      ret += solve(now+1, rest^(1<<i), gp);
  }

  return dp[now][rest][gp] = ret;
}

int main(){
  int n = getInt();
  const int fact = 2*3*4*5*6*7*8*9;
  while(n --> 0){
    REP(i,9) G[i] = getInt();
    REP(i,9) J[i] = getInt();
    memset(dp,-1,sizeof(dp));
    double ans = (double)solve(0,(1<<9)-1,0) / fact;
    printf("%.5f %.5f\n",ans,1.0-ans+1e-10);
  }
  return 0;
}

Measured memory_bytes: 3944
n = int(input())
a = list(map(int,input().split()))

if n == 1:
    print(1)
    exit()

cnt = 0
i = 0
while i < n-1:
    if a[i] < a[i+1]:
        while i < n-1:
            if a[i] > a[i+1]:
                cnt += 1
                i += 1
                break
            i += 1
    elif a[i] > a[i+1]:
        while i < n-1:
            if a[i] < a[i+1]:
                cnt += 1
                i += 1
                break
            i += 1
    else:
        i += 1
print(cnt+1)

Measured memory_bytes: 14436
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String args[]) throws IOException {
		@SuppressWarnings("resource")
		Scanner cin = new Scanner(System.in);
		ArrayList<String> inLines = new ArrayList<String>();
		for (; cin.hasNext();) {
			inLines.add(cin.nextLine());
		}
		Solver solver = new Solver();
		solver.solve(inLines);
	}
}

class Solver {

	public void solve(ArrayList<String> inLines) {
		String str = inLines.get(0);
		int posA;
		int posZ;
		for (posA = 0; str.charAt(posA) != 'A'; posA++) {
		}
		for (posZ = str.length() - 1; str.charAt(posZ) != 'Z'; posZ--) {
		}
		System.out.println((posZ - posA + 1));
	}
}


Measured memory_bytes: 15548
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 1073741824
#define ll long long
#define PI (2*acos(0.0))
using namespace std;
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> 
void dbg_out(Head H, Tail... T) { 
    cerr << ' ' << H;
     dbg_out(T...); 
}
#define dbg(...) cerr << '(' << #__VA_ARGS__ << ')'<<':', dbg_out(__VA_ARGS__)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define on(val,pos) val|(1<<pos)
#define off(val,pos) val&(~(1<<pos))
#define check(val,pos) (val&(1<<pos))
#define all(n) n.begin(),n.end()
//first four adjacent,second four corner
//int row[8]={0,-1,0,1,1,-1,-1,1};
//int col[8]={-1,0,1,0,-1,-1,1,1};
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main(){
    ll i,j,k,n,m,val,t=0,test;
    //freopen("000input.txt","r",stdin);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(max(a*c,a*d),max(b*c,b*d));
    //free();   //if pointer array
    return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)
#define mp make_pair
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define scfl(xx) scanf("%I64d",&xx)
#define All(a) a.begin(), a.end()


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, ll> ii;
typedef long double ld;





int main(){	
	fastIO;
	//write; read;
	int n, k;
	cin >> n >> k;
	map<int, int> m;
	while (n--){
		int x;
		cin >> x;
		m[x]++;
	}
	vi v;
	for (map<int, int>::iterator it = m.begin(); it != m.end(); ++it)
		v.push_back(it->second);
	sort(All(v));
	int res = 0;
	if (v.size() >= k){
		rep(i, v.size() - k)
			res += v[i];
		cout << res;
	}
	else {
		cout << 0;
	}
	return 0;
}


Measured memory_bytes: 10744
#include<bits/stdc++.h>
using namespace std;
long long tab[200005];
long long dp_suf[200005];
long long dp_pref[200005];
vector<pair<int,int>> v;
long long comp(long long a,long long b)
{
    long long out=0;
    if(a>b)
    {
        while(a>b)
        {
            b*=4;
            out--;
        }
    }
    else
    {
        while(a<=b)
        {
            a*=4;
            out++;
        }
        a/=4;
        out--;
    }
    return out;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int a;
    cin>>a;
    for(int x=1;x<=a;x++)
        cin>>tab[x];
    v.push_back(make_pair(a,1e9));
    for(int x=a-1;x>=1;x--)
    {
        long long pom=comp(tab[x],tab[x+1]),dodaj=0,last=x;
        if(pom>0)
            v.push_back(make_pair(x,pom));
        else if(pom<0)
        {
            pom*=(-1);
            while(1)
            {
                dodaj+=(v.back().first-last)*pom;
                if(pom<=v.back().second)
                {
                    v.back().second-=pom;
                    if(v.back().second==0)
                        v.pop_back();
                    break;
                }
                else
                {
                    pom-=v.back().second;
                    last=v.back().first;
                    v.pop_back();
                }
            }
        }
        dp_suf[x]=dp_suf[x+1]+dodaj;
    }
    v.resize(0);
    v.push_back(make_pair(1,1e9));
    for(int x=2;x<=a;x++)
    {
        long long pom=comp(tab[x],tab[x-1]),dodaj=0,last=x;
        if(pom>0)
            v.push_back(make_pair(x,pom));
        else if(pom<0)
        {
            pom*=(-1);
            while(1)
            {
                dodaj+=(last-v.back().first)*pom;
                if(pom<=v.back().second)
                {
                    v.back().second-=pom;
                    if(v.back().second==0)
                        v.pop_back();
                    break;
                }
                else
                {
                    pom-=v.back().second;
                    last=v.back().first;
                    v.pop_back();
                }
            }
        }
        dp_pref[x]=dp_pref[x-1]+dodaj;
    }
    long long wynik=1e18;
    for(int x=1;x<=a+1;x++)
        wynik=min(wynik,(dp_pref[x-1]+dp_suf[x])*2+x-1);
    cout<<wynik;
	return 0;
}


Measured memory_bytes: 4992
// 解説を読みました...
#include<iostream>
#include<cstring>
using namespace std;

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

int dp[30][30][901];

int main(){
    memset(dp, 0x3f, sizeof(dp));
    int h, w;
    cin >> h >> w;
    int mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }
    dp[0][0][0] = 0;
    for(int step = 0; step < h*w; step++){
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(dp[i][j][step] > 1e9)    continue;
                for(int k = 0; k < 4; k++){
                    int ni = i+di[k], nj = j+dj[k];
                    if(!inRange(ni,0,h)||!inRange(nj,0,w))  continue;
                    int nc = dp[i][j][step]+2*step*mat[ni][nj]+mat[ni][nj];
                    dp[ni][nj][step+1] = min(dp[ni][nj][step+1], nc);
                }
            }
        }
    }
    int ans = 1<<30;
    for(int i = 0; i < h*w; i++)    ans = min(ans, dp[h-1][w-1][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6284
# coding: utf-8

# In[1]:

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


# In[2]:

#import copy
#import numpy as np
try:
    from fractions import gcd
except:
    from math import gcd


# In[ ]:

# 左からn個の最大公約数を求める O(n)
# 右からn個の最大公約数を求める O(n)
# n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数


# In[3]:

lg = [1]*(N)
rg = [1]*(N)
ans = 0


# In[4]:

#print(lg)
#print(rg)
#print(A)


# In[5]:

lg[0] = A[1]
rg[0] = A[N-2]
lg[1] = A[0]
rg[1] = A[N-1]
#print(lg, rg)
for i in range(1, N-1):
    #print(i)
    lg[i+1] = gcd(lg[i], A[i])
    #print(lg[i], A[i])
    rg[i+1] = gcd(rg[i], A[N-1-i])
    #print(rg[N-1-i], A[N-1-i])
#print(lg, rg)

for i in range(N):
    #print(i, lg[i], rg[N-i-1])
    tmp = gcd(lg[i], rg[N-i-1])
    #print(tmp)
    if ans < tmp:
        ans = tmp
    #print(ans)


# In[6]:

print(ans)


# In[ ]:

"""
[42 54 69 92 12 23]のとき
 1 [54 69 92 12 23]の最大公約数
 2 [42 69 92 12 23]
 3 [42 54 92 12 23]
 4 [42 54 69 12 23]

"""



Measured memory_bytes: 14584
#include <bits/stdc++.h>
using namespace std;
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)
 
string s;
int main() {
    cin >> s;
    s = REPLACE(s, "P\\?", "PD");
    s = REPLACE(s, "\\?D", "PD");
    s = REPLACE(s, "\\?", "D");
    cout << s;
    return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a,b,x;
	cin>>a>>b>>x;
	if(a>x)cout<<"NO";
	else if(a+b>=x)cout<<"YES";
	else cout<<"NO";

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    S = input()
    if S == 'RRR':
        print(3)
    elif 'RR' in S:
        print(2)
    elif 'R' in S:
        print(1)
    else:
        print(0)

if __name__ == "__main__":
    main()


Measured memory_bytes: 65084
kn = list(map(int,input().split()))
A = list(map(int,input().split()))
K = kn[0]
N = kn[1]
x = []
for i in range(N - 1):
    x.append(A[i + 1] - A[i])
x.append(abs(K - A[N - 1] + A[0]))
print(sum(x) - max(x))

Measured memory_bytes: 26444