akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;



ll INF=LLONG_MAX;
int main()
{
    // input
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    // solve
    ll ans=INF;
    for(ll bit=0; bit<(1<<(n-1)); bit++){
        vector<int> tmp(0);
        for(int i=0; i<n-1; i++){
            if(bit&(1<<i)){
                tmp.emplace_back(i);
            }
        }
        if(tmp.size()<k-1) continue;
        ll ans_tmp=0;
        ll nmax=a[0];
        for(int i=1; i<n; i++){
            if(find(tmp.begin(),tmp.end(),i-1)!=tmp.end()){
                if(a[i]<=nmax) {ans_tmp+=(nmax-a[i]+1); nmax++;}
                else nmax=a[i];
            }
            else{
                nmax = max(nmax, a[i]);
            }
        }
        ans=min(ans,ans_tmp);
    }
    // output
    cout << ans << endl;
    return 0;
}

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

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

	int main(){

		long long  a,b,g,l;
		while(cin>>a>>b)
		{
			g = gcd(a,b);
			l = a * b /g;
			cout<<g<<" "<<l<<endl;	
		}		
		return 0;
	}

Measured memory_bytes: 1156
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
int main(){
	LL n;
	cin >> n;
 
	vector<int> b;
 
	REP(i, n){
		int x;
		cin >> x;
	
		if((i % 2 == 0 && n % 2 == 0) ||
			(i % 2 == 1 && n % 2 == 1)){
			b.pb(x);
		}else{
			b.insert(b.begin(), x);
		}
	}
 
	REP(i, n){
		cout << b[i];
		if(i != n - 1){
			cout << " ";
		}
	}
	cout << endl;
 
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 
ll N;
ll five(int expo) {
  if (N<pow(5,expo)*2) return 0;
  return five(expo+1) + N/((ll)pow(5,expo)*2);
}

int main() {
  cin >> N; 
  if (N&1) {
    cout << 0 << endl; return 0;
  }
  printf("%lld\n", five(1));
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
	char ch=getchar();
	int o=0;
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){
		o=(o<<3)+(o<<1)+(ch^48);
		ch=getchar();
	}
	return o;
}
int n;
struct node{
	int id,val;
}a[100001];
inline bool cmp(node x,node y){
	return x.val<y.val;
}
int main(){
	n=read();
	for(register int i=1;i<=n;i++){
		a[i].id=i;
		a[i].val=read();
	}
	sort(a+1,a+1+n,cmp);
	for(register int i=1;i<=n;i++)printf("%d ",a[i].id);
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main()
{
 int n,f=1,s=0;
 cin>>n;
 int a[n+1];
 for(int i=1;i<=n;i++) cin>>a[i];
 while(f!=0)
 {
  s++;
  for(int i=1;i<=n;i++)
  {
   if(a[i]%2!=0)
   f=0;
   
   a[i]=a[i]/2;
  }
 }
 cout<<s-1;
 return 0;
}

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

int main() {
    int W,H,N;
    cin >> W>>H>>N;
    vector<vector<int>> data(N, vector<int>(3));
 
  // 入力 (2重ループを用いる)
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 3; j++) {
        cin >> data.at(i).at(j);
      }
    }
    int lx=0,hx=W,ly=0,hy=H;
    for(int i=0;i<N;i++){
      if(data[i][2]==1)
        lx=max(lx,data[i][0]);
      if(data[i][2]==2)
        hx=min(hx,data[i][0]);
      if(data[i][2]==3)
        ly=max(ly,data[i][1]);
      if(data[i][2]==4)
        hy=min(hy,data[i][1]);
    }
    if(hx-lx>=0&&hy-ly>=0)
       cout<<(hx-lx)*(hy-ly)<<endl;
    else
      cout<<0<<endl;
    
  
         
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int n, m, a, b;
int d[1010];

int main(void){
	cin >> n >> m >> a >> b;
	rep(i, n)  cin >> d[i];

	stack<int> gomi;

	for (int i = 0; i < n; ++i){
		if(d[i] >= a){
			gomi.push(d[i]);
		}else{
			break;
		}
	}

	if(n - gomi.size() >= m){//?????????m??\???
		printf("%d\n", gomi.size());
		return 0;
	}

	while(gomi.size()){
		int k = gomi.top();
		if(k <= b){
			gomi.pop();
		}else{
			break;
		}
	}
	printf("%d\n", gomi.size());
	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



i64 n;
void solve(){
	cin >> n;
	
	printf("%.10f\n", pow(n/3.0,3));
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll x;
    cin >> x;

    put(1 - x);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    ll val = 0;
    rep(i,n){
        val += vec[i] / 2;
        if(i < n-1 && vec[i]%2 && vec[i+1] > 0){
            vec[i+1] -= 1;
            val++;
        }
    }
    cout << val << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict as dd
N = int(input())
A = list(map(int, input().split()))

D = dd(int)
for i in range(len(A)):
  D[A[i]] += 1
def C(n):
  if n <= 1:
    return 0
  else:
    return n*(n-1)//2
  
ans = 0
for k,v in D.items():
  ans += C(v)
for i in range(N):
#  print (A[i], D[A[i]])
  print (ans - C(D[A[i]]) + C(D[A[i]]-1))

Measured memory_bytes: 26780
import scala.io.StdIn

object Main extends App {


  val Array(n, m) = StdIn.readLine().split(' ').map(_.toInt)
  
  val t: Array[Int] = Array.fill[Int](n+1)(Int.MaxValue)
  t(0) = 0

  val c = StdIn.readLine().split(' ').map(_.toInt)

  (0 until m).foreach { i =>
    for(j <- c(i) to n){
      t(j) = scala.math.min(t(j), t(j-c(i)) + 1)
    }
  }

  println(t(n))
  
}



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

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

  int h, n;
  cin >> h >> n;

  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];

  ll sum = accumulate(a, a+n, 0);

  if (sum >= h) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
// using Graph = vector<vector<int>>;
const int MOD = 1000000007;

int main() {
  ll a, b, q;
  cin >> a >> b >> q;
  ll s[a + 1];
  for (ll i = 0; i < a; i++) cin >> s[i];
  s[a] = 1e15;
  ll ns[a + 1];
  for (ll i = 0; i < a; i++) ns[i] = -1 * s[i];
  sort(ns, ns + a);
  ns[a] = 1e15;
  ll t[b + 1];
  for (ll i = 0; i < b; i++) cin >> t[i];
  t[b] = 1e15;
  ll nt[b + 1];
  for (ll i = 0; i < b; i++) nt[i] = -1 * t[i];
  sort(nt, nt + b);
  nt[b] = 1e15;
  while (q--) {
    ll x;
    cin >> x;

    ll rs = lower_bound(s, s + a + 1, x) - s;
    ll ls = lower_bound(ns, ns + a + 1, -1 * x) - ns;

    rs = s[rs];
    ls = ns[ls] * (-1);

    ll rt = lower_bound(t, t + b + 1, x) - t;
    ll lt = lower_bound(nt, nt + b + 1, -1 * x) - nt;

    rt = t[rt];
    lt = nt[lt] * (-1);

    ll op1 = max(rs - x, rt - x);
    ll op2 = max(x - ls, x - lt);
    ll op3 = rt - ls + min(x - ls, rt - x);
    ll op4 = rs - lt + min(rs - x, x - lt);

    cout << min({op1, op2, op3, op4}) << "\n";
  }
}

Measured memory_bytes: 4480
#include <stdio.h>
#include <inttypes.h>

int N;
uint32_t K;
uint32_t A[114514];
uint64_t B[114514];

uint64_t nyan(uint32_t must_zero) {
	int i;
	uint64_t res = 0;
	for (i = 0; i < N; i++) {
		if ((A[i] & must_zero) == 0) res += B[i];
	}
	return res;
}

int main(void) {
	int i;
	uint64_t answer = 0, candidate;
	uint32_t must_zero = 0;
	if (scanf("%d%" SCNu32, &N, &K) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNu32 "%" SCNu64, &A[i], &B[i]) != 2) return 1;
	}

	for (i = 31; i >= 0; i--) {
		uint32_t mask = UINT32_C(1) << i;
		if ((K & mask) != 0) {
			candidate = nyan(must_zero | mask);
			if (candidate > answer) answer = candidate;
		} else {
			must_zero |= mask;
		}
	}
	candidate = nyan(must_zero);
	if (candidate > answer) answer = candidate;

	printf("%" PRIu64 "\n", answer);
	return 0;
}

/*

0 : ゼロ
* : ドントケア

00001011
00000***
0000*00*
0000*0*0
0000*0**


*/


Measured memory_bytes: 2916
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
 
 
using namespace std;

const int N = 100 * 1000;
long long down = 0;
long long up = N;
string sex;
int cnt = 0;
bool isval(long long k)
{
	cout << k << endl;
	cnt++;
	string s;
	cin >> s;
	if (s == "Vacant")
	{
		exit(0);
	}
	if (k % 2 == 0)
	{
		return (s != sex);
	}
	if (k % 2 == 1)
	{
		return (s == sex);
	}
}
void bsearch()
{
	while (up - down > 1)
	{
		long long md = (up + down) / 2;
		if (isval(md))
		{
			up = md;
		}
		else
		{
			down = md;
		}
	}
}

int main()
{
	cin >> up;
	cout << 0 << endl;
	cnt++;
	cin >> sex;
	if (sex == "Vacant")
	{
		exit(0);
	}
	bsearch();
	cout << up + 1 << endl;

}

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

// Modulo Summation
int main() {
	int N;
	cin >> N;

	vector<int> vA(N);
	int64_t res = 0ll;

	for (int i=0; i<N; i++){
		cin >> vA.at(i);
		res += vA.at(i);
	}

	// m が vA の最小公倍数-1 のとき
	res -= N;

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define INF (1e18)

int main(){   
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,A,B,C;
    cin >> N >> A >> B >> C;
    ll l[1010];
    rep(i,0,N) cin >> l[i];
    ll ans = INF;
    rep(bit,0,pow(4,N)){
        ll n = bit;
        ll v[10] = {};
        ll idx = 0;
        while(n > 0){
            v[idx] = n % 4;
            n /= 4;
            idx++;
        }
        ll tt = 0, sz[4] = {}, cnt[4] = {};
        // printa(v, N);
        rep(i,0,N){
            ll nn = v[i];
            if(nn == 0) continue;
            sz[nn] += l[i];
            cnt[nn]++;
        }
        // printa(v, N);
        bool ok = true;
        rep(k,1,4){
            if(cnt[k] == 0) ok = false;
        }
        if(!ok) continue;
        rep(k,1,4){
            // print(cnt[k]);
            // print(10 * (cnt[k]-1));
            tt += 10 * (cnt[k]-1);
            // print2("cnt",cnt[k]);
            // print(tt);
            if(k == 1){
                tt += abs(A - sz[k]);
            }else if(k == 2){
                tt += abs(B - sz[k]);
            }else{
                tt += abs(C - sz[k]);
            }
        }
        // print(tt);
        ans = min(ans, tt);

    }
    print(ans);

}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    if(n % 10 == 3){
        cout << "bon" << endl;
    }else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main(){
    int a,b,k,i,s,x[50],j=0;
    cin>>a>>b>>k;
    if(a>b) s=b;
    else s=a;
    for(i=s;i>0;i--)
        if(a%i==0 && b%i==0){
            x[j]=i;
            j++;
        }
    cout<<x[k-1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll W,H,x,y;
    int hantei=0;
    cin >> W >> H >> x >> y;
    double ans;
    if(W == x*2 && H == y*2) hantei =1;
    cout << fixed << setprecision(10) << W*H/2.0 << " " << hantei << endl;
}

Measured memory_bytes: 256
def s():
 n=int(input())-1
 A=list(map(int,input().split()))
 i=0
 for j in range(n):
  if A[j]<=A[-1]:A[i],A[j]=A[j],A[i];i+=1
 A[i],A[n]=A[n],A[i]
 print(" ".join(map(str,A[:i]))+" ["+str(A[i])+"] "+" ".join(map(str,A[i+1:])))
if'__main__'==__name__:s()


Measured memory_bytes: 16384
#include <iostream>

using namespace std;

int main(){
  
  int a,b,c,d;
  while(1){

    cin>>a>>b;
    if(a==0 && b==0)break;
    for(c=1;c<=a;c++){
      
      for(d=1;d<=b;d++){
	
	cout<<"#";
	
      }
      
      cout<<"\n";
      
    }
    cout<<"\n";
  }
  
  
  
  
  return 0;
}

Measured memory_bytes: 1120
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        while (true) {
            String data[] = reader.readLine().split(" ");
            int a = Integer.parseInt(data[0]);
            int b = Integer.parseInt(data[1]);

            if (a == 0 && b == 0) {
                break;
            }

            for (int y = 0; y < a; y++) {
                for (int x = 0; x < b; x++) {
                    builder.append("#");
                }
                builder.append("\n");
            }
            builder.append("\n");

        }
        System.out.print(builder);
    }
}

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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

const int dx[]={1,-1,0,0},
		  dy[]={0,0,1,-1};

const int inf=1e9;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,sz[N];

char s[N];

void IO(){
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	scanf("%d",&n);
	priority_queue<int,vector<int>,greater<int> > pq;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		pq.push(x);
		if (pq.top()==x)
			ans++;
	}
	printf("%d\n", ans);
}


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

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

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; }

vector<ll> dp(100000);

int counter=0;

void solve(int prev, int roop, ll num)
{
  if(prev>9||prev<0)
    return;

  if(num>3234566667)
    return;

  dp[counter++]=num;

  solve(prev+1, roop+1,num*10+(prev+1));
  solve(prev, roop+1, num*10+(prev));
  solve(prev-1, roop+1, num*10+(prev-1));
}

int main()
{
  int K;
  cin >> K;  
  
  for(int i=1; i<10; i++)
    solve(i, 0, i);

  sort(dp.begin(), dp.end());
  //rep(i, 100)
    cout << dp[K-1] << endl;

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline

MOD = 10**9 + 7
MAX_N = 10**5 + 10

fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * (i) % MOD

fac_inv = [1] + [0] * MAX_N
# Fmrmat's little theorem says a**(p-1) mod p == 1
# then, a * a**(p-2) mod p == 1
# it means that a**(p-2) is the inverse element
# Here, Get 1 / n! first
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

n, k = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
a.sort(reverse=True)

ans = 0
# Calculate Max
for i, item in enumerate(a):
    ans += mod_nCr(n-1-i, k-1) * item
    ans %= MOD

a = a[::-1]
for i, item in enumerate(a):
    ans -= mod_nCr(n-1-i, k-1) * item
    ans %= MOD

print(ans)

Measured memory_bytes: 22752
import itertools

N = int(input())
P = input()
Q = input()
pn =0
qn =0
count =0
for x in itertools.permutations(range(1,N+1,1)):
    count+=1
    tmp = " ".join(list(map(str,x)))
    if tmp == P:
        pn = count
    if tmp == Q:
        qn = count
print(abs(qn-pn))


Measured memory_bytes: 3060
main = do
  getLine
  s<-getLine
  print$solve s

solve s = minimum $ zipWith (+) toW toB
  where
  toW = scanl (\n c->if c=='#' then n+1 else n) 0 s
  toB = scanr (\c n->if c=='.' then n+1 else n) 0 s

Measured memory_bytes: 44668
#include<stdio.h>
int main(){
  int a, b, w, n, i, x[100]={0}, tmp;
  scanf("%d",&w);
  scanf("%d",&n);

  for( i=1 ; i<=w ; i++ ){
    x[i]=i;
  }

  for( i=0 ; i<n ; i++ ){
    scanf("%d,%d",&a,&b);
    tmp=x[a];
    x[a]=x[b];
    x[b]=tmp;
  }

  for( i=1 ; i<=w ; i++ ){
    printf("%d\n",x[i]);
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	static String str;
	static int pos;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			str = sc.next();
			pos = 0;
			System.out.println(expression());
		}
		sc.close();
	}

	static int expression() {
		int ret = term();
		while (str.charAt(pos) != '=') {
			if (str.charAt(pos) == '+') {
				pos++;
				ret += term();
			} else if (str.charAt(pos) == '-') {
				pos++;
				ret -= term();
			} else {
				break;
			}
		}
		return ret;
	}

	static int term() {
		int ret = factor();
		while (str.charAt(pos) != '=') {
			if (str.charAt(pos) == '*') {
				pos++;
				ret *= factor();
			} else if (str.charAt(pos) == '/') {
				pos++;
				ret /= factor();
			} else {
				break;
			}
		}
		return ret;
	}

	static int factor() {
		if (str.charAt(pos) == '(') {
			pos++;
			int temp = expression();
			pos++;
			return temp;
		} else {
			return number();
		}
	}

	static int number() {
		int ret = 0;
		while (Character.isDigit(str.charAt(pos))) {
			ret *= 10;
			ret += str.charAt(pos) - '0';
			pos++;
		}
		return ret;
	}

}

Measured memory_bytes: 17176
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static int[][] a;
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        a = new int[n][n];
        dp(0, n, 1);
        for(int i=0; i<n-1; i++) {
          StringBuilder sb = new StringBuilder();
          for(int j=i+1; j<n; j++) sb.append(a[i][j] + " ");
          out.println(sb.toString());
        }
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
    public static void dp(int begin, int end, int level) {
      if(begin>=end-1) return;
      int mid = (begin+end)/2;
      for(int i = begin; i<mid; i++)
        for(int j=mid; j<end; j++)
          a[i][j] = level;
      dp(begin, mid, level+1);
      dp(mid, end, level+1);

    }
}


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

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

  int ans = 0;
  for (int x=0; x<=k; x++) {
    for (int y=0; y<=k; y++) {
      int z = s - x - y;
      if (0<=z && z<=k) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

int main() {

    long long int k;
    cin >> k;

    long long int ans = 0;
    for ( long long int a = 1; a <= k; a++ ) {
        for ( long long int b = 1; b <= k; b++ ) {
            long long int g = gcd( a, b );
            for ( long long int c = 1; c <= k; c++ ) {
                ans += gcd( g, c );
            }
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

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

    int k,n;cin>>k>>n;
    vi a(n,0);ll mx=-1, sum=0;
    rep(i,n){
        cin>>a[i];
        if(i) mx=max(mx, 1ll*a[i]-a[i-1]);
    }
    mx=max(mx,1ll*a[0]+k-a[n-1]);
    cout<<k-mx<<endl;

	return 0;
}
 



Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    if(s[0]!=s[1]||s[1]!=s[2]){
        cout<<"Yes"<<Endl;
    }
    else cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

/*
ll n;cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++)
    cin>>a[i];
 
ll n;cin>>s;
string s;cin>>s;

ll n,m;cin>>n>>m;
vector<ll>a(n),b(m);
for(ll i=0;i<n;i++){
    cin>>a[i];
}
for(ll i=0;i<m;i++){
    cin>>b[i];
}

ll n;cin>>n;
vector<Pll>xy;
for(ll i=0;i<n;i++){
    ll x,y;cin>>x>>y;
    xy.pb({x,y});
}
*/


Measured memory_bytes: 256
n, max_weight = map(int, input().split())
dp = [[0 for _ in range(max_weight+1)] for _ in range(n+1)]

for i in range(n):
    weight, value = map(int,input().split())
    for w in range(max_weight+1):
        if w >= weight:
            dp[i+1][w] = max(dp[i][w-weight] + value, dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]
print(dp[n][max_weight])

Measured memory_bytes: 171400
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A;
int B;
int C;
long long K;
int main(){
  rd(A);
  rd(B);
  rd(C);
  rd(K);
  if(K%2){
    wt_L(B-A);
    wt_L('\n');
  }
  else{
    wt_L(A-B);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// int A, B, C; ll K;
// {
//   rd(A,B,C,K);
//   wt(if[K%2, B-A, A-B]);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define VMAX 100000
#define MAXLOOP 200000000
void solve(long long N, long long W, vector<long long> w, vector<long long> p){
  long long vmax = (MAXLOOP/N)/20;
  vector<vector<long long>> dp(N, vector<long long>(vmax+1, LLONG_MAX));
  dp[0][0] = 0;
  dp[0][p[0]] = w[0];

  for(long long i = 1; i < N; i++) {
    for(long long j = 0; j <= vmax; j++) {
      long long source = j - p[i];
      if(source < 0 || dp[i-1][source] == LLONG_MAX) {
        dp[i][j] = dp[i-1][j];
        continue;
      }

      dp[i][j] = min(dp[i-1][j], dp[i-1][source] + w[i]);
    }
  }


  #ifdef DEBUG
  for(long long i = 0; i < N; i++) {
    for(long long j = 0; j <= VMAX; j++) {
      if(dp[i][j] != LLONG_MAX) {
        cout << "[" << i << "][" << j << "]=" << dp[i][j] << " ";
      }
    }

    cout << endl;
  }
  #endif

  for(long long j = vmax; j >= 0; j--) {
    if(dp[N-1][j] <= W) {
      cout << j << endl;
      break;
    }
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long W;
  scanf("%lld",&W);
  vector<long long> ws;
  vector<long long> ps;
  long long w, p;
  for(int i = 0 ; i < N ; i++){
    cin >> w >> p;
    ws.push_back(w);
    ps.push_back(p);
  }
    solve(N, W, std::move(ws), std::move(ps));
    return 0;
}


Measured memory_bytes: 156544
X = int(input())

if X >= 400 and X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
elif X <= 1999:
    print(1)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String[] st = s.split(" ");
		int a = Integer.parseInt(st[0]);
		int b = Integer.parseInt(st[1]);
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}

}

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

int one[11];

signed main(void){ 
  
  string N; cin >> N;
  
  for(int i = 0; i <= 10; i++){ 
    if( i <= 5 ){ one[i] = i;}
    else{ one[i] = 11-i;}
  }
  
  
  
  if( N.size() == 1 ){ 
    int c = (int)(N[0]-'0');
    cout << one[c] << endl; return 0;
  } // N.size() == 1 の特殊な場合だけ別途処理
  
  
  
  int small = 0,large = 0; //ぴったりと、一つだけ大きい場合それぞれを持っておく
  
  for(int i = 0; i < (int)N.size()-1; i++){ 
    
    int c = (int)(N[i]-'0');
    
    if( i == 0 ){ 
      small = one[c]; large = one[c+1];
    } //初期値
   
    //それ以外の遷移
    
    int i_small,i_large; int ne = (int)(N[i+1]-'0');
    
    i_small = min(small+one[ne],large+one[10-ne]);
    i_large = min(small+one[ne+1],large+one[9-ne]);
    
    small = i_small; large = i_large;
  
  }
  
  cout << small << endl;
  
  return 0;
}

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

int main() {
    int n ,m;
    cin >> n >> m;
    int r1,l1;
    cin >> l1 >> r1;
    
    for(int i = 0; i < m - 1; ++i){
        int l,r;
        cin >> l >> r;

        if(l > l1)l1 = l;
        if(r < r1)r1 = r;
    }

    cout << (r1 - l1 + 1 > 0 ? r1 - l1 + 1 : 0) << endl;
}


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

int main() {
    string name;
    int i,n,q,time,elapsedt = 0;
    queue<pair<string,int> > que;
    vector<pair<string,int> > ans;
    pair<string,int> tmp;
    cin>>n>>q;
    for(i=0;i<n;i++) {
        cin>>name>>time;
        que.push(make_pair(name,time));
    }
    while(que.size()>0){
        tmp = que.front();
        que.pop();
        if(tmp.second <= q) {
            elapsedt += tmp.second;
            ans.push_back(make_pair(tmp.first,elapsedt));
        } else {
            elapsedt += q;
            que.push(make_pair(tmp.first,tmp.second - q));
        }
    }
    for(i=0;i<n;i++) {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}


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


int vis [10];

bool check( int n)
{  
     //check n if it have any undesired digit
     //if not return true
	while( n)
	{
	    int x= n%10;
	   if(vis[x]==1) return false ;
		n= n/10;
	}
	return true ;
}


int main()
{
   int n,k ;
   cin>>n>>k;
   
   for( int i=0;i<k;i++)
   {    
        int x;
     	cin>>x;
     	vis[x]=1;  //for marking undesired digit
   	
   	
	}	
	
	for( int i=n ; ; i++)  //look for digit greater than n which have no digit of k
	{
		if( check(i))
		{
			cout<<i<<endl;
			return 0;
		}
	}
	
}

Measured memory_bytes: 3544
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int s;
  cin >> s;
  int idx = 2;
  set<int> st;
  st.insert(s);

  while (1) {
    int n;
    if (s % 2 == 0) {
      n = s / 2;
    } else {
      n = 3 * s + 1;
    }
    // cout << n << endl;
    if (st.count(n)) {
      cout << idx << endl;
      return 0;
    }
    st.insert(n);
    idx++;
    s = n;
  }
  return 0;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S;
	std::cin >> S;
	if (S.size() == 3)
		std::reverse(S.begin(), S.end());
	std::cout << S << "\n";
}


Measured memory_bytes: 256
N,K = list(map(int, input().split()))

Lmax = 1
Rmin = N

P = [0.0]*(N+1)

for i in reversed(list(range(1, N+1))):
    if i >= K:
        P[i] = 1/N
    elif i*2 > N:
        p = 1/N
        current_point = i
        while current_point < K:
            p *= 1/2
            current_point *= 2
        P[i] = p
    else:
        P[i] = P[i*2] * (1/2)


print(sum(P))


Measured memory_bytes: 40432
/*
[abc105] B - Cakes and Donuts
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int N;

bool solve() {
    for (int i = 0; i <= N; i += 4) {
        if ((N - i) % 7 == 0) {
            return true;
        }
    }
    return false;
}

int main() {
    cin >> N;

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll X, i, ans=0, n=100;
    double a;

    cin >> X;

    while(n<X){
        a = (ld)n*1.01;
        n = a;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

//Compiler version gcc  6.3.0

int main()
{
  int k,s;
  int ans=0;
  scanf("%d %d",&k,&s);
  
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int temp = s -x - y;
      
     if(0<= temp && temp <= k)
       ans++;
      }
      
    }
  
   printf("%d",ans);
  
  
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
lint cxmax = -1e9;
lint cxmin = 1e9;
lint cymax = -1e9;
lint cymin = 1e9;
lint rxmax = -1e9;
lint rxmin = 1e9;
lint lxmax = -1e9;
lint lxmin = 1e9;
lint uymax = -1e9;
lint uymin = 1e9;
lint dymax = -1e9;
lint dymin = 1e9;
lint solve(lint t) {
  if(t < 0) return 1e18;
  lint xmax = max(cxmax, max(rxmax+t, lxmax-t));
  lint xmin = min(cxmin, min(rxmin+t, lxmin-t));
  lint ymax = max(cymax, max(uymax+t, dymax-t));
  lint ymin = min(cymin, min(uymin+t, dymin-t));
  return (xmax-xmin)*(ymax-ymin);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  REP(i, N) {
    lint x, y;
    char d;
    cin >> x >> y >> d;
    x *= 2; y *= 2;
    if(d == 'R') {
      rxmax = max(rxmax, x);
      rxmin = min(rxmin, x);
      cymax = max(cymax, y);
      cymin = min(cymin, y);
    } else if(d == 'L') {
      lxmax = max(lxmax, x);
      lxmin = min(lxmin, x);
      cymax = max(cymax, y);
      cymin = min(cymin, y);
    } else if(d == 'U') {
      cxmax = max(cxmax, x);
      cxmin = min(cxmin, x);
      uymax = max(uymax, y);
      uymin = min(uymin, y);
    } else {
      cxmax = max(cxmax, x);
      cxmin = min(cxmin, x);
      dymax = max(dymax, y);
      dymin = min(dymin, y);
    }
  }
  lint ans = solve(0);
  ans = min(ans, solve((lxmax-rxmax)/2));
  ans = min(ans, solve((lxmax-cxmax)));
  ans = min(ans, solve((cxmax-rxmax)));
  ans = min(ans, solve((lxmin-rxmin)/2));
  ans = min(ans, solve((lxmin-cxmin)));
  ans = min(ans, solve((cxmin-rxmin)));
  ans = min(ans, solve((dymax-uymax)/2));
  ans = min(ans, solve((dymax-cymax)));
  ans = min(ans, solve((cymax-uymax)));
  ans = min(ans, solve((dymin-uymin)/2));
  ans = min(ans, solve((dymin-cymin)));
  ans = min(ans, solve((cymin-uymin)));
  cout << fixed << setprecision(10) << (double)ans/4.0 << "\n";
}

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

int main(){
  string s;
  cin >> s;

  int ans;
  int n=s.length();
  for(int i=n;i>0;i--){
    if(s[i]=='Z'){
      ans=i;
      break;
    }
  }
  for(int i=0;i<n-1;i++){
    if(s[i]=='A'){
      ans-=i;
      break;
    }
  }
  cout << ans+1 << endl;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<vector<int> > g;

int dfs(int id,int pre){
	int res = 0;
	for(auto x:g[id]){
		if(x!=pre){
			res ^=dfs(x,id)+1;
		}
	}
	return res;
}

int main(){
	int n;
	cin >> n;
	g.resize(n);
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	if(dfs(0,0)==0){
		cout << "Bob" << endl;
	}else{
		cout << "Alice" << endl;
	}
	return 0;
}

Measured memory_bytes: 10368
import java.util.*;
import java.io.*;

// Template for atcoder
public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        int LIMIT = 1000 * 10000 + 10;
        int[] div = new int[LIMIT];
        Arrays.fill(div, 1);
        for (int i = 2; i < LIMIT; i++) {
            for (int j = i; j < LIMIT; j += i) {
                div[j]++;
            }
        }

        long res = 0;
        int n = nextInt();
        for (int i = 1; i <= n; i++) {
            res += 1L * i * div[i];
        }
        outln(res);
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


Measured memory_bytes: 72764
n = int(input())
data = [input().split() for i in range(n)]
data = [[i[0],int(i[1]),j+1] for i,j in zip(data,list(range(n)))]
data.sort(key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(data[i][2])


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>

class Point{
public:
	double x, y;
	Point(){
		x = y = 0;
	}
	Point(double _x, double _y){
		x = _x;
		y = _y;
	}
};

class Segment{
public:
	Point begin, end;
	Segment(){
		begin = Point();
		end = Point();
	}
	Segment(Point _begin, Point _end){
		begin = _begin;
		end = _end;
	}
};

int SegmentsIntersectionPoint(Segment &a, Segment &b, Point &out){
	double d = (a.end.x - a.begin.x) * (b.end.y - b.begin.y) - (a.end.y - a.begin.y) * (b.end.x - b.begin.x);
	double s = (b.end.y - b.begin.y) * (b.begin.x - a.begin.x) - (b.end.x - b.begin.x) * (b.begin.y - a.begin.y);
	double t = (a.end.y - a.begin.y) * (b.begin.x - a.begin.x) - (a.end.x - a.begin.x) * (b.begin.y - a.begin.y);
	
	if(d == 0){
		//????????§???????????????
		return 1;
	}
	
	out.x = a.begin.x + s * (a.end.x - a.begin.x) / d;
	out.y = a.begin.y + s * (a.end.y - a.begin.y) / d;
	
	return 0;
}

int main(){
	int n;
	int xp0, yp0, xp1, yp1, xp2, yp2, xp3, yp3;
	Point insc;
	Segment a, b;
	
	std::cin >> n;
	for(int i=0;i<n;++i){
		std::cin >> xp0 >> yp0 >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3;
		a = Segment(Point(xp0, yp0), Point(xp1, yp1));
		b = Segment(Point(xp2, yp2), Point(xp3, yp3));
		
		SegmentsIntersectionPoint(a, b, insc);
		
		std::cout << std::setprecision(15) << insc.x << " " << insc.y << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1240