akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while (true) {
        int N,A,B,C,X; cin >>N>>A>>B>>C>>X;
        if(N+A+B+C+X==0) break;

        vector<int> rndint(N);
        rep(i, N) cin >> rndint[i];

        int ans = 0;
        int cur = X;
        rep(i, N){
            if (ans>10000) break;
            int x = rndint[i];
            while (cur!=x) {
                cur = (A*cur+B)%C;
                ans++;
                if (ans>10000) break;
            }
            if (i<N-1) {
                cur = (A*cur+B)%C;
                ans++;
            }
        }
        if (ans<=10000) cout << ans << endl;
        else cout << -1 << endl;
    }
}


Measured memory_bytes: 3084
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 5e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int A,B,C;

void work(){
    scanf("%d%d%d",&A,&B,&C);
    swap(A,B);
    swap(A,C);
    printf("%d %d %d\n",A,B,C);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}





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

string str;
ll x;
ll n;
ll A[100];
ll sum=0;

int main(){
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>A[i];
    sum+=A[i];
  }
  if( sum < x ){
    cout<<n-1<<endl;
  }else if(sum==x){
    cout<<n<<endl;
  }else{
    ll ans=0;
    sort(A,A+n);
    for(int i=0;i<n;i++){
      if(i)A[i]+=A[i-1];
      if(A[i]>x){
        ans=i;
        break;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

int main()
{
    char tap[128];

    int i=0;
    int len;
    int count=0;

    scanf("%s",tap);

    len=strlen(tap);
    
    for(i=0;i<len;i++)
    {
        if(count%2==0)
        {
            if(tap[i]=='L')
            {
                printf("No\n");
                return 0;
            }
        }

        else if(count%2==1)
        {
            if(tap[i]=='R')
            {
                printf("No\n");
                return 0;
            }
        }
       count++;
    }

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

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

int main(){
  int x,y;
  cin>>x>>y;
  int z;
  if((x-1)%(y-1)==0){
  z=(x-1)/(y-1);
  }
  else{
  z=(x-1)/(y-1)+1;
  }
  cout<<z<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
// #include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,k,n) for(ll i=k; i<(ll)(n); i++)
#define Q 1000000007


struct UnionFind {
    vector<ll> par; //par[a]=b: aの親がb

    UnionFind(ll N) : par(N) { //初めは全て根として初期化
        rep(i,0,N) par[i] = i;
    }

    ll root(ll x) { //xの属する根を求める
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return; //根が同じときはそのまま
        par[rx] = ry;
    }

    bool same(ll x, ll y) { //x,y の属する木が同じならtrue
        return root(x) == root(y);
    }
};


int main(){
    ll n,m; cin >> n >> m;
    UnionFind tree(n);
    vector<ll> p(n);
    rep(i,0,n) {
        cin >> p[i];
        --p[i];
    }
    vector<ll> x(m),y(m);
    rep(i,0,m) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
        tree.unite(x[i],y[i]);
    }

    ll ans = 0;
    rep(i,0,n) {
        if(tree.same(i,p[i])) {
            // cout << i << "," << p[i] << endl;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6424
# include <iostream>
# include <cstdio>
# include <cstring>

using namespace std;

char a[200010];
char b[200010];

int main() {
	scanf("%s", a);
	int n = strlen(a);
	int m = 0;
	for(int i = 0; i < n; ++i) {
		if(m && b[m-1] == 'S' && a[i] == 'T') --m;
		else b[m++] = a[i];
	}
	printf("%d\n", m);
	return 0;
}


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

using namespace std;

int main(void)
{
    int a, b, x; cin >> a >> b >> x;

    if(a > x)
        cout << "NO\n";
    else if((a + b) < x)
        cout << "NO\n";
    else if(a == x)
        cout << "YES\n";
    else if((a + b) >= x)
        cout << "YES\n";
    


    return 0;
}

Measured memory_bytes: 256
import sys

a = [[0] * 3] * 3
for i in range(0, 3, 1):
	a[i] = list(map(int, input().split()))
N = int(input())

for i in range(0, N, 1):
	b = int(input())
	for j in range(0, 3, 1):
		for k in range(0, 3, 1):
			if b == a[j][k]:
				a[j][k] = 0

for i in range(0, 3, 1):
	if a[i][0] == a[i][1] and a[i][1] == a[i][2]:
		print("Yes")
		sys.exit(0)
	elif a[0][i] == a[1][i] and a[1][i] == a[2][i]:
		print("Yes")
		sys.exit(0)

if a[0][0] == a[1][1] and a[1][1] == a[2][2]:
	print("Yes")
	sys.exit(0)
elif a[0][2] == a[1][1] and a[1][1] == a[2][0]:
	print("Yes")
	sys.exit(0)

print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
void *wmem;
inline void rd(long long &x){
  int k, 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(long long x){
  char f[20];
  int m=0, s=0;
  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');
  }
}
template<class T> int Factor_L(T N, T fac[], int fs[]){
  T i;
  int sz=0;
  if(N%2==0){
    fac[sz] = 2;
    fs[sz] = 1;
    N /= 2;
    while(N%2==0){
      N /= 2;
      fs[sz]++;
    }
    sz++;
  }
  for(i=3;i*i<=N;i+=2){
    if(N%i==0){
      fac[sz] = i;
      fs[sz] = 1;
      N /= i;
      while(N%i==0){
        N /= i;
        fs[sz]++;
      }
      sz++;
    }
  }
  if(N > 1){
    fac[sz] = N;
    fs[sz] = 1;
    sz++;
  }
  return sz;
}
template<class T> int Divisor_L(T N, T res[], void *mem = wmem){
  T *fc;
  int *fs, fsz, i, j, k, s, sz=0;
  fc = (T*)wmem;
  fs = (int*)(fc+100);
  fsz =Factor_L(N, fc, fs);
  res[sz++] = 1;
  for(i=0;i<fsz;i++){
    s = sz;
    k = s * fs[i];
    for(j=0;j<k;j++){
      res[sz++] = res[j] * fc[i];
    }
  }
  sort(res, res+sz);
  return sz;
}
char memarr[96000000];
long long S;
long long X1;
long long Y1;
long long X2;
long long Y2;
long long X3;
long long Y3;
long long y[100000];
int ys;
int main(){
  long long i, k;
  wmem = memarr;
  rd(S);
  k = sqrt(S);
  while(k*k<S){
    k++;
  }
  X2 = Y3 = k;
  for(;;){
    i = X2 * Y3 - S;
    if(i <= 1000000000){
      X3 = i;
      Y2 = 1;
      break;
    }
    ys =Divisor_L(i, y);
    for(k=0;k<ys;k++){
      if(y[k] <= 1000000000 && i/y[k] <= 1000000000){
        break;
      }
    }
    if(k < ys){
      X3 = y[k];
      Y2 = i / y[k];
      break;
    }
    if(X2 <= Y3){
      X2++;
    }
    else{
      Y3++;
    }
  }
  wt_L(X1);
  wt_L(' ');
  wt_L(Y1);
  wt_L(' ');
  wt_L(X2);
  wt_L(' ');
  wt_L(Y2);
  wt_L(' ');
  wt_L(X3);
  wt_L(' ');
  wt_L(Y3);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// ll S;
// ll X1, Y1, X2, Y2, X3, Y3;
// 
// ll y[100000]; int ys;
// 
// {
//   ll i, k;
//   rd(S);
// 
//   k = sqrt(S);
//   while(k*k<S) k++;
//   X2 = Y3 = k;
// 
//   for(;;){
//     i = X2 * Y3 - S;
//     if(i <= 1d9){
//       X3 = i;
//       Y2 = 1;
//       break;
//     }
//     ys = Divisor(i, y);
//     rep(k,ys) if(y[k] <= 1d9 && i/y[k] <= 1d9) break;
//     if(k < ys){
//       X3 = y[k];
//       Y2 = i / y[k];
//       break;
//     }
// 
//     if[X2 <= Y3, X2, Y3]++;
//   }
// 
//   wt(X1,Y1,X2,Y2,X3,Y3);
// }


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

void printv(vector<ll> v) {
  for (ll i : v)
    cout << i << endl;
}

int main() {
	int n;
	cin>>n;
	int ch=n%10;
	string ans;
	if (ch==3)ans="bon";
	else if((ch==0)||(ch==1)||(ch==6)||(ch==8)) ans="pon";
	else ans="hon";
	cout<<ans<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int main(){

  int n,W;
  cin >> n >> W;

  //n個の価値と重さ
  int v[n],w[n];

  //入力
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }

  int dp[W+1]={};
  //d[i][w]は最初のi個の中から重さw以下となるように選んだ際の最大

  for(int i=0;i<=W;i++){
    for(int j=0;j<n;j++){
      if(i-w[j]>=0)dp[i]=max(dp[i],dp[i-w[j]]+v[j]);
    }
  }


  cout << dp[W] << endl;

}


Measured memory_bytes: 3136
from heapq import heappush, heappop
from math import sqrt
xs, ys, xt, yt = map(int, raw_input().split())
n = input()
ps = [map(int, raw_input().split()) for i in xrange(n)]
cant = [0]*n
for i in xrange(n):
    x0, y0, r0 = ps[i]
    for j in xrange(n):
        x1, y1, r1 = ps[j]
        if i == j or r0 > r1: continue
        if (x0 - x1)**2 + (y0 - y1)**2 <= (r1 - r0)**2:
            cant[i] = 1
            break

EPS = 1e-10
que = []
dist = [10**18+7]*n
def calc(x0, y0, r0, x1, y1, r1):
    v = (x0 - x1)**2 + (y0 - y1)**2
    if v <= (r0+r1)**2:
        return 0.
    return sqrt(v) - r0 - r1
for i in xrange(n):
    if cant[i]: continue
    x, y, r = ps[i]
    d = dist[i] = calc(xs, ys, 0, x, y, r)
    heappush(que, (d, i))
while que:
    d, v = heappop(que)
    if dist[v] < d:
        continue
    x0, y0, r0 = ps[v]
    for t in xrange(n):
        if v == t or cant[t]: continue
        x1, y1, r1 = ps[t]
        nd = calc(x0, y0, r0, x1, y1, r1)
        if d+nd < dist[t]:
            dist[t] = d+nd
            heappush(que, (d+nd, t))
ans = sqrt((xs - xt)**2 + (ys - yt)**2)
for i in xrange(n):
    if cant[i]: continue
    x, y, r = ps[i]
    d = calc(xt, yt, 0, x, y, r) + dist[i]
    ans = min(ans, d)
print "%.010f" % ans


Measured memory_bytes: 76444
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int size=Integer.parseInt(s.next());
		int[] heights=new int[size];
		for(int i=0;i<size;i++)
		{
			heights[i]=(s.nextInt());
		}
        int[] dp=new int[heights.length];
  dp[0]=0;dp[1]=Math.abs(heights[1]-heights[0]);
  for(int i=2;i<heights.length;i++)
  {
    dp[i]=Math.min(dp[i-1]+Math.abs(heights[i]-heights[i-1]),
                   dp[i-2]+Math.abs(heights[i]-heights[i-2]));
  }
   int ans=dp[dp.length-1];
		System.out.println(ans);
		s.close();
	}
}


Measured memory_bytes: 51188
#include<bits/stdc++.h>
using namespace std;
int print(int x){
	cout<<x<<"\n";
}
int main(){
         string str;
		 cin>>str;
		 int i=0,j=str.size()-1,ans=0;
		 while(i<j){
		 	if(str[i]==str[j]){
		 		i++;j--;
		 		continue;
		 	}
		 	if(str[i]!='x'&&str[j]!='x')
		 		return print(-1);
		 	if(str[i]=='x')
		 		i++;
		 	if(str[j]=='x')
		 		j--;
		 	ans++;
		 }
		print(ans);	
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, i, j, ans;
    cin>>n>>m;
    int r, c;
    cin>>r>>c;
    ans = n*m;
    ans -= r*m;
    ans -= (n-r)*c;
    cout<<ans; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
map<string,int> mp;
int N,M;
string a,b;

cin>>N;
for(int i=0;i<N;++i){
  cin>>a;
  auto itr=mp.find(a);
  if(itr!=mp.end()){
    mp[a]+=1;
  }
  else{
    mp[a]=1;
  }
}

cin>>M;
for(int i=0;i<M;++i){
  cin>>b;
  auto itr=mp.find(b);
  if(itr!=mp.end()){
    mp[b]-=1;
  }
  else{
    mp[b]=(-1);
  }
}
int ans=0;
for(auto itrn = mp.begin(); itrn != mp.end(); ++itrn) {
        if(ans<(itrn->second)){
          ans=(itrn->second);
        }
    }
cout<<ans<<"\n";
return 0;
}

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

using namespace std;

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

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define ff first
#define ss second

ll rec(ll A, ll B){
    if (A == B) {
        return A;
    }
    if (A == 0 || B == 0) return 0;
    ll res = 0;
    if (A < B){
        ll k = B / A;
        res += (2LL * k - 1) * A;
        ll C = B % A;
        if (C) res += A;
        res += rec(C, A);
    } else {
        ll k = A / B;
        res += (2LL * k - 1) * B;
        ll C = A % B;
        if (C) res += B;
        res += rec(C, B);
    }
    return res;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    ll n, x;
    cin >> n >> x;

    ll res = n;
    res += rec(x, n - x);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long N;
    long res;
    long divisor;
    long m;

    cin >> N;

    res = 0;
    divisor = 5;

    if (N % 2 == 1) {
        res = 0;
    } else {
        m = N / 2;
        while (m >= divisor) {
            res += m / divisor;
            divisor *= 5;
        }    
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import itertools as it
class mybool:
    def __init__(self, value):
        self.value = value
    def __neg__(self):
        return mybool(2-self.value)
    def __mul__(self, other):
        return mybool(min(self.value,other.value))
    def __add__(self, other):
        return mybool(max(self.value,other.value))

while 1:
    s = raw_input()
    if s == ".": break

    for i in xrange(3):
        s = s.replace(str(i),"mybool(%d)"%i)
    
    ans = 0
    for p,q,r in it.product([0,1,2],repeat=3):
        P,Q,R = mybool(p),mybool(q),mybool(r)
        if eval(s).value == 2:
            ans += 1
    
    print ans
    

Measured memory_bytes: 4396
#include "bits/stdc++.h"

using namespace std;



int main() {
	int K,A,B;
	cin >> K >> A >> B; 
	int C;
	if (0 == A % K) {
		C = A;
	}
	else {
		C = (A / K + 1) * K;
	}

	if (B >= C) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 3548
N = gets.chomp.to_i
ans = { "AC" => 0, "WA" => 0, "TLE" => 0, "RE" => 0 }
1.upto(N) do
  ans[gets.chomp] += 1
end
ans.each do |k,v|
  puts "#{k} x #{v}"
end


Measured memory_bytes: 14380
import Data.Functor( (<$>))

main = do
    ls <- (takeWhile ("0 0"/=)) . lines <$> getContents
    let
	hws = (read <$>) . words <$> ls
	printRect [h,w] = putStrLn `mapM_` rect >> putStrLn ""
	  where
	    l1 = take w $ cycle "#."
	    l2 = take w $ cycle ".#"
	    rect = take h $ cycle [l1,l2]

    printRect `mapM_` hws




Measured memory_bytes: 4032
import math

A, B = [int(i) for i in input().split()]

ans = []

true_A_max = A + 0.999
true_B_max = B + 0.999

X_A = math.floor(A / 0.08)
X_max_A = math.ceil(true_A_max /0.08)
X_B = math.floor(B / 0.1)
X_max_B = math.ceil(true_B_max /0.08)

if X_max_A - X_A >= X_max_B - X_B:
    X_min = X_B
    X_max = X_max_B

else:
    X_min = X_A
    X_max = X_max_A

for X in range(X_min, X_max):
    cal_A = math.floor(X * 0.08)
    cal_B = math.floor(X * 0.1)
    
    if cal_A == A and cal_B == B:
        ans.append(X)
            
if len(ans) > 0:
    print(min(ans))
else:
    print(-1)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#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(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(20) << x << endl
const int MOD = 1e9 + 7;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 1e-8;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

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

  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> tmp;
  rep(i, s.size()) {
    for(int j = i; j <= min((int)s.size() - 1, i + k); ++j) {
      tmp.insert(s.substr(i, j - i + 1));
    }
  }
  auto t = tmp.begin();
  advance(t, k - 1);
  out(*t);

  return 0;
}


Measured memory_bytes: 5180
import bisect
q=int(input())

def sieve(n):
      is_prime = [True for _ in range(n)]
      is_prime[0] = False
  
      for i in range(2, int((n**0.5)//1+2)):
          if is_prime[i-1]:
              j = 2 * i
              while j <= n:
                  is_prime[j-1] = False
                  j += i           
      table = [ i for i in range(1, n+1) if is_prime[i-1] and is_prime[i//2]]
      return table[1:]

x=sieve(10**5+1)
ans=[]

for _ in range(q):
  l,r=map(int,input().split())
  ans.append(bisect.bisect_right(x,r)-bisect.bisect_left(x,l))

print(*ans,sep="\n")

Measured memory_bytes: 14696
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, M_a: int, M_b: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    c_max = 100
    a_max = 10
    total_max = (N+1) * a_max

    t = np.full((N+1, total_max + 1, total_max + 1), c_max * N, dtype=int)
    t[0][0][0] = 0

    for i in range(N):
        t[i+1] = t[i]
        buy = t[i, :-a[i], :-b[i]] + c[i]
        not_buy = t[i, a[i]:, b[i]:]
        cheaper = buy < not_buy
        t[i+1, a[i]:, b[i]:] = np.where(cheaper, buy, not_buy)
    
    t_a, t_b = M_a, M_b
    cheapest = total_max + 1
    while t_a <= total_max and t_b <= total_max:
        total = t[N][t_a][t_b]
        if total < cheapest:
            cheapest = total
        t_a += M_a
        t_b += M_b
    
    if cheapest == total_max + 1:
        print(-1)
    else:
        print(cheapest)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M_a = int(next(tokens))  # type: int
    M_b = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    c = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M_a, M_b, a, b, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 73496
#include<stdio.h>

int main(){
	int A,B,C,D,time=0;
	
	scanf("%d %d %d %d",&A,&B,&C,&D);
	
	if(A>=D||B<=C)
		time=0;
	else if(C>=A&&B>=D)
		time=D-C;
	else if(A>=C&&D>=B)
		time=B-A;
	else if(A>=C&&B>=D)
		time=D-A;
	else if(C>=A&&D>=B)
		time=B-C;
	else
		time=0;
	
	printf("%d",time);
	
	return 0;
}

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

int main() {
  int A,B,T;
  cin >> A >> B >> T;
  
  int count=0;
  int j=1;
  for(int i=0; i<T+0.5;i++) {
    if(i==A*j) {
      count+=B;
      ++j;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,a,b,c,k;
     cin>>a>>b>>c>>k;
     if(abs(a-b)>10e18)
        cout<<"Unfair"<<endl;
     else if(k%2==0)
        cout<<a-b<<endl;
     else
        cout<<b-a<<endl;
}


Measured memory_bytes: 256
d=input().split()
d=list(map(int,d))
a=d[0]
b=d[1]
c=d[2]
if a+b<=c+a and a+b<=b+c:
    print(a+b)
elif c+b<=c+a and c+b<=b+a:
    print(c+b)
elif a+c<=b+a and a+c<=b+c:
    print(a+c)


Measured memory_bytes: 3060
def nA(n, k):
    minimum = n*(n-1)//2
    maximum = n*k - minimum
    res = maximum-minimum+1

    return n*k - n*(n-1) + 1
    
    


NK = input().split()
N = int(NK[0])
K = int(NK[1])


res = 0
for i in range(K, N+2):
    res += nA(i, N)

res = res % 1000000007

print(res)



Measured memory_bytes: 63916
#include <bits/stdc++.h>
#define N 10000005
#define LL long long 
using namespace std;
LL int n,m,ar[N],t,x,br[N];
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>n;
	LL int a,b,t,k;
	for(int i=1;i<=n;i++)
		cin>>ar[i],cin>>br[i];
	for(int i=n;i>=1;i--)
	{
		//~ cin>>a>>b;
		ar[i]+=x;
		t=ar[i]/br[i];
		if(ar[i]%br[i])
			t++;
		k=br[i]*t;
		x+=k-ar[i];	
		//~ printf("\n%d %d %d %d\n",i,k,a,x);
	}
	cout<<x;
}


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

int n;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	int ans = 0;
	while(n > 1){
		n = (n+2)/3;
		++ans;
	}
	cout << ans << "\n";
	// 2 3 4 5 6 7 8
	// 1 1 2 2 2 2 
}


Measured memory_bytes: 3108
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <deque>

#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;



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

	int ans = 0;
	for (int a = 1; a + 2 <= 9; a++) {
		for (int b = 1; a + b + 1 <= 9; b++) {
			for (int c = 1; a + b + c <= 9; c++) {
				vector<int> ary;
				ary.reserve(a + b + c);
				for (int i = 0; i < a; i++) ary.push_back(3);
				for (int i = 0; i < b; i++) ary.push_back(5);
				for (int i = 0; i < c; i++) ary.push_back(7);
				do {
					int value = 0;
					int t = 1;
					for (int i = ary.size() - 1; i >= 0; i--) {
						value += ary[i] * t;
						t *= 10;
					}
					if(value <= N) ans++;
				} while (next_permutation(ary.begin(), ary.end()));
			}
		}
	}

	cout << ans NL;

	return 0;
}

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

int n,t,k;long long sol[1000000+100];
bool o[1000000+100];
vector< pair<int,int > >v[1000000+100];
int dfs(int n)
{
    o[n]=true;
    for (int i=0;i<v[n].size();i++){
        int y=v[n][i].first;
        if (!o[y]) sol[y]=sol[n]+v[n][i].second,dfs(y);
    }
return 0;
}
int main()
{
    cin>>n;
    for (int i=1;i<n;i++){
        int x,y,val;
        scanf("%d %d",&x,&y);
        scanf("%d",&val);
        v[x].push_back(make_pair(y,val));
        v[y].push_back(make_pair(x,val));
    }
    cin>>t>>k;

dfs(k);

    while(t--){
        int x,y;
        scanf("%d %d",&x,&y);
        printf("%lld\n",sol[x]+sol[y]);
    }


return 0;
}


Measured memory_bytes: 36224
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s,t,a;
    cin>>s>>t>>a;
    cout<<(char)toupper(s[0])<<(char)toupper(t[0])<<(char)toupper(a[0]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#include<algorithm>
#define INF 1111111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;
vector<int> vec(100100);
vector<int> passed(100100);
vector<int> dx = {-1,1};

int main() {
    int n;
    cin >> n;
  int tmp = n;
  int keta = 1;
  while(tmp/10 >= 1){
    tmp/=10;
    keta++;
  }
  if(keta == 1)
    cout << n << endl;
  else if(keta == 2)
    cout << 9 << endl;
  else if(keta == 3)
    cout << 9+n-99 << endl;
  else if(keta == 4)
    cout << 909 << endl;
  else if(keta == 5)
    cout << 909 + n -9999 << endl;
  else if(keta == 6)
    cout << 90909 << endl;
  else if(keta == 7)
    cout << 90910 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long 
using namespace std;
LL n,m;
int main(){
    scanf("%lld %lld",&n,&m);
    LL ans=1LL*(1900LL*m+100LL*(n-m)); 
    for (int i=1;i<=m;i++) ans*=2;
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
import math
n, k = map(int, input().split())
A = list(map(int, input().split()))
for i in range(n):
    if A[i] == 1:
        break
ans = 10e9
left = len(A[:i])
right = len(A[i+1:])
for j in range(k):
    left_c = math.ceil((left-(k-1-j)) / (k-1))
    right_c = math.ceil((right-j) / (k-1))
    ans = min(ans, left_c+right_c)
print(ans+1)


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

//#define DEBUG

using namespace std;
constexpr uint32_t INF = 1e9 + 1;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N, M;
    uint64_t K;
    cin >> N >> M >> K;
    std::vector<uint64_t> A, B;
    A.reserve(N+1);
    B.reserve(M+1);
    A.push_back(0);
    B.push_back(0);
    uint64_t last_element = 0;
    for(uint32_t i = 0 ; i < N ; i++){
        uint64_t a;
        cin >> a;
        last_element = last_element + a;
        A.push_back(last_element);
    }
    last_element = 0;
    for(uint32_t i = 0 ; i < M ; i++){
        uint64_t b;
        cin >> b;
        last_element = last_element + b;
        B.push_back(last_element);
    }

    uint32_t count_book_best = 0;

    for(uint32_t i = 0 ; i < A.size() ; i++){
        if( A[i] <= K){
            //cout << "read " << i << " from A" << endl;
            uint64_t remaining_time = K - A[i];
            //cout << "remaining time " << remaining_time << endl;
            auto b_itr = std::upper_bound(B.begin(), B.end(), remaining_time);
            auto book_number = std::distance(B.begin(), b_itr) - 1;
            // cout << "read " << book_number << " from B" << endl;
            // cout << *(b_itr) << endl;
            uint32_t read_book = i + book_number;
            if( read_book >= count_book_best){
                count_book_best = read_book;
            }
        }else{
            cout << count_book_best << endl;
            return ;
        }
    }
    cout << count_book_best << endl;

}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 4;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 6360
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<list>
#include <vector>
using namespace std;



int main(){
  std::list <long long> list;
  int n;
  long long p;
  string str;
  std::list<long long>::iterator itr,l;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str;
    if(str=="insert") {cin>>p; list.push_front(p);}
    else if(str=="deleteFirst") list.pop_front();
    else if(str=="deleteLast") list.pop_back();
    else{
      cin >>p; 
      for(itr=list.begin(),l=list.end();itr!=l;++itr){
        if(*itr==p){ list.erase(itr);
        break;}
      }
    }
  }
  for(itr=list.begin(),l=--list.end();itr!=l;++itr) cout << *itr << " ";
  cout << *itr << endl;
  return 0;
}





Measured memory_bytes: 34460
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

ll rep_power_modM(ll a, ll n, ll M){
    if(n == 0)return 1;
    if(n%2 == 0){ll tmp = rep_power_modM(a,n/2,M); return tmp*tmp%M;}
    return a*rep_power_modM(a,n-1,M)%M;
}

int main(){
	int m,n;
	cin>>m>>n;
	cout<<rep_power_modM(m,n,MOD)<<endl;
	return 0;
}


Measured memory_bytes: 3120
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll mpow(ll a,ll b){
	if(b==0)return 1;
	ll ans =mpow(a,b/2);
	ans*=ans;
	ans%=mod;
	if(b&1)return (ans*a)%mod;
	return ans;

}

ll fac[300000+5];
ll ifac[300000+5];
ll n,a,b,k;

ll ncr(ll n,ll r){
	if(r>n)return 0;
	if(r<0)return 0;
return (((fac[n]*ifac[r])%mod)*ifac[n-r])%mod;
}

ll ans(ll x){
	if(k-a*x>=0&&(k-a*x)%b==0)return (ncr(n,x)*ncr(n,(k-a*x)/b))%mod;
	return 0;
}


main() {
	//freopen("input","r",stdin);
	
	cin>>n>>a>>b>>k;
	 fac[0]=1;
	for(int i=1;i<=n;i++){fac[i]=fac[i-1]*i;fac[i]%=mod;}
		ifac[n]=mpow(fac[n],mod-2);
	for(int i=n-1;i>=0;i--){ifac[i]=ifac[i+1]*(i+1);ifac[i]%=mod;}

     ll ans1 = 0;

	for(int i=0;i<=n;i++){ans1+=ans(i);ans1%=mod;}
		cout<<(ans1+mod)%mod<<endl;
 
	
}

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

using namespace std;

using ll = long long;

int const maxn = 16;

int a[maxn][maxn];
ll dp[1<<maxn];
ll c[1<<maxn];

inline int ctz(int x) {
    return __builtin_ctz(x);
}

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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i < (1<<n); i++) {
        int j = ctz(i);
        ll ns = c[i^(1<<j)];
        for (int k = i^(1<<j); k > 0; k -= k&-k) {
            int bit = ctz(k);
            ns += a[j][bit];
        }
        c[i] = ns;
    }

    for (int i = 1; i < (1<<n); i++) {
        for (int j = i; j > 0; j = i&(j-1)) {
            dp[i] = max(dp[i], c[j] + dp[i^j]);
        }
    }

    cout << dp[(1<<n)-1] << "\n";
}

Measured memory_bytes: 1280
def main():
    N = int(input())
    MAX = 18
    ans = 0
    if(N % 2 == 1):
        ans = 0
    else:
        tmp = N//10
        ans += tmp
        while(tmp!=0):
            tmp = tmp//5
            ans += tmp
    print(ans)
 

if __name__ == "__main__":
    main()




Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int x;
    cin>>x;
    if(x!=3 && x!=5 && x!=7) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
x = []
y = []
while True:
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)
    if a == 0 and b == 0:
        break
for i in range((len(x) - 1)):
  if x[i] < y[i]:
    print("{} {}".format(x[i], y[i]))
  else:
    print("{} {}".format(y[i], x[i]))


Measured memory_bytes: 5908
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 105, M = 105;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, m, f[N][M];
char str[N][M];

int main () {
	read(n), read(m);
	for (int i = 0; i < n; i++) scanf("%s", str[i]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!i && !j) f[i][j] = str[i][j] == '#' ? 1 : 0;
			else {
				int x;
				f[i][j] = N + M;
				if (i) {
					x = (str[i][j] == '#' && str[i - 1][j] == '.');
					f[i][j] = min(f[i][j], f[i - 1][j] + x);
				}
				if (j) {
					x = (str[i][j] == '#' && str[i][j - 1] == '.');
					f[i][j] = min(f[i][j], f[i][j - 1] + x);
				}
			}
		}
	}
	write(f[n - 1][m - 1]), putchar('\n');
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {

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

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			int[] carr = new int[n];
			for (int i = 0; i < n; ++i) {
				carr[i] = sc.scanChar() - '0';
			}
			int[] f = new int[n];
			int[] s = new int[n];
			int[] t = new int[n];
			int[] d = new int[10];
			for (int i = 0; i < n; ++i) {
				int curr = carr[i];
				if (d[curr] == 0) {
					f[i] = (i > 0 ? f[i - 1] + 1 : 1);
					d[curr] = 1;
				} else
					f[i] = f[i - 1];
			}
			Arrays.fill(d, 0);
			for (int i = 1; i < n; ++i) {
				s[i] = s[i - 1] + f[i - 1];
				s[i] -= d[carr[i]];
				d[carr[i]] = f[i-1];
			}
			Arrays.fill(d, 0);
			for (int i = 2; i < n; ++i) {
				t[i] = t[i - 1] + s[i - 1];
				t[i] -= d[carr[i]];
				d[carr[i]] = s[i-1];
			}
			System.out.println(t[n - 1]);
		}
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


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

// const double PI = acos(-1.0); 

void solve();

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout); 
    #endif
    
    fastio(); 

    // int t; 
    // cin >> t;

    // while (t--) 
    solve(); 

    return 0;
}

void solve()
{
    int X, N;
    cin >> X >> N;
    set <int> sequence;
    for (int i = 0; i < N; ++i)
    {
        int input;
        cin >> input;
        sequence.insert(input);
    }

    int i = 0, ans;
    bool ansFound = false;
    while (not ansFound)
    {
        if (sequence.find(X - i) == sequence.end())
        {
            ansFound = true;
            ans = X - i;
            break;
        }
        else if (sequence.find(X + i) == sequence.end())
        {
            ansFound = true;
            ans = X + i;
            break;
        }
        i++;
    }

    cout << ans << "\n";
}

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

int main(){
	int N;
	cin>>N;
	
	long double A[N];
	for(int i=0;i<N;i++)
		cin>>A[i];
	
	long double B=0;
	for(int i=0;i<N;i++){
		B+=(long double) 1/A[i];
	}
	
	cout<<(long double)(1/B);
	return 0;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

li fact(li n)
{
    li ans=1;

    f(i,1,n)
    {
        ans*=i;
    }

    return ans;
}
    
int main()
{    
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        li n;

        cin>>n;

        li fact1 = fact(n);

        li fact2 =fact(n-1);

        long double x[n],y[n];

        for(li i=0;i<n;i++)
            cin>>x[i]>>y[i];

        vector<ld> ans;

        f(i,0,n-1)
        {
            f(j,i+1,n-1)
            {
                ans.PB(sqrt(pow(abs(x[i]-x[j]),2)+pow(abs(y[i]-y[j]),2)));
            }
        }

        ld cnt=0;
        
        f(i,0,(li)ans.size()-1)
        {
            cnt+=(2*(fact2)*ans[i]);
        }

        cout<<fixed<<setprecision(10)<<(cnt/fact1);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	ll a, b, n;
	cin >> a >> b >> n;
	cout << (a * min(b - 1, n)) / b - a * (min(b - 1, n) / b) << endl;
	return 0;
}

// int main(){
// 	int n, m, q;
// 	cin >> n >> m >> q;
// 	vector<vector<int>> v(q);
// 	rep(i,q){
// 		int a, b, c, d;
// 		cin >> a >> b >> c >> d;
// 		a--;
// 		b--;
// 		v[i] = {a, b, c, d};
// 	}
// 	ll ans = 0;
// 	rep(i, 1 << m)
// 	{
// 		vector<int> t;
// 		ll temp = 0;
// 		rep(j, m)
// 		{

// 			if ((i >> j) & 1)
// 			{
// 				t.push_back(j+1);
// 			}
// 		}
		

// 		if(t.size() == n){
// 			rep(k, q)
// 			{
// 				if(t[v[k][1]] - t[v[k][0]] == v[k][2]){
// 					temp += v[k][3];
// 				}
// 			}
// 			print(t);
// 			cout << temp << endl;
// 		}
// 		ans = max(ans, temp);
// 	}
// 	cout << ans << endl;
// 	return 0;
// }

Measured memory_bytes: 3644
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int INF = 1e9 + 5;
const int V_TOTAL_MAX = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N, W;
    cin >> N >> W;
    vector<int> dp(V_TOTAL_MAX, INF);
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;

        for (int tot = V_TOTAL_MAX - 1; tot >= 0; tot--)
            if (dp[tot] < INF)
                dp[tot + v] = min(dp[tot + v], dp[tot] + w);
    }

    int ans = V_TOTAL_MAX - 1;

    while (dp[ans] > W)
        ans--;

    cout << ans << '\n';
}


Measured memory_bytes: 640
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

void solve(){
	//code
	string s;
	cin>>s;
	set<char> m;
	for(int i=0;i<s.length();i++){
		m.insert(s[i]);
	}
	if(m.size()==2) cout<<"Yes";
	else cout<<"No";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char[] ch = str.toCharArray();

        for(int i = 0; i < ch.length; i++) {
        	if(Character.isLowerCase(ch[i])) {

        		ch[i] = Character.toUpperCase(ch[i]);

        	} else if(Character.isUpperCase(ch[i])) {

        		ch[i] = Character.toLowerCase(ch[i]);

        	}
        }

        System.out.println(new String(ch));
    }
}


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

int main(void){
  int a, b;
  cin >> a >> b;
  if(a*b*1%2 == 1 || a*b*2%2 == 1 || a*b*3%2 == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
a,b,c,d = gets.split(" ").map{|item| item.to_i}
cdlcm = c.lcm(d)

c_div_count = b/c - (a-1)/c
d_div_count = b/d - (a-1)/d
cd_div_count = b/cdlcm - (a-1)/cdlcm

p b-a+1-c_div_count-d_div_count+cd_div_count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int, bool>> G[100000];
ll K;
vector<ll> d(100000, LLONG_MAX);
priority_queue<pair<ll, int>> que;
int main () {
    cin >> K;
    for (int i = 0; i < K; i++) {
        G[i].push_back(make_pair((i+1)%K, 1));
        G[i].push_back(make_pair((i*10)%K, 0));
    }
    d[1] = 1;
    que.push(make_pair(-d[1], 1));
    while (que.size()) {
        auto x = que.top();
        que.pop();
        if (d[x.second] < -x.first) continue;
        for (auto t: G[x.second]) {
            if (d[t.first] > -x.first+t.second) {
                d[t.first] = -x.first+t.second;
                que.push(make_pair(-d[t.first], t.first));
            }
        }
    }
    cout << d[0] << endl;
}

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

const int MAXN = 510;
char color[5] = "RYGB";
char res[MAXN][MAXN];

int main()
{
    int h,w,d,x,y;
    scanf("%d %d %d",&h,&w,&d);
    for(int i = 1 ;i <= h; ++i)
    {
        for(int j = 1; j <= w; ++j)
        {
            //先转化成切比雪夫距离
            x = (i+j+500)/d;
            y = (i-j+500)/d;
            //然后再根据切比雪夫距离来判断颜色
            res[i][j] = color[(x%2)*2+y%2];
            putchar(res[i][j]);
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scan = new Scanner(System.in);
        
        int suri = scan.nextInt();
        int miseA = scan.nextInt();
        int miseB = scan.nextInt();
        
        int ans1 = miseA - suri;
        int ans2 = miseB - suri;
        
        if (ans1 < 0 && ans2 < 0){
            ans1 = ans1 * -1;
            ans2 = ans2 * -1;
        }else if (ans1 < 0){
            ans1 = ans1 * -1;
        }else if (ans2 < 0){
            ans2 = ans2 * -1;
        }
        
        if (ans1 > ans2){
            System.out.println("B");
        }else{
            System.out.println("A");
        }
        
    }
}

Measured memory_bytes: 22740
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto N = readln.chomp.to!int;
    auto K = readln.chomp.to!int;
    
    int sum_t;
    foreach (x; readln.split.to!(int[])) {
        auto a = x * 2;
        auto b = abs(x - K) * 2;
        sum_t += min(a, b);
    }
    writeln(sum_t);
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	bNum := y / 4
	if y%2 != 0 || bNum > x {
		fmt.Println("No")
		return
	}
	if bNum == 0 {
		fmt.Println("Yes")
		return
	}

	var aNum int
	if y%4 != 0 {
		aNum = 1
	}

	for bNum >= 0 {
		if aNum+bNum == x {
			fmt.Println("Yes")
			return
		}
		bNum--
		aNum += 2
	}
	fmt.Println("No")
}



Measured memory_bytes: 1816