akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
ll work(ll x,ll l,ll r,ll lim){
	chkmin(r,lim);
	if(r<l) return 0;
	ll u=(l>>x)>0,v=(r>>x)>0,w=(lim>>x)>0;
	if(x==0) return (u!=v)+1;
	l&=(1ll<<x)-1;
	r&=(1ll<<x)-1;
	lim&=(1ll<<x)-1;
	if(u==v) return work(x-1,l,r,w>u?((1ll<<x)-1):lim);
	if(l<=r) return (1ll<<x)-l+lim+1;
	if(w) return work(x-1,0,r,min(lim,l-1))+max(lim-2*l+1+(1ll<<x),0ll);
	return lim-l+1;
}
int main(){
	ll l=readll(),r=readll();
	printf("%lld\n",work(59,l,r,(1ll<<60ll)-1));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void){
    // Here your code !
    
    int R[MAX], n;
    
    // First input, determines how many values there are
    cin >> n;
    
    // Allocate the number of inputs to the array
    for(int i = 0; i < n; i++) cin >> R[i];
    
    // Initialise max value
    int maxv = -2000000000;
    
    // Initialise min value to first element
    int minv = R[0];
    
    // Max value always after min value because of R[i] - minv
    for(int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
    
}

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

#define INF 1234567890
#define ll long long

int N, M;

int main()
{
	scanf("%d %d", &N, &M);
	vector<ll> A(N), B(M), C;
	for(int i=0; i<N; i++)
		scanf("%lld", &A[i]);
	for(int i=0; i<M; i++)
		scanf("%lld", &B[i]);
	C = convolution<998244353>(A, B);
	for(int i=0; i<C.size(); i++)
		printf("%lld ", C[i]);
	return 0;
}

Measured memory_bytes: 27272
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define mod 998244353
ll a[2000005],dp[2000005];
int main()
{
    /*string s;
    cin >> s;
    int n = s.size();
    if(s[n-1]=='s')
        s+="es";
    else
        s+="s";
    cout <<s << endl;*/
    /*int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i] >> b[i];

    int f=0;
    for(int i=1;i<=n-2;i++)
    {
        if((a[i]==b[i])&&(a[i+1]==b[i+1])&&(a[i+2]==b[i+2]))
        {
            f=1;
            break;
        }
    }
    if(f) cout << "Yes\n";
    else
        cout << "No\n";*/;
    /*ll n;
    cin >> n;
    ll ans=0;
    for(ll i=1;i<n;i++)
        ans+= (n-1)/i;

    cout << ans << endl;*/


    /*ll n,k;
    cin >> n>>k;
    set<ll>st;
    for(ll i=0;i<k;i++)
    {
        ll x,y;
        cin >> x>> y;
        for(ll j=x;j<=y;j++)
            a[j]=1;
    }
    vector<ll>v;
    dp[1]=1;
    for(ll i=1;i<=n;i++)
    {
        if(a[i])
            v.push_back(i);
    }
    sort(v.begin(),v.end());
    ll sz = v.size();
    for(ll i=1;i<=n;i++)
        {
            for(ll j=0;j<sz;j++)
            {
                if(i>=v[j])
                {
                    dp[i]=(dp[i]+dp[i-v[j]])%mod;
                }
                else
                    break;
            }
        }
    cout << dp[n] << endl;*/

    ll n, x,m;
    cin >> n >> x >> m;
    ll ans=x;
    dp[1]= x;
    ll mn = min(n,m);
    for(ll i=2;i<=mn;i++)
    {
        dp[i] = (dp[i-1]*dp[i-1])%m;
        ans+= dp[i];

    }
    //cout << ans << endl;
    if(n>m)
    {
        ll id;
        ll p  = (dp[mn]*dp[mn])%m;
        for(ll i=1;i<=mn;i++)
        {
            if(dp[i]==p)
            {
                id = i;
                break;
            }
        }
        //cout << id <<  endl;
        ll tot = mn-id+1;
        ll sum=0;
        for(ll i= id;i<=mn;i++) sum+= dp[i];
        n = n-m;
        ll vag = n/tot;
        ans+= (sum)*vag;
        ll rem= n%tot;
        if(rem!=0){
            for(ll i = id;;i++)
            {
                ans+= dp[i];
                rem--;
                if(rem==0) break;
            }
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 4368
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())


if (a*b) < 0:
    child = max(a,b) - min(a,b)
else:
    child = abs(b-a)

mother = v-w
if mother <= 0:
    print('NO')
    exit()

n = child/mother
if n>0 and n<=t:
    print('YES')
else:
    print('NO')

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

int main(){
	int r;
  cin>>r;
  if(r<1200){
    cout<<"ABC"<<endl;
    return 0;
  }
  if(r<2800){
    cout<<"ARC"<<endl;
    return 0;
  }
  cout<<"AGC"<<endl;
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())

    x = [[0] * N for _ in range(M)]
    for i in range(N):
        K, *A, = map(int, input().split())
        for a in A:
            x[a-1][i] = 1

    ans = 0
    for y in x:
        if sum(y) == N:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> T[i];
    sum+=T[i];
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for(int i=0; i<M; i++) cin >> P[i] >> X[i];
  vector<int> result(M);
  for(int i=0; i<M; i++) result[i]=sum-T[P[i]-1]+X[i];
  for(int i=0; i<M; i++) cout << result[i] <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef pair<lli, pii> ppi;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
    }
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const{
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        uint64_t x = hash1 ^ hash2;
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M ;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M;
    }
    return res%M;
}
lli solve(){
    lli a, b;
    cin>>a>>b;
    lli ans = 6 - a-b;
    cout<<ans<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
    // cin>>t;
    t = 1;
    while(t>0){
        t--;
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    cost = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    A.sort()
    D = {cost[i-1]: i for i in A}
    cost = sorted(D.keys())
    dp = [-1] * (N+1)
    dp[0] = 0
    for i in range(N+1):
        if dp[i] == -1:
            continue
        for c, d in D.items():
            if i + c <= N:
                dp[i+c] = max(dp[i+c], dp[i] * 10 + d)
    print(dp[N])
    return


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

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){

int n;
cin >> n;
long long a[n],b[n],c[n];
for (int i = 0; i < n; i++)
{
  cin >> a[i];
}
for (int i = 0; i < n; i++)
{
  cin >> b[i];
}
for (int i = 0; i < n; i++)
{
  cin >> c[i];
}
long long ans = 0;
sort(a,a+n);
sort(b,b+n);
sort(c,c+n);
for (int i = 0; i < n; i++)
{
  long long  amax = lower_bound(a,a+n,b[i])-a;
  long long cmin = upper_bound(c,c+n,b[i])-c;
  cmin = n-cmin;
  ans+=amax*cmin;

}

cout << ans;
return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k,c=0,ans=0,index=0;
    string s;
    cin>>n>>k>>s;
    for(int i=0;i<n;i++){
        if(i==0){
            if(s[i]=='0')c++;
        }
        else if(s[i]=='0' && s[i-1]=='1'){
            c++;
        }
        ans=max(ans,i-index+1);
        if(i!=n-1 &&s[i]=='1'&&s[i+1]=='0' &&c==k){
            while(s[index]=='1' && index!=n-1){
                index++;
            }
            while(s[index]=='0' && index!=n-1){
                index++;
            }
            c--;
        }

    }
    cout << ans<<endl;
    return 0;
}


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

int main()
{
    deque <int> dq;

    int q;
    scanf("%d", &q);

    while(q--)
    {
        int num, d, p, x;
        scanf("%d", &num);

        if(num == 0)
        {
            scanf("%d%d", &d, &x);

            if(!d)
                dq.push_front(x);
            else
                dq.push_back(x);
        }

        else if(num == 1)
        {
            scanf("%d", &p);

            printf("%d\n", dq.at(p));
        }

        else
        {
            scanf("%d", &d);

            if(!d)
                dq.pop_front();

            else
                dq.pop_back();
        }
    }

    return 0;
}



Measured memory_bytes: 4672
#include<stdio.h>
int main()
{
  int a,b;
  int x,y,z;
  int gcd,lcm;
  while(scanf("%d%d",&a,&b)!=EOF)
    {
      if(a>=b)
	{
	  x=a;
	  y=b;
	}
      else
	{
	  x=b;
	  y=a;
	}
      while(1)
	{
	  z=x%y;
	  if(z==0) break;
	  else
	    {
	      x=y;
	      y=z;
	    }
	}
      gcd=y;

      if(a>=b)
	{
	  x=a;
	  y=b;
	}
      else
	{
	  x=b;
	  y=a;
	}
      z=y;
      while(1)
	{
	  if(z%x==0) break;
	  else z+=y;
	}
      lcm=z;

      printf("%d %d\n",gcd,lcm);
    }
  return 0;
}

Measured memory_bytes: 592
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   it.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> //indexed_set;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b,ll m) {ll res=1;a%=m;for(;b;b>>=1){if(b&1)res=res*a%m;a=a*a%m;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n,k,ans;
		cin>>n>>k;
		ans=0;
		for(ll i=k;i<=n+1;i++){
			ll l=((i-1)*i)/2;
			// cout<
			ll r=((2*n-i+1)*i)/2;
			// cout<<"l="<<l<<"r="<<r<<endl;
			ans=(ans+(r-l+1+MOD)%MOD)%MOD;
		}
		cout<<ans<<endl;
	}
}

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

int main() {
  	long long int N, M;
  	cin >> N >> M;
  	long long int A[M];
  	for (int i = 0; i < M; i++) cin >> A[i];
  	long long int res;
  	long long int count = 0;
  	for (int i = 0; i < M; i++) count += A[i];
  
  	if (count > N) res = -1;
  	else res = N - count;
  
  	cout << res << endl;
}

Measured memory_bytes: 3712
S = gets.chomp
# s = S.chars

# space: (s.size - 1)

def all_forms(s)
  if s.size <= 1
    return [s]
  end
  
  a = []
  all_forms(s[1..-1]).each do |ss|
    a << s[0] + ss
    a << s[0] + "+" + ss
  end
  a
end

a = all_forms(S)
r = 0
a.each do |form|
  r += eval(form)
end
p r

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

int main()
{
  int n,ans;
  ans=0;
  cin>>n;
  vector<int> a(n,100001);
  vector<int> b(n-1);
  for(int i=0;i<n-1;i++)
  {
    cin>>b.at(i);
  }
  for(int i=0;i<n-1;i++)
  {
    a.at(i)=min(b.at(i),a.at(i));
    a.at(i+1)=min(b.at(i),a.at(i+1));
  }
  for(int i=0;i<n;i++)
  {
    ans+=a.at(i);
  }
  cout<<ans<<endl;
}

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

int n;

double a[N][N];

void print() {

    char c; cin >> c;

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

int main() {

    cin >> n;

    double p[n + 1];

    for (int i = 0;i < n;i++) {
        cin >> p[i];
    }

    a[0][0] = 1 - p[0]; a[1][0] = p[0];

    for (int i = 1;i < n;i++) {
        a[0][i] = (1 - p[i]) * a[0][i - 1];
    }

    for (int i = 1;i <= n;i++) {
        for (int j = 1;j <= n;j++) {
            a[i][j] = (1 - p[j]) * a[i][j - 1] + a[i - 1][j - 1] * p[j];
            //print();
        }
    }

    double ans = 0;

    for (int i = n / 2 + 1;i <= n;i++) {
        ans += a[i][n];
    }

    //print();

    printf("%.9f", ans);
}

Measured memory_bytes: 70656
package main

import (
	"fmt"
)

type Student struct {
	Number     int
	inClassNum int
}

type ByClassNum []Student

func (a ByClassNum) Len() int           { return len(a) }
func (a ByClassNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByClassNum) Less(i, j int) bool { return a[i].inClassNum < a[j].inClassNum }

func main() {

	var A int
	var B int
	fmt.Scan(&A)
	fmt.Scan(&B)

	var ans = A - B * 2
	if ans < 0 {
		ans = 0
	}

	fmt.Println(ans)

}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc079.contest.atcoder.jp/tasks/abc079_d>
問題文============================================================
 魔法少女のjoisinoお姉ちゃんは、この世にあるすべての数字を 1 に変えてやろうと思い立ちました。
 
 1 つの数字を i から j(0≦i,j≦9) に書き変えるには魔力 ci,j が必要です。
 
 今、目の前にある壁は縦方向に H、横方向に W のマス目になっていて、
 1 つ以上のマス目に 0 以上 9 以下の整数が 1 つずつ書かれています。
 
 上から i(1≦i≦H) 番目、左から j(1≦j≦W) 番目のマスの情報として Ai,j が与えられ、
 
 Ai,j≠−1 の場合はマスに Ai,j が書かれている
 Ai,j=−1 の場合はマスに数字が書かれていない
 ことを意味します。
 
 この壁に書かれている数字を最終的に全て 1 に変えるのに必要な魔力の最小量を求めてください。
=================================================================

解説=============================================================
ワーシャルフロイドで数字変換の最小魔力を求めておき、
 順番にマスを１に変換していけば良い
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    ll G[10][10] = {0};
    for(int i = 0; i < 10;i++)for(int j = 0; j < 10;j++) cin >> G[i][j];
    for(int i = 0; i  < 10;i++)for(int j = 0; j < 10;j++) for(int k = 0; k < 10;k++)
        G[j][k] = min(G[j][k],G[j][i] + G[i][k]);
    ll ans = 0;
    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            ll A; cin >> A;
            if(A == -1) continue;
            ans += G[A][1];
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstring>
#include <vector>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <cstring>
#include <unordered_set>
#include <algorithm>
using namespace std;

bool chk[10];
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	chk[a] = true;
	chk[b] = true;
	chk[c] = true;
	chk[d] = true;
	int cnt = 0;
	if (chk[1])cnt++;
	if (chk[7])cnt++;
	if (chk[9])cnt++;
	if (chk[4])cnt++;
	if (cnt == 4) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
		
	

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back






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


bool isprime(ll x){
  bool answer=true;
  for (ll i=2;i*i<=x;i++){
    if (x%i==0){
      answer=false;
      break;
    }
  }
  return answer;
}


int main(){

  ll a,b;
  cin>>a>>b;
  
  ll abgcd=gcd(a,b);

  vector<ll> answers(0);
  
  for (ll i=1;i*i<=abgcd;i++){
    if (abgcd%i==0){
      answers.pb(i);
      if (abgcd/i!=i){
        answers.pb(abgcd/i);
      }
    }
  }
  
  ll count=0;
  
  for (ll divider:answers){
    if (isprime(divider)){
      count++;
    }
  }

  cout<<count<<endl;

}


















Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>

typedef long long i64;

const int N = 100000 + 10;

int n, m, a[N];
std::pair<int, i64> sum[N];

inline std::pair<int, i64>& operator+= (std::pair<int, i64> &lhs, const std::pair<int, i64> &rhs) {
  lhs.first += rhs.first;
  lhs.second += rhs.second;
  return lhs;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]), --a[i];
  i64 ans = 0;
  for (int i = 1; i < n; ++i) {
    int l = a[i - 1], r = a[i];
    ans += (r - l + m) % m;
    if (l <= r) {
      sum[l + 1] += {1, -l - 1};
      sum[r + 1] += {-1, l + 1};
    } else {
      sum[l + 1] += {1, -l - 1};
      sum[m] += {-1, l + 1};
      sum[0] += {1, -(l + 1 - m)};
      sum[r + 1] += {-1, l + 1 - m};
    }
  }
  for (int i = 1; i < m; ++i) sum[i] += sum[i - 1];
  static i64 val[N];
  for (int i = 0; i < m; ++i) val[i] = (i64)i * sum[i].first + sum[i].second;
  printf("%lld\n", ans - *std::max_element(val, val + m));
  return 0;
}


Measured memory_bytes: 2944
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int xy[][]= new int[n][2];
        for(int i = 0; i < 2; i++){
            for(int j = 0; j < n; j++){
                xy[j][i] = sc.nextInt();
            }
        }
        distance(xy, n);
    }
     public static void distance(int xy[][], int n){
        double array[] = new double[4];
        double max = 0;
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < n; j++){
                array[i] += Math.abs(Math.pow(xy[j][0] - xy[j][1], i + 1));
                max = Math.max(max, Math.abs(xy[j][0] - xy[j][1]));
            }
        }
        System.out.println(array[0]);
        System.out.println(Math.sqrt(array[1]));
        System.out.println(Math.cbrt(array[2]));
        System.out.println(max);
        
    }
}


Measured memory_bytes: 26464
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();

        List<REL> rel = new LinkedList<>();
        for(int i = 0; i < M; i++){
            int P = sc.nextInt();
            int Y = sc.nextInt();
            rel.add( new REL(P, Y, i) );
        }
        
        Comparator<REL> comparator = new Comparator<REL>(){
            @Override
            public int compare(REL o1, REL o2){
                if( o1.P > o2.P ) return 1;
                if( o1.P < o2.P ) return -1;
                if( o1.Y > o2.Y ) return 1;
                if( o1.Y < o2.Y ) return -1;
                return 0;
            }
        };
        Collections.sort(rel, comparator);
        
        Map<Integer,String> map = new TreeMap<>();
        
        int orderY = Integer.MAX_VALUE;
        int beforeP = Integer.MAX_VALUE;
        for(REL x : rel){
            if( x.P != beforeP ){
                beforeP = x.P;
                orderY = 1;
            } else {
                orderY++;
            }
            
            String ID = String.format("%06d", x.P) + String.format("%06d", orderY);
            map.put(x.order, ID);
        }
        
        StringBuilder sb = new StringBuilder();
        for( int i : map.keySet() ){
            sb.append( map.get(i) ).append("\r\n");
        }

        System.out.println(sb.toString());
    }
    
    static class REL{
        int order;
        int P;
        int Y;
        public REL(int P, int Y, int order){
            this.order = order;
            this.P = P;
            this.Y = Y;
        }
        
        public String toString(){
            return P + " " + Y;
        }
    }
}


Measured memory_bytes: 172884
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

std::string X, Y;

int main()
{
  std::cin >> X >> Y;

  std::cout << (X<Y ? "<" : X>Y ? ">" : "=") << std::endl;

  return 0;
}

Measured memory_bytes: 256
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      _s: String
   }
   let s: Vec<_> = _s.as_bytes().iter().map(|c| if *c == b'B' {0} else {1}).collect();
   let n = s.len();
   let mut ans = 0;
   for i in 0..n-1 {
      if s[i] != s[i+1] {
         ans += 1;
      }
   }
   println!("{}", ans);
}


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a--;      //since inclusive

  ll lcm = (c*d) / __gcd(c, d);          //Inclusion - exclusion
  ll ans = (b - (b/c + b/d - b/lcm)) - (a - (a/c + a/d - a/lcm));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define SIZE 1000039
using namespace std;

string hashTable[SIZE];

int hashValue(string str){
  int res = 0;
  int v = 1;
  for(int i = 0; i < str.length(); i++){
    res += v * (str[i] - '0');
    v *= 7;
  }
  return res;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  for(int i = 0; i < SIZE; i++) hashTable[i] = "";

  int n; cin >> n;
  while(n--){
    string query, str;
    cin >> query >> str;
    if(query == "insert"){
      int hash = hashValue(str);
      int place = hash % SIZE;
      int v = 1;
      while(hashTable[place] != ""){
        place = (hash % SIZE + v * (1 + hash % (SIZE-1))) % SIZE;
        v++;
      }
      hashTable[place] = str;
    }
    if(query == "find"){
      int hash = hashValue(str);
      int place = hash % SIZE;
      int v = 1;
      bool yes = true;
      while(hashTable[place] != str){
        if(hashTable[place] == ""){
          yes = false; break;
        }
        place = (hash % SIZE + v * (1 + hash % (SIZE-1))) % SIZE;
        v++;
      }
      if(yes) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
  return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    cout << x + (y / 2) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=24;
const int INF=0x3f3f3f3f;
int n,m;
char mp[N][N];
int dis[N*N][N*N];
int id[N][N],cur;
int main() {
	memset(dis,INF,sizeof(dis));
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i) {
		scanf("%s",mp[i]+1);
		for (int j=1;j<=m;++j) {
			id[i][j]=++cur;
			if (i>1) {
				if (mp[i-1][j]=='.'&&mp[i][j]=='.')
					dis[id[i-1][j]][id[i][j]]=dis[id[i][j]][id[i-1][j]]=1;
			}
			if (j>1) {
				if (mp[i][j-1]=='.'&&mp[i][j]=='.')
					dis[id[i][j-1]][id[i][j]]=dis[id[i][j]][id[i][j-1]]=1;
			}
		}
	}
	for (int i=1;i<=cur;++i) dis[i][i]=0;
	for (int k=1;k<=cur;++k)
		for (int i=1;i<=cur;++i)
			for (int j=1;j<=cur;++j)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	int ans=0;
	for (int i=1;i<=cur;++i)
		for (int j=1;j<=cur;++j)
			if (dis[i][j]^INF)
				ans=max(ans,dis[i][j]);
	printf("%d\n",ans);
	return 0;
}

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

int main() {
	bool check = false;
	int c11, c12, c13, c21, c22, c23, c31, c32, c33;
	cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23 >> c31 >> c32 >> c33;
	if (c11 - c12 == c21 - c22 && c11 - c12 == c31 - c32) {
		if (c11 - c13 == c21 - c23 && c11 - c13 == c31 - c33) {
			check = true;
		}
	}
	if (check) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

using namespace std;

typedef long long li;
typedef unsigned long long lu;
const li infl = ~0LLU >> 2;

template <class T>
inline void Min(T &x, T y) {
  if (y < x) x = y;
}
template <class T>
inline void Max(T &x, T y) {
  if (y > x) x = y;
}

const int mod = 1e9 + 7;
inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }
int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}
int Inv(int x) {
  return Pow(x, mod - 2);
}

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

typedef vector<int> Poly;

const int maxn = 5000;

int n;
vector<int> g[maxn];
Poly dp[maxn];
int way[maxn + 1];

Poly Merge(const Poly &a, const Poly &b) {
  int n = a.size() - 1, m = b.size() - 1;
  Poly c(n + m + 1);
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      Add(c[i + j], Mul(a[i], b[j]));
    }
  }
  return c;
}

Poly Line(const Poly &a) {
  int n = a.size() - 1;
  Poly c = a;
  for (int i = 2; i <= n; i += 2) {
    Add(c[0], Mul(c[i], way[i], mod - 1));
  }
  return c;
}

void Dfs(int u, int p) {
  dp[u] = {0, 1};
  for (int v : g[u]) {
    if (v != p) {
      Dfs(v, u);
      dp[u] = Merge(dp[u], Line(dp[v]));
    }
  }
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  way[0] = 1;
  for (int i = 2; i <= n; i += 2) {
    way[i] = Mul(way[i - 2], i - 1);
  }
  
  Dfs(0, -1);
  int ans = 0;
  for (int i = 2; i <= n; i += 2) {
    Add(ans, Mul(dp[0][i], way[i]));
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll=long long;
const ll mod = 1e9 + 7;


template<class T>
T gcd(T a, T b)
{
  if(a && b) {
    return gcd(min(a, b), max(a, b) % min(a, b));
  } else {
    return a;
  }
}

template<class T>
T lcm(T a, T b)
{
  return a / gcd(a, b) * b;
}

ll power(ll base, ll exponent, ll module)
{
  if(exponent % 2) {
    return power(base, exponent - 1, module) * base % module;
  } else if(exponent) {
    ll root_ans = power(base, exponent / 2, module);
    return root_ans * root_ans % module;
  } else {
    return 1;
  }
}

struct combination
{
  vector<ll> fact, inv;
  combination(int sz) : fact(sz + 1), inv(sz + 1)
  {
    fact[0] = 1;
    for(int i = 1; i <= sz; i++) {
      fact[i] = fact[i - 1] * i % mod;
    }
    inv[sz] = power(fact[sz], mod - 2, mod);
    for(int i = sz - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % mod;
    }
  }
  ll P(int n, int r)
  {
    if(r < 0 || n < r) return 0;
    return (fact[n] * inv[n - r] % mod);
  }
  ll C(int p, int q)
  {
    if(q < 0 || p < q) return 0;
    return (fact[p] * inv[q] % mod * inv[p - q] % mod);
  }
};

template<typename T>
void print_vec(vector<T>& v)
{
  for(const auto& e: v) {
    cout << e << " ";
  }
  cout << endl;
}
template<typename T>
void print_2dvec(vector<vector<T>>& m)
{
  for(const auto& v: m) {
    for(const auto& e: v) {
      cout << e << " ";
    }
    cout << endl;
  }
}


int main(int argc, char const* argv[])
{
  int n, m;

  cin >> n >> m;

  if (n == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//
//  replacing_integer.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(int argc, const char* argv[]) {
  int n, k, c;
  string s;
  std::vector<int> work_day;
  std::vector<int> l;
  std::vector<int> r;
  std::vector<int> bounded;
  std::cin >> n >> k >> c;
  std::cin >> s;
  for (int i=0; i<n; i++) {
    if (s[i]=='x') continue;
    work_day.push_back(i+1);
  }

  l.push_back(work_day[0]);
  for (int i=1; i<work_day.size(); i++) {
    if (work_day[i] - l[l.size()-1] > c) {
      l.push_back(work_day[i]);
    }
  }

  r.push_back(work_day[work_day.size()-1]);
  for (int i=work_day.size()-2; i>=0; i--) {
    if (r[r.size()-1] - work_day[i] > c) {
      r.push_back(work_day[i]);
    }
  }

  for (int i = 0; i <k; i++) {
    if (l[i] == r[k-1-i]) {
      std::cout << l[i] << std::endl;
    }
  }
}

Measured memory_bytes: 4216
#include<stdio.h>
int main()
{
  int N, n[100];
  int i, max=0, sum=0;
  
  scanf("%d", &N);
  
  for(i=1;i<=N;i++){
    scanf("%d", &n[i]);
  }
  
  for(i=1;i<=N;i++){
   if(n[i]>=max){
     sum +=1;
     max = n[i];
     }
  }
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 128
import math
import itertools

n = int(input())
a = list(map(int, input().split()))
pf = [0] + list(itertools.accumulate(a, math.gcd))
pb = [0] + list(itertools.accumulate(reversed(a), math.gcd))
pb.reverse()
ans = [0]*n
for i in range(n):
  ans[i] = math.gcd(pf[i], pb[i+1])
print(max(ans))

Measured memory_bytes: 24976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  rep(i,h){
    rep(j,w){
      if(i<b){
        if(j<a) cout<<0;
        else cout<<1;
      }else{
        if(j<a) cout<<1;
        else cout<<0;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;


int main() {
    string s;
    cin >> s;
    int cnt[26] = {};

    for(int i = 0; i < s.size(); i++){
        cnt[s[i] - 'a']++;
    }
    bool flag = false;
    for(int i = 0; i < 26; i++){
        if(cnt[i] > 1) flag = true;
    }
    if(flag) cout << "no" << endl;
    else cout << "yes" << endl;


}


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

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


Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P = pair<int, int>;
int main(){
    int h,w;
    cin>>h>>w;
    char a[100][100];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<h;i++){
        int count=0;
        for(int j=0;j<w;j++){
            if(a[i][j]=='.')count++;
        }
        if(count==w){
            for(int j=i+1;j<h;j++){
                for(int k=0;k<w;k++){
                    a[j-1][k]=a[j][k];
                }
            }
            h--;
            i--;
        }
    }
    for(int i=0;i<w;i++){
        int count=0;
        for(int j=0;j<h;j++){
            if(a[j][i]=='.')count++;
        }
        if(count==h){
            for(int j=i+1;j<w;j++){
                for(int k=0;k<h;k++){
                    a[k][j-1]=a[k][j];
                }
            }
            w--;
            i--;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
VI e[SIZE];
int v[SIZE];
void dfs(int x,int lt){
    int now=0;
    REP(i,SZ(e[x])){
        int y=e[x][i];
        if(y==lt)continue;
        dfs(y,x);
        now^=v[y]+1;
    }
    v[x]=now;
}
int main(){
    DRI(N);
    REP(i,N-1){
        DRII(x,y);
        e[x].PB(y);
        e[y].PB(x);
    }
    dfs(1,1);
    puts(v[1]?"Alice":"Bob");
    return 0;
}


Measured memory_bytes: 36864
import sys

while True:
    data = sys.stdin.readline().strip().split(' ')
    h = int(data[0])
    w = int(data[1])

    if h == 0 and w == 0:
        break

    for i in range(h):
        for j in range(w):
            if i==0 or i == (h - 1) or j == 0 or j == (w - 1):
                print('#', end='')
            else:
                print('.', end='')

        print('')

    print('')

Measured memory_bytes: 8944
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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

const int mod = INF+7;
int main(){
    ll a,b;cin>>a>>b;
    ll n = gcd(a,b);
    ll res = 1;
    for(ll i=2;i<=pow(n,0.5);i++){
        if(n%i!=0)continue;
        res++;
        while(n%i==0)n /= i;
    }
    if(n!=1)res++;
    cout<<res<<endl;
}



Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N],dp[N];

ll abso(ll x)
{
    if(x<0)
        return -x;
    return x;
}

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

    cin >> n >> k;

    rep(i,0,n)
    {
        cin >> ar[i];
    }

    dp[0] = 0;
    dp[1] = abso(ar[1]-ar[0]);

    rep(i,2,n)
    {
        dp[i] = INF;

        rep(j,1,k+1)
        {
            if(i >= j)
                dp[i] = min(dp[i-j]+abso(ar[i]-ar[i-j]),dp[i]);
        }
    }

    cout << dp[n-1];

    return 0;
}


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

long long max(int a, int b){
    if(a>=b) return a;
    else return b;
}

long long min(int a, int b){
    if(a<=b) return a;
    else return b;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a.at(i);
    
    long long mi = a.at(0), ma = a.at(0), su = a.at(0);
    for(int i=1; i<n; i++){
        mi = min(mi, a.at(i));
        ma = max(ma, a.at(i));
        su += a.at(i);
    }
    cout << mi << " " << ma << " " << su << endl;
    return 0;
    
    
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int d[1024][1024];
int H, W;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};

int crd2idx(P p){
  return p.first * W + p.second;
}

P idx2crd(int idx){
  return make_pair(idx / W, idx % W);
}

int main(){
  for(int i=0;i<1024;i++){
    for(int j=0;j<1024;j++){
      d[i][j] = 1<<30;
    }
  }
  cin >> H >> W;
  queue<pair<int, int> >q;
  for(int i=0;i<H;i++){
    string A;
    cin >> A;
    for(int j=0;j<W;j++){
      if(A[j] == '#'){
	d[i][j] = 0;
	q.push(make_pair(crd2idx(make_pair(i, j)), 0));
      }
    }
  }

  while(!q.empty()){
    P p = q.front(); q.pop();
    P cur = idx2crd(p.first);
    int cost = p.second;
    if(d[cur.first][cur.second] < cost) continue;
    for(int i=0;i<4;i++){
      int nx = cur.first + dx[i];
      int ny = cur.second + dy[i];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if(cost + 1 < d[nx][ny]){
	d[nx][ny] = cost + 1;
	q.push(make_pair(crd2idx(make_pair(nx, ny)), cost + 1));
      }
    }
  }

  int res = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      res = max(res, d[i][j]);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 12560
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
static const double EPS = 1e-10;


double dist(const vector<int> p1, const vector<int> p2) {
    double out = 0;
    for (int i = 0; i < p1.size(); i++) out += pow(p1[i] - p2[i], 2);
    return sqrt(out);
}

int main() {
    int n, d; cin >> n >> d;
    vector<vector<int>> P(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            int x; cin >> x;
            P[i].push_back(x);
        }
    }

    int out = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            double yd = dist(P[i], P[j]);
            if (min(ceil(yd) - yd, yd - floor(yd)) < EPS) out++;
        }
    }

    cout << out << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

def f(x,y):
    return x-y,x+y

def main():
    n = int(input())
    x = [0]*n
    y = [0]*n
    for i in range(n):
        x[i],y[i] = map(int,input().split())
    f0 = [0]*n
    f1 = [0]*n
    for i in range(n):
        f0[i],f1[i] = f(x[i],y[i])
    print(max(max(f0)-min(f0),max(f1)-min(f1)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 40504
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc = new FastScanner();
	static final double ALLOWABLE_ERROR = 0.00000001;

	public static void main(String[] args) {
		int q = sc.nextInt();
		
		StringBuilder ans = new StringBuilder();
		for(int i=0; i<q; i++) {
			double x0 = sc.nextDouble();
			double y0 = sc.nextDouble();
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			
			if(x0 == x1) {
				if(x2 == x3) {
					ans.append(2);
				} else if(y2 == y3) {
					ans.append(1);
				} else {
					ans.append(0);
				}
			} else if(y0 == y1) {
				if(x2 == x3) {
					ans.append(1);
				} else if(y2 == y3) {
					ans.append(2);
				} else {
					ans.append(0);
				}
			} else {
				double a1 = (y1 - y0) / (x1 - x0);
				double a2 = (y3 - y2) / (x3 - x2);
				
				if(Math.abs(a2 - a1) < ALLOWABLE_ERROR) {
					ans.append(2);
				} else if(Math.abs((a1 * a2) + 1) < ALLOWABLE_ERROR) {
					ans.append(1);
				} else {
					ans.append(0);
				}
			}
			
			ans.append("\n");
		}
		
		System.out.print(ans);
	}

	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 28976