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

int main() {
    bool fi = false;
    int N, a;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    for(int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] != 0)
            a = i;
    }
    for(int i = 0; i <= 100; ++i) {
        for(int j = 0; j <= 100; ++j) {
            bool iscorrect = true;
            int H = h[a] + abs(x[a] - i) + abs(y[a] - j);
            for(int k = 0; k < N; ++k) {
                if(h[k] != max(H - abs(x[k] - i) - abs(y[k] - j), 0)) {
                    iscorrect = false;
                    break;
                }
            }
            if(iscorrect) {
                printf("%d %d %d\n", i, j, H);
                fi = true;
            } else
                continue;
        }
        if(fi)
            break;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}

ll dp[21][1010];

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(K);
  rep(i,K) cin>>A[i];

  setComb();

  dp[0][0]=1;
  for(int i=0;i<K;i++){
    for(int j=0;j<=N;j++){
      for(int k=0;k<=A[i]&&j+k<=N;k++){
        ll coef=comb(N-j,k)*comb(N-k,A[i]-k)%MOD;
        add(dp[i+1][j+k],dp[i][j]*coef%MOD);
      }
    }
  }

  cout<<dp[K][N]<<endl;

  return 0;
}


Measured memory_bytes: 5120
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for(i=1;i<=n;i++) {
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    trace(A, n);
  }
  return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<cctype>
#include<list>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<functional>
#include<utility>
using namespace std;
#define tmax(a, b) if (b > a) a = b
#define tmin(a, b) if (b < a) a = b
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<char, char> pcc;
const int inf = 0x3f3f3f3f;
const LL lnf = 0x3f3f3f3f3f3f3f3fLL;
const double pi = 3.14159265358979323846;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 300 + 10;
int n, k;
bool a[15];

int check(int x) {
	char num[15]; sprintf(num, "%d", x);
	int len = strlen(num);
	for (int i = 0; i < len; ++i) {
		int j = num[i] - '0';
		if (a[j]) return pow(10, len - i - 1);
	}
	return -1;
}

int main() {
	int cas = 0;
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
#ifdef NIGHT_13  
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int timest = clock();
#endif
	while (scanf("%d%d", &n, &k) == 2) {
		memset(a, false, sizeof a);
		for (int i = 0, j; i < k; ++i) scanf("%d", &j), a[j] = true;
		for (int i = n;; ) {
			int j = check(i);
			if (j == -1) { printf("%d\n", i); break; }
			i++;
		}
	}
#ifdef NIGHT_13  
	printf("\nTime Cost: %d\t", (int)clock() - timest);
#endif
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vite ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tst lli T; cin>>T; while(T--)
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define lli long long int
#define vt vector
#define pb push_back
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    lli n, d, ans = 0;
    cin >> n >> d;
    while(n--)
    {
        lli a, b;
        cin >> a >> b;
        lli x = a * a + b * b;
        if(x<=d*d)
            ans++;
    }
    cout << ans;
    cout<< endl;
    // cout<< fixed << 1.0 * clock() / CLOCKS_PER_SEC << setprecision(10);
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>

int exhaustiveSearch(int i, int m, int Array[]){
    if(i==0){
        if(m==0)return 1;
        else return 0;
    }
        // a[i-1] を選ばない場合 (func(n-1, x, a) が OK なら OK)
    if (exhaustiveSearch(i-1, m, Array)) return 1;

    // a[i-1] を選ぶ場合 (func(n-1, x-a[i-1], a) が OK なら OK)
    if (exhaustiveSearch(i-1, m-Array[i-1], Array)) return 1;

    // どっちもダメだったらダメ
    return 0;
}


int main(){
    int n, q, M;
    int Array[50];

    scanf("%d",&n);
    int i=0;
    for(i=0; i<n; i++)scanf("%d", &Array[i]);
    scanf("%d",&q);

    for(i=0; i<q; i++){
        scanf("%d", &M);
        if(exhaustiveSearch(n, M, Array))printf("yes\n");
        else printf("no\n");
    }
    
    return 0;
}



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

int main(){
  long long N, A, B;
  cin >> N >> A >> B;
  long long d = N / (A+B);
  long long ans = A*d;
  long long x = N%(A+B);
  ans+=min(A, x);
  cout << ans <<endl;
  return 0;
}

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

int main(){
  int n,m; cin >>n >>m;
  int s[6], c[6];
  rep(i,m) cin >>s[i] >>c[i];
  rep(i,1000){
    string str = to_string(i);
    if(str.size()==n){
      int cnt = 0;
      rep(j,m){
        if(str[s[j]-1]!=c[j]+'0') break;
        else cnt++;
      }
      if(cnt==m){
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0; 
}

Measured memory_bytes: 3676
#include <iostream>
#include <utility>

using namespace std;

int main(){
   int A,B,C;
   scanf("%d %d %d",&A,&B,&C);

   if(A-B>=C){
       cout<<0<<endl;
   }else if(A-B<C){
       cout<<C-(A-B)<<endl;
   }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long A, long long B, std::vector<long long> X)
{
    ll ans = 0;
    ll tmp = X[0];
    for (int i = 1; i < N; i++)
    {
        if ((X[i] - tmp) * A <= B)
        {
            ans += (X[i] - tmp) * A;
        }else{
            ans += B;
        }
        tmp = X[i];
    }
    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    std::vector<long long> X(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &X[i]);
    }
    solve(N, A, B, std::move(X));
    return 0;
}


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

int main() {
  int n,a;
  string ans="APPROVED";
  cin >> n;
  for(int i=0;i<n&&ans=="APPROVED";i++){
    cin >> a;
    if((a%2==0 && a%3!=0) && a%5!=0) ans="DENIED";
  };
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int L, R, D; cin >> L >> R >> D; 
	int ans = 0; 
	for(int i = L; i <= R; i++){
		if(i % D == 0) ans ++; 
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;



int main(){
	int K,S;
	cin>>K>>S;
	int cnt = 0;
	for(int i=0;i<=K;i++){
		for(int j=0;j<=K;j++){
			if(i+j<=S){
				if(S-i-j<=K)cnt++;
			}
			else break;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import product
H,W,K = map(int,input().split())
S = [input().strip() for _ in range(H)]
C = {i:[0 for _ in range(W+1)] for i in range(H)}
for i in range(H):
    for j in range(1,W+1):
        C[i][j] = C[i][j-1]+int(S[i][j-1])
cmin = (H-1)*(W-1)
for x in product((0,1),repeat=H-1):
    A = []
    cur = 0
    for i in range(H-1):
        if x[i]==1:
            A.append(list(range(cur,i+1)))
            cur = i+1
    A.append(list(range(cur,H)))
#     print("A={}".format(A))
    cur = 0
    cnt = 0
    ind = 0
    for j in range(1,W+1):
        flag = 0
        for a in A:
            tot = 0
            for i in a:
                tot += C[i][j]-C[i][cur]
            if tot<=K:continue
            else:
                flag = 1
                break
        if flag==1:
            cnt += 1
            if cur==j-1:
                ind = 1
                break
            cur = j-1
    if ind==0:
        cmin = min(cmin,cnt+sum(x))
#     print("cmin={},x={}".format(cmin,x))
print(cmin)               

Measured memory_bytes: 74944
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=4005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
string s;
int n;
int r[MAXN],g[MAXN],b[MAXN];
ll ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>s;
	r[s.size()]=g[s.size()]=b[s.size()]=0;
	for(int i=s.size()-1;i>=0;i--)
	{
		r[i]=r[i+1];
		g[i]=g[i+1];
		b[i]=b[i+1];
		if(s[i]=='R')r[i]++;
		else if(s[i]=='G')g[i]++;
		else b[i]++;
	}
	for(int i=0;i<s.size();i++)
	{
		for(int j=i+1;j<s.size();j++)
		{
			if(s[i]==s[j])continue;
			if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
			{
				ans+=b[j];
				if(2*j-i<s.size()&&s[2*j-i]=='B')ans--;
			}
			if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
			{
				ans+=g[j];
				if(2*j-i<s.size()&&s[2*j-i]=='G')ans--;
			}
			if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
			{
				ans+=r[j];
				if(2*j-i<s.size()&&s[2*j-i]=='R')ans--;
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3688
w = input()

w_dict = {}
for a in range(len(w)):
    if w[a] not in w_dict:
        w_dict[w[a]] = 1
    else:
        w_dict[w[a]] += 1

checker = ''
for a in w_dict.values():
    if not a % 2 == 0:
        checker += '*'
        break

if checker == '':
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <stdio.h>
#define MAX 200

int i,n,q;
int A[MAX];

int solve(int i, int m){
	if (m == A[i])
		return 1;
	if (i >= n)
		return 0;
	
	if(solve(i + 1, m))
		return 1;
	if(solve(i + 1, m - A[i]))
		return 1;
	
	return 0;
}


int main(void) {
	int M; 
	
	scanf("%d",&n);
	
	for(i=0; i<n; i++)
		scanf("%d",&A[i]);
	
	scanf("%d",&q);

	for(i=0; i<q; i++){
		scanf("%d",&M);
		
		if(solve(0,M))
			printf("yes\n");
		else printf("no\n");
	}
	return 0;
}





Measured memory_bytes: 2128
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	int a=sc.nextInt();
	int b=sc.nextInt();
	int c=sc.nextInt();
	int count =0;
	for(int i=a;i<=b;i++){
	    if(c%i==0) count++;
	}
	System.out.println(count);
    }
}

Measured memory_bytes: 17356
#include <iostream>

using namespace std;

long long fact(int n);

int main ()
{
	int n;

	cin >> n;

	cout << fact(n) << endl;

	return 0;
}

long long fact(int n)
{
	if(n == 1)    return 1;
	else if(n == 0)    return 0;

	return (n * fact(n - 1));
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  ll n,d,x,y;
  cin>>n>>d;
  ll ans=0;
  rep(i,n)
  {
    cin>>x>>y;
    if(x*x+y*y<=d*d)
    {
      ans++;
    }
  }
  cout<<ans;nl;
  return;
}
int main()
{
    IOS;
    int T=1;
   // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3804
N = int(input())
A = list(map(int, input().split()))

l = [0]*(10**5+1)

for i in A:
    l[i] += 1

ans = 0
for a, b, c in zip(l, l[1:], l[2:]):
    ans = max(ans, a+b+c)

print(ans)


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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;



void solve()
{
	int n, k;
	cin >> n >> k;
	int arr[n + 1];
	lop(i, 1, n + 1) cin >> arr[i];

	lop(i, k + 1, n + 1)
	{
		if (arr[i] > arr[i - k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





















Measured memory_bytes: 5216
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

int a,b,c;

int main(){
	cin>>a>>b>>c;
	if(b-a==c-b) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
h,w,n=map(int,input().split())
sx,sy=map(int,input().split())
S=input(); T=input()
u,d=sx,sx; l,r=sy,sy
for i in range(n):
    if S[i]=='U':
        u-=1
    if S[i]=='D':
        d+=1
    if S[i]=='L':
        l-=1    
    if S[i]=='R':
        r+=1
    if u<1 or d>h or l<1 or r>w:
        print('NO')
        break
    if T[i]=='U':
        d=max(1,d-1)
    if T[i]=='D':
        u=min(h,u+1)
    if T[i]=='L':
        r=max(1,r-1)
    if T[i]=='R':
        l=min(w,l+1)
else:
    print('YES')

Measured memory_bytes: 48496
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  ll p=1000000007;
  int k[n];
  rep(i,n)cin >> k[i];
  int u[n];
  u[0]=0;
  rep(i,n-1)u[i+1]=max(u[i],i+1-(k[i]+1)/2);
  ll ans=1;
  rep(i,n){
    ans=(ans*(n-i-u[n-1-i]))%p;
  }
  cout << ans << endl;
}

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

#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define M_PI 3.1415
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

lli conta(lli a, lli b, lli m){
  if(a%m == 0) return (b/m) - (a/m) + 1;
  return (b/m) - (a/m);
}

lli gcd(lli a, lli b){
	while(1){
		if(a == 0) return b;
		b%=a;
		if(b == 0) return a;
		a %= b;
	}
}


lli lcm(lli a, lli b){
	lli temp = gcd(a,b);
	return temp ? (a / temp*b) : 0;
}

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

  lli a, b, c, d;

  cin >> a >> b >> c >> d;

  lli ans = 0;

  // cout << conta(a, b, c) << endl;
  // cout << conta(a, b, d) << endl;
  // cout << conta(a, b, d*c) << endl;

  cout << (b-a+1) - conta(a, b, c) - conta(a, b, d) + conta(a, b, (lcm(c, d))) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

int num[101];
int main() {
  int n, S;
  while(cin >> n >> S,n||S) {
    memset(num,0,sizeof(num));
    REP(i,n) {
      int r;
      cin >> r;
      num[r]++;
    }
    int res = 0;
    REP(i,101) {
      REP(j,i+1) {
        if (i+j > S) {
          if (i==j) res += (num[i] - 1) * num[i] / 2;
          else res += num[i] * num[j];
        }
      }
    }
    cout << res << endl;
  }
}

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

using namespace std;
using ll = long long;

int z;

int main() {

	int a, b;
	char s[60][60];
	int cnt = 0;
	
	cin >> a >> b;

	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			cin >> s[i][j];
		}
	}
	
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			if (s[i][j] == '.') {
				if (s[i - 1][j] == '#')cnt++;
				if (s[i - 1][j - 1] == '#')cnt++;
				if (s[i][j - 1] == '#')cnt++;
				if (s[i + 1][j] == '#')cnt++;
				if (s[i + 1][j + 1] == '#')cnt++;
				if (s[i][j + 1] == '#')cnt++;
				if (s[i - 1][j + 1] == '#')cnt++;
				if (s[i + 1][j - 1] == '#')cnt++;
				s[i][j] = '0'+cnt;
			}
			cnt = 0;
		}
	}

	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			cout << s[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll a, b, v, w, t, d;
  scanf("%lld%lld%lld%lld%lld", &a, &v, &b, &w, &t);
  d = a > b ? a - b : b - a;
  printf("%s", d > (v - w) * t ? "NO" : "YES");
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
typedef long long lint;
const int N=2005;
int n,m;
char mp[N][N];

namespace utils{
	template <class T> inline void apx(T &x,const T y){
		x<y?x=y:0;
	}
	template <class T> inline void apn(T &x,const T y){
		x>y?x=y:0;
	}
	inline int nxi(FILE *fd=stdin){
		int x=0;
		char c;
		while(((c=fgetc(fd))>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=fgetc(fd));
		while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

template <class T>
class mque{
	protected:
		T que[N];
		int hd,tl;
	public:
		mque():hd(0),tl(0){}
		inline T front(){
			return que[hd];
		}
		inline void pop(){
			++hd;
		}
		inline void push(const T &v){
			que[tl++]=v;
		}
};
mque <int> lim[N];

int solve(const int st){
	static int buk[N],stk[N];
	for(int i=1; i<m; ++i){
		while(lim[i].front()<=st) lim[i].pop();
		buk[i]=lim[i].front();
	}
	buk[m]=st-1;
	int ans=0,top=0;
	for(int i=1; i<=m; ++i){
		for(; top&&buk[stk[top]]>buk[i]; --top){
			apx(ans,(i-stk[top-1])*(buk[stk[top]]-st));
		}
		stk[++top]=i;
	}
	return ans;
}

int main(){
	n=nxi(),m=nxi();
	for(int i=1; i<=n; ++i){
		assert(scanf("%s",mp[i]+1)==1);
	}
	for(int i=1; i<n; ++i){
		for(int j=1; j<m; ++j){
			if((mp[i][j]==mp[i][j+1])!=(mp[i+1][j]==mp[i+1][j+1])){
				lim[j].push(i+1);
			}
		}
	}
	for(int j=1; j<=m; ++j){
		lim[j].push(n+1);
	}
	int ans=0;
	for(int i=1; i<=n; ++i){
		apx(ans,solve(i));
	}
	printf("%d\n",std::max(std::max(n,m),ans));
	return 0;
}


Measured memory_bytes: 19840
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=3e5+100;
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1)ret*=a;
		b>>=1;
		a*=a;
	}
	return ret;
}
ll get(ll x){
	return x*(x+1)/2;
}
int a[maxn];
ll sum[maxn];
void solve()
{
    int n;scd(n);
    rep1(i,n){
    	scd(a[i]);
    	sum[i]=sum[i-1]+1ll*a[i];
	}
	ll ans=INF;
	rep1(i,n-1)ans=min(ans,abs(sum[n]-2*sum[i]));
	ac;
}
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("D://out.txt","w",stdout);
    //IOS;
    solve();
    return 0;
}

Measured memory_bytes: 2560
N, T = map(int, input().split())
A = list(map(int, input().split()))

maxp = 0
minv = float('inf')
ans = 0
for a in A:
    p = a - minv
    if p > maxp:
        maxp = p
        ans = 1
    elif p == maxp:
        ans += 1

    minv = min(minv, a)

print(ans)

Measured memory_bytes: 14244
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
const int N = (int)1e5+10 ;
const int M = (int)1000000007; 


int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    ll n , i , j ;
    cin >> n ;
    double p[n+1] ;
    for(i=1 ; i<=n ; i++){
        cin >> p[i] ;
    }
    double dp[n+1][n+1] ;
    for(i=0 ; i<=n ; i++){
        for(j=0 ; j<=n ; j++){
        dp[i][j] = 0.0 ;
      }
    }
    dp[0][0] = 1.0 ;
    for(i=1 ; i<=n ; i++){
        dp[i][0] = dp[i-1][0]*(1.0 - p[i]) ;
        for(j=1 ; j<=i ; j++){
             dp[i][j] = p[i]*dp[i-1][j-1] + (1.0 - p[i])*dp[i-1][j] ;
        }
    }

    double ans = 0.0 ;
    for(i=(n+1)/2 ; i<=n ; i++){
        ans+=dp[n][i]  ;
    }
    cout << setprecision(10) << fixed << ans ;
    return 0 ;
}

Measured memory_bytes: 70656
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=998244353;
const long long int INF=99999999999999999;

long long int n,m,sum,res=0,d[100005];

int main() {
	cout << fixed << setprecision(10);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            res+=d[i]*d[j];
        }
    }
    cout<<res;
} 


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NUL -1

typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[MAX];
int n, D[MAX], H[MAX];

void Depth(int , int );
int Height(int );
int Sibling(int );
void print(int );

int main(){
  int t, l, r, root=0, i;

  scanf("%d", &n);

  for(i=0; i<n; i++) T[i].parent = NUL;
  
  for(i=0; i<n; i++){
    scanf("%d %d %d", &t, &l, &r);
    T[t].left = l;
    T[t].right = r;
    if( l != NUL ) T[l].parent = t;
    if( r != NUL ) T[r].parent = t;
  }
  
  for(i=0; i<n; i++) if( T[i].parent == NUL ) root = i;
  
  Depth(root, 0);
  Height(root);
  
  for(i=0; i<n; i++) print(i);
  
  return 0;
}

void Depth(int u, int d){
  if( u == NUL ) return;
  D[u] = d;
  Depth(T[u].left, d+1);
  Depth(T[u].right, d+1);
}

int Height(int u){
  int h_a=0, h_b=0;

  if( T[u].left != NUL ) h_a = Height( T[u].left )+1;
  if( T[u].right != NUL ) h_b = Height( T[u].right )+1;
  return H[u] = (h_a > h_b ? h_a : h_b);
}

int Sibling(int u){
  if( T[u].parent == NUL ) return NUL;
  if( T[ T[u].parent ].left != u && T[ T[u].parent ].left != NUL )
    return T[ T[u].parent ].left;
  if( T[ T[u].parent ].right != u && T[ T[u].parent ].right != NUL )
    return T[ T[u].parent ].right;
  return NUL;
}

void print(int u){
  int h = 0;
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", Sibling(u));
  if( T[u].left != NUL ) h++;
  if( T[u].right != NUL ) h++;
  printf("degree = %d, ", h);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if( T[u].parent == NUL ) printf("root\n");
  else if( T[u].left == NUL && T[u].right == NUL ) printf("leaf\n");
  else printf("internal node\n");
}




Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    int N; cin>>N;
    double ans=0.0;
    if(N%2==0){
        ans = (N/2.0)/N;
        cout<<ans<<endl;
    }else{
        ans = (ceil(N/2.0))/N;
        cout<<ans<<endl;
    }
    return 0;
}

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

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

int main(){
  int r;
  double rr;
  cin >> r;
  rr = double(r);

  cout << rr*2*3.141592 << endl;
  return 0;
}

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

ll knapsackDP(ll wt[],ll price[],ll N,ll W){
        ll dp[N+1][W+1] = {0};
        for(ll n=0;n<=N;n++){
            for(ll w=0;w<=W;w++){
                if(n==0||w==0){
                    dp[n][w] = 0;
                }
                else{
                    ll inc=0,exc = 0;
                    if(wt[n-1]<=w){
                        inc = price[n-1] + dp[n-1][w-wt[n-1]];
                    }
                        exc = dp[n-1][w];
                    dp[n][w] = max(inc,exc);
                }
            }
        }
        return dp[N][W];
}


int main() {
    ll N,W;
    cin>>N>>W;
    ll wts[N];
    ll prices[N];
    for(ll i=0;i<N;i++){
        cin>>wts[i]>>prices[i];
    }
    cout << knapsackDP(wts,prices,N,W) << endl;
	return 0;
}



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

public class Main {
	
	static BufferedReader reader;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		String A_B = readLine();
		String[] AB = A_B.split(" ");
		int A = Integer.parseInt(AB[0]);
		int B = Integer.parseInt(AB[1]);
		if(A>B){System.out.println(A*2-1);}
		else if(A<B){System.out.println(B*2-1);}
		else{System.out.println(A*2);}
	}

	private static String readLine(){
		try{
			return reader.readLine();
		}catch(Exception e){
			return e.getMessage();
		}
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,K;
    cin>>N>>K;
    vi A(N);
    rep(i,N) cin>>A[i];
    rep(i,N) A[i]--;
    map<int,int> m;
    rep(i,N) {
        m[A[i]]++;
    }
    vi v;
    for(auto c : m) v.pb(c.se);
    sort(v.begin(),v.end(),greater<int>());
    //rep(i,N) cout<<v[i]<<" ";
    int answer=0;
    for(int i=K; i<v.size(); i++) {
        answer+=v[i];
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 11516
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ls x<<1
#define rs x<<1|1
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=1e7+19;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+100;

void solve()
{
	ll n;cin>>n;
	ll ans;
	for(ll i=sqrt(n);i;i--){
		if(n%i)continue;
		ans=i+n/i-2;
		break;
	}
	ac;
}
int main(){
    //IOS;
    solve();
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	x := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i])
	}

	ans := 0
	for _, v := range x {
		if  v*v <= (K-v)*(K-v) {
			ans += execTypeA(v)
		} else {
			ans += execTypeB(K, v)
		}
	}

	fmt.Println(ans)
}

func execTypeA(x int) int {
	return x*2
}

func execTypeB(K, x int) int {
	r := (K-x)*2

	if r >= 0 {
		return r
	} else {
		return -r
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll n, x, ans = 1, now = 0;
	cin >> n >> x;
	REP(i, n) {
		ll a;
		cin >> a;
		now += a;
		if (now <= x)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
a,b,c=map(int,input().split())
k=int(input())
ct=0
while b<=a:
  ct+=1
  b*=2
while c<=b:
  ct+=1
  c*=2
if ct<=k:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9164
import java.io.*;

public class Main{
	public static void main(String[] args){
		BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
		String s;
		int n;
		Long ans =1L;
		try{
			while((s=reader.readLine()) !=null){
				n=Integer.parseInt(s);
				for(int i=1;i<=n;i++){
					ans *= i;
				}
				System.out.println(ans);
				ans=1L;
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16868
#include <bits/stdc++.h>
#define F(i, x, y) for (int i = (x); i <= (y); ++i)
#define Fr(i, x, y) for (int i = (x); i < (y); ++i)
#define int long long
#define rt 1, 1, cnt
using namespace std;
typedef long long ll;

const int N = 200000 + 5;
int n, q, a, b, Q[N], dsc[N], cnt;
ll mns[N << 2], add[N << 2], tag[N << 2];
void put(int x, int tg) {
	add[x] += tg;
	mns[x] += tg;
	tag[x] += tg;
}
void pushdown(int p) {
	if (!tag[p]) return ;
	put(p << 1, tag[p]);
	put(p << 1 | 1, tag[p]);
	tag[p] = 0;
}
void pushup(int p) {
	add[p] = min(add[p << 1], add[p << 1 | 1]);
	mns[p] = min(mns[p << 1], mns[p << 1 | 1]);
}
void change(int p, int l, int r, int v, ll val) {
	if (l == r) {
		add[p] = min(add[p], val + dsc[l]);
		mns[p] = min(mns[p], val - dsc[l]);
	//	cerr << "update " << l << ": " << val + dsc[l] << " " << val - dsc[l] << '\n';
		return ;
	}
	pushdown(p);
	int mid = (l + r) >> 1;
	if (v <= mid) change(p << 1, l, mid, v, val);
	else change(p << 1 | 1, mid + 1, r, v, val);
	pushup(p);
}
void rangeadd(int p, int l, int r, int L, int R, ll v) {
	if (L <= l && r <= R) {
		put(p, v);
		return ;
	}
	int mid = (l + r) >> 1;
	pushdown(p);
	if (L <= mid) rangeadd(p << 1, l, mid, L, R, v);
	if (R > mid) rangeadd(p << 1 | 1, mid + 1, r, L, R, v);
	pushup(p);
}
ll minmns(int p, int l, int r, int L, int R) {
	if (L <= l && r <= R) return mns[p];
	int mid = (l + r) >> 1; pushdown(p); 
	if (R <= mid) return minmns(p << 1, l, mid, L, R);
	if (L > mid) return minmns(p << 1 | 1, mid + 1, r, L, R);
	return min(minmns(p << 1, l, mid, L, R), minmns(p << 1 | 1, mid + 1, r, L, R));
}
ll minadd(int p, int l, int r, int L, int R) {
	if (L <= l && r <= R) return add[p];
	int mid = (l + r) >> 1; pushdown(p);
	if (R <= mid) return minadd(p << 1, l, mid, L, R);
	if (L > mid) return minadd(p << 1 | 1, mid + 1, r, L, R);
	return min(minadd(p << 1, l, mid, L, R), minadd(p << 1 | 1, mid + 1, r, L, R));
}
signed main() {
	memset (mns, 0x3f, sizeof(mns));
	memset (add, 0x3f, sizeof(add));
	
	scanf ("%lld%lld%lld%lld", &n, &q, &a, &b);
	for (int i = 1; i <= q; ++i) scanf ("%lld", &Q[i]), dsc[i] = Q[i];
	dsc[q + 1] = a, dsc[q + 2] = b;
	sort (dsc + 1, dsc + q + 3);
	cnt = unique(dsc + 1, dsc + q + 3) - (dsc + 1);
	for (int i = 1; i <= q; ++i) Q[i] = lower_bound(dsc + 1, dsc + cnt + 1, Q[i]) - dsc;
	// ans(0, a) = |Q1-b|, ans(0, b) = |Q1-a|
	a = lower_bound(dsc + 1, dsc + cnt + 1, a) - dsc;
	b = lower_bound(dsc + 1, dsc + cnt + 1, b) - dsc;
	change(rt, a, abs(dsc[Q[1]] - dsc[b]));
	change(rt, b, abs(dsc[Q[1]] - dsc[a]));
	for (int i = 1; i < q; ++i) {
	//	rangeadd(rt, 1, cnt, abs(dsc[Q[i]] - dsc[Q[i + 1]]));
		ll rgt = minadd(rt, Q[i + 1], cnt) - dsc[Q[i + 1]], lft = dsc[Q[i + 1]] + minmns(rt, 1, Q[i + 1]);
		rangeadd(rt, 1, cnt, abs(dsc[Q[i]] - dsc[Q[i + 1]]));
		change(rt, Q[i], min(lft, rgt)); 
	}
	ll ans = 5e18;
	for (int i = 1; i <= cnt; ++i) ans = min(ans, minadd(rt, i, i) - dsc[i]);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 21280
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;    }
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;    }


//Variables Declaration


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    ll count = 0;
    for (int i = 0; i < m; ++i)
    {
        int a;
        cin>>a;
        count+=a;
    }
    n-=count;
    cout<<(n>=0 ? n : -1);

    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{

	string s;
	cin >> s;
	cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String a = stdIn.next();
		String b = stdIn.next();
		
		if (a.charAt(0) == 'H' && b.charAt(0) == 'H') { 
			System.out.println("H");
		} else if (a.charAt(0) == 'D' && b.charAt(0) == 'H') {
			System.out.println("D");
		} else if (a.charAt(0) == 'D' && b.charAt(0) == 'D') {
			System.out.println("H");
		} else {
			System.out.println("D");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#define REP(i,a) for(int i = 0; i < (a); i++)
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> b(n);
	REP(i, n) cin >> b[i];
	int a[n] = {};
	int i = n - 1;
	while(i >= 0){
		for(int j = i; j >= 0; j--){
			if(b[j] == j + 1){
				a[i] = b[j];
				b.erase(b.begin() + j);
				break;
			}
		}
		i--;
	}
	REP(i, n){
		if(a[i] == 0){
			cout << -1 << endl;
			return 0;
		}
	}
	REP(i, n)cout << a[i] << endl;
}

Measured memory_bytes: 256
import sys

a, b = sys.stdin.readline().strip().split()
s = sys.stdin.readline().strip()

for i in range(int(a)):
    try:
        if int(s[i]) < 0 or int(s[i]) > 9:
            print("No")
            sys.exit(0)
    except:
        print("No")
        sys.exit(0)
if s[i+1] != "-":
    print("No")
    sys.exit(0)
for j in range(i+2, i+1+int(b)):
    try:
        if int(s[j]) < 0 or int(s[j]) > 9:
            print("No")
            sys.exit(0)
    except:
        print("No")
        sys.exit(0)
print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  int count = 0;
  rep(i,s.length()){
    if(s[i] == 'p') ++count;
  }
  cout << s.length()/2 - count << endl;
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;

namespace AtCoder.Question
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var (a, b) = ReadValue<int, int>();
            Console.WriteLine(a * b);
        }
        static T ReadValue<T>()
        {
            return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
        }
        static (T1, T2) ReadValue<T1, T2>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
        }
        static (T1, T2, T3) ReadValue<T1, T2, T3>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
        }
        static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
        }
        static T[] ReadValues<T>()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
        }
    }
}


Measured memory_bytes: 27356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

vector<pair<int,int>> factorize(int n)
{
	vector<pair<int, int>> vp;
	int primes[] = { 2,3,5,7,11,13,17,19,23,29,31,37 };
	for (int i = 0; i < 12; ++i)
	{
		int m = 0;
		while (n%primes[i]==0)
		{
			n = n / primes[i];
			m++;
		}
		if (m > 0)vp.push_back(make_pair(primes[i], m));
	}
	for(auto a :vp)
	{
		std::cout << a.first <<":" << a.second <<"\n";
	}

	return vp;

}

set<int> s;
int arr[100000];
int main()
{
	
	Iint(n);
	int m = 0;
	for (int i = 0; i < n; ++i)
	{
		Iint(t);
		if(!s.insert(t).second)
		{
			s.erase(t);
			arr[m++] = t;
		}
		else { s.insert(t); }
	}
	if(m<=1)std::cout << 0;
	else {
		int* mxp = max_element(arr, arr + m);
		int mx = *mxp;
		int mx2 = -1;
		for(int* p=arr;p!=arr + m;p++)
		{
			if(p!=mxp)
			{
				if (*p > mx2)mx2 = *p;
			}
		}
		std::cout << mx*(ll)mx2;

	}

}




Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		for (int a = 1; a < 10; a++) {
			for (int b = 1; b < 10; b++) {
				if (a * b == n) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 22868
a, b = map(int, input().split())
s = input()
cnt = 0
y = ['0','1','2','3','4','5','6','7','8','9']

for i in range(a+b+1):
    if i == a:
        if s[a] == '-':
            cnt +=1
    else:
        if s[i] in y:
            cnt += 1
        
if cnt == (a+b+1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61508
s = gets.chomp.split('')

easy = true
s.each_with_index do |value, index|
    if (index + 1) % 2 == 1
        if value == 'L'
            easy = false
            break
        end
    else
        if value == 'R'
            easy = false
            break
        end
    end
end

print(easy ? 'Yes' : 'No')

Measured memory_bytes: 1916
n = int(input())
l=[]
for i in range(n):
    x, y = [int(i) for i in input().split()]
    l.append([x, y])

def kyori(a, b): # 2座標間の距離を求める関数
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5

soukyori = 0
for j in range(n):#★各町のペア間の距離の総和の2倍
    for k in range(n):
        soukyori = soukyori + kyori(l[j],l[k])
#print(soukyori)
print((soukyori * 2)/n/2) #★解説を要再確認！！！

Measured memory_bytes: 3064