akhauriyash/Code-Regression huggingface dataset:
function exec(N, M, A, B) {
  const a_max = Math.max.apply(null, A);
  const b_max = Math.max.apply(null, B);
  const max = Math.max(a_max, b_max);

  const A_Set = new Set(A);
  const B_Set = new Set(B);

  const mod = 10 ** 9 + 7;

  const already_A = [];
  const already_B = [];

  let ans = 1;

  for (let i = max; i > 0; i--) {
    const a_exists = A_Set.has(i);
    const b_exists = B_Set.has(i);
    if (a_exists && b_exists) {
      already_A.push(i);
      already_B.push(i);
    } else if (a_exists) {
      already_A.push(i);
      ans = ans * already_B.length;
      ans = ans % mod;
    } else if (b_exists) {
      already_B.push(i);
      ans = ans * already_A.length;
      ans = ans % mod;
    } else {
      let tmp = ((already_A.length * already_B.length) % mod) - (N * M - i);
      if (tmp < 0) {
        tmp += mod;
      }
      ans = (ans * tmp) % mod;
    }
  }

  return ans % mod;
}

function main(input) {
  let array = input.split("\n");
  let NM_array = array[0].split(" ").map(item => parseInt(item));
  let A_array = array[1].split(" ").map(item => parseInt(item));
  let B_array = array[2].split(" ").map(item => parseInt(item));
  return exec(NM_array[0], NM_array[1], A_array, B_array);
}

const input = require("fs").readFileSync("/dev/stdin", "utf8");
console.log(main(input));


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

int main(){
	int A[4][14]={},n,num;
	char mark;
	cin>>n;
	
	/*
			for(int i=0;i<4;i++){
			for(int j=1;j<=13;j++){
				cout<<A[i][j]<<" ";
			}
			cout<<endl;
		}
		*/
		
		
	for(int i=0;i<n;i++){
		cin>>mark>>num;
		if(mark=='S'){
			A[0][num]=1;
		}
		else if(mark=='H'){
			A[1][num]=1;
		}
		else if(mark=='C'){
			A[2][num]=1;
		}
		else if(mark=='D'){
			A[3][num]=1;
		}
	}
		
		for(int i=0;i<4;i++){
			for(int j=1;j<=13;j++){
				if(i==0&&A[i][j]==0){
					cout<<"S "<<j<<endl;
				}
				else if(i==1&&A[i][j]==0){
					cout<<"H "<<j<<endl;
				}
				else if(i==2&&A[i][j]==0){
					cout<<"C "<<j<<endl;
				}
				else if(i==3&&A[i][j]==0){
					cout<<"D "<<j<<endl;
				}
			}
		}
		
		/*
		for(int i=0;i<4;i++){
			for(int j=1;j<=13;j++){
				cout<<A[i][j]<<" ";
			}
			cout<<endl;
		}
		*/
		
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main(){

  int N; cin >> N;
  
  for(int i=9; i>0; i--){
    
    if(N%i == 0){
      
      if(N/i < 10)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
      
      return 0;
    
    }
  
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc126/tasks/abc126_b

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

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

    string yy = s.substr(0, 2);
    string mm = s.substr(2, 2);
    bool oky = false, okm = false;

    if (yy >= "01" && yy <= "12") {
        oky = true;
    }

    if (mm >= "01" && mm <= "12") {
        okm = true;
    }

    if (oky && okm) {
        cout << "AMBIGUOUS" << endl;
    } else if (oky) {
        cout << "MMYY" << endl;
    } else if (okm) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim
->>Code by Ashraful Islam Paran
->>CUET,CSE
*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef unsigned long long ull;
typedef vector<int> vi;
const int MX=2e5+5;
#define f(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

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

    int n, i, a[MX], sum1{0}, sum2{0}, mid1, mid2;

    cin >> n;
    f(i,0,n)
    {
        cin >> a[i],
            sum1+=a[i];
    }

    mid1 = ceil((double)sum1/n);
    mid2 = sum1/n;
    sum1 = 0;
    f(i,0,n)
    {
        sum1 += abs(a[i]-mid1)*abs(a[i]-mid1);
        sum2 += abs(a[i]-mid2)*abs(a[i]-mid2);
    }
    cout << min(sum1, sum2) << endl;

    return 0;
}



Measured memory_bytes: 3668
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
# N = list(map(int, input()))[::-1]
# N = int(input())
N, M, Q = map(int, input().split())
big = 0
s = 2**N
l = []

moto = list(range(1, Q+1))

for i in range(Q):
    l.append(list(map(int, input().split())))

A = []
for i in range(N):
    AA = []
    if A:
        for k in A:
            for j in range(1, M+1):
                if k[-1] <= j:
                    AA.append(k+[j])
        A = AA
    else:
        for j in range(1, M+1):
            A.append([j])

for i in A:
    wa = 0
    for j in l:
        if (i[j[1]-1]-i[j[0]-1]) == j[2]:
            wa += j[3]

    if big < wa:
        big = wa
print(big)


Measured memory_bytes: 110560
// AOJ 2151: Brave Princess Revisited
// 2017.11.11 bal4u@uu

#include <stdio.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

typedef struct { int t, n, m; } QUE;
QUE que[20001]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

int deq(int *n, int *m)
{
	if (qsize == 0) return 0;
	*n = que[0].n, *m = que[0].m;
	que[0] = que[--qsize];
	min_heapify(0);
	return 1;
}

void enq(int t, int n, int m)
{
	int i, min;

	i = qsize++;
	que[i].t = t, que[i].n = n, que[i].m = m;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		QUE tt = que[i]; que[i] = que[min]; que[min] = tt;
		i = min;
	}
}

typedef struct { int len, to[101], d[101], e[101]; } TBL;
TBL tbl[101];
int node[101][101]; int size;

int search(int start, int goal, int l)
{
	int s, m, i, k, e, p, ans;
	TBL *tp;

	qsize = 0;
	memset(node, 0x33, sizeof(node));
	node[start][l] = 0; enq(0, start, l);
	ans = 0x7fffff;
	while(deq(&s, &m)) {
		p = node[s][m];
		if (s == goal) {
			if (p < ans) ans = p;
			if (ans == 0) break;
			continue;
		}

		for (tp = tbl + s, i = 0; i < tp->len; i++) {
			e = tp->to[i];

			k = p + tp->e[i];
			if (k < node[e][m]) node[e][m] = k, enq(node[e][m], e, m);

			k = m - tp->d[i];
			if (tp->d[i] <= m && p < node[e][k]) node[e][k] = p, enq(node[e][k], e, k);
		}
	}
	return ans;
}

char buf[30], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, l, a, b, d, e, i;
	TBL *tp;
#if TM
	clock_t start, end;
	start = clock();
#endif

	while (fgets(p=buf, 30, stdin) && *p != '0') {
		n = getint(), p++, m = getint(), p++, l = getint();
		memset(tbl, 0, sizeof(tbl));
		while (m--) {
			fgets(p=buf, 30, stdin);
			a = getint()-1, p++, b = getint()-1, p++, d = getint(), p++, e = getint();
			tp = tbl+a, i = tp->len;
			tp->to[i] = b, tp->d[i] = d, tp->e[i] = e, tp->len++;
			tp = tbl+b, i = tp->len;
			tp->to[i] = a, tp->d[i] = d, tp->e[i] = e, tp->len++;
		}
		size = n;
		printf("%d\n", search(0, n-1, l));
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
int main() {
  int c[3][3];
  bool b[3][3];
  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) {
      cin >> c[i][j];
    }
  }
  int n;
  cin >> n;
  int p[n];
  for(int i=0; i<n; i++) {
    cin >> p[i];
  }
  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) {
      b[i][j] = false;
      for(int k=0; k<n; k++) {
        if(c[i][j] == p[k]) {
          b[i][j] = true;
        }
      }
    }
  }
  for(int i=0; i<3; i++) {
    if(b[i][0] && b[i][1] && b[i][2]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for(int i=0; i<3; i++) {
    if(b[0][i] && b[1][i] && b[2][i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if(b[0][0] && b[1][1] && b[2][2]) {
    cout << "Yes" << endl;
    return 0;
  }
  if(b[0][2] && b[1][1] && b[2][0]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>

//31 29 31 30 31 30 31 31 30 31 30 31



int main(){
	int i,j;
	int m,d;
	char* days[] ={
		"Monday",
		"Tuesday",
		"Wednesday",
		"Thursday",
		"Friday",
		"Saturday",
		"Sunday"
	};
	int month[12]={
		31,
		29,
		31,
		30,
		31,
		30,
		31,
		31,
		30,
		31,
		30,
		31,
	};
	while(1){
		scanf("%d %d",&m,&d);
		if(m==0&&d==0){
			break;
		}
		for(i=0;i<m-1;i++){
			d+=month[i];
		}
		d+=2;
		d%=7;
		printf("%s\n",days[d]);
	}
	return 0;
}

Measured memory_bytes: 584
# coding: utf-8

a,b,c,d=list(map(int,input().split()))

if a<=c<b<d:
    print(b-c)
elif a<c<d<=b:
    print(d-c)
elif c<=a<d<b:
    print(d-a)
elif c<a<b<=d:
    print(b-a)
elif a==c<b==d:
    print(b-a)
else:
    print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;
    cin>>s;
    lli dp[2][2019]={0};
    dp[0][s[0]-'0']++;
    lli ans=0;
    for(lli i=1;i<s.length();++i){
    	for(lli j=0;j<2019;++j)
    		dp[1][j]=0;
    	dp[1][s[i]-'0']++;
    	for(lli j=0;j<2019;++j){
    		lli next=(j*10+s[i]-'0')%2019;
    		dp[1][next]+=dp[0][j];
    	}
    	ans+=dp[1][0];
    	for(lli j=0;j<2019;++j)
    		dp[0][j]=dp[1][j];
    	//cout<<dp[i]<<" ";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3780
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

void solve()
{
int x;cin>>x;
if(x>=30)
cout<<"Yes";
else
cout<<"No";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890
 
int main(){
    ll i,j,k;
    ll n,ma,mb;
    cin>>n>>ma>>mb;
    VVI dp(404,VI(404,INF));
    dp[0][0]=0;
    for(k=0;k<n;k++){
        ll a,b,c;
        cin>>a>>b>>c;
        for(i=403;i>=a;i--){
            for(j=403;j>=b;j--){
                dp[i][j]=min(dp[i][j],dp[i-a][j-b]+c);
            }
        }
    }
    ll ans=INF;
    for(i=1;i*max(ma,mb)<404;i++){
        ans=min(ans,dp[i*ma][i*mb]);
    }
    if(ans==INF) ans=-1;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);


//modint
template<long long mod> struct modint {
    long long x;
    modint(long long x=0) : x((x%mod+mod)%mod) {}
    static int get_mod() { return mod; }
    modint &operator+=(const modint &a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint &a) {
        if((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint &a) {
        x = (int) (1LL * x * a.x % mod);
        return *this;
    }
    modint &operator/=(const modint &a) {
        *this *= a.inverse();
        return *this;
    }
    modint operator-() const { return modint(-x); }
    modint operator+(const modint &a) const { return modint(*this) += a; }
    modint operator-(const modint &a) const { return modint(*this) -= a; }
    modint operator*(const modint &a) const { return modint(*this) *= a; }
    modint operator/(const modint &a) const { return modint(*this) /= a; }
    bool operator==(const modint &a) const { return x == a.x; }
    bool operator!=(const modint &a) const { return x != a.x; }
    modint pow(long long t) const {
        if (!t) return 1;
        modint<mod> a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    modint inv() const {
        return pow(mod-2);
    }
    friend std::ostream &operator<<(std::ostream &os, const modint &a) { return os << a.x; }
    friend std::istream &operator>>(std::istream &is, modint &a) {
        long long t;
        is >> t;
        a = modint<mod>(t);
        return (is);
    }
};
//const long long mod = 998244353;
const long long mod = 1000000007;
using mint = modint<mod>;


struct combination {
    std::vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


int main(){
    fast_io();

    ll k,n; std::cin >> k;
    std::string s; std::cin >> s;
    n = static_cast<ll>(s.size());

    combination comb(n+k);

    mint ans=0;
    for(int i=0; i<=k; i++){
        mint b = mint(26).pow(k-i);
        b *= mint(25).pow(i);
        b *= comb(i+n-1,n-1);
        ans += b;
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 35620
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a,b,c,ans;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b) swap(a,b);
	if(a>c) swap(a,c);
	if(b>c) swap(b,c);
	printf("%d",c-a);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll a[100005];
    vector <int> v(100005,0);
    REP(i,n){
        cin >> a[i];
        v[a[i]]++;
    }
    
        for(int i=(n%2)+1;i < n;i+=2){
            if(v[i]!=2){
                cout << 0 << endl;
                return 0;
            }
        }
    
    if(n%2==1 && v[0]!=1){
        cout << 0 << endl;
        return 0;
    }
    ll answer = 1;
    REP(i,n/2)answer = (answer*2)%1000000007;
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<iostream> 
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector> 
#include<array>
#include<deque>
#include<list>
#include<forward_list>
#include<stack>
#include<queue>
#include<algorithm>
#include<numeric>
#include<iterator>
#include<functional>
#include<map>
#include<unordered_map>
#include<set>
#include<utility>
#include<unordered_set>
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define sort_all(v) sort(v.begin(), v.end())
#define fill(a) memset(a, 0, sizeof(a))

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define FOR_REV(i, a ,b) for(int i = a; i >= b; i--)
#define REP(i, n) FOR(i, 0, n)


void test() {
    int n;
    cin >> n;
    vector<int64_t> a(n);
    vector<ld> logarithm;
    for(auto &i : a) {
        cin >> i;
        if(i == 0) {
            cout << 0;
            return;
        }
        logarithm.push_back(log10((ld) i));
    }
    int64_t ans = 1;
    if(accumulate(logarithm.begin(), logarithm.end(), (ld) 0) > 18.1) {
        cout << -1;
        return;
    }
    else {
        for(const auto &i : a) {
            ans *= i;
        }
        if(ans > 1000000000000000000) cout << -1;
        else cout << ans;
    }
}   
 
int main ()     
{
    // int t;
    // cin >> t;
    // while(t--) 
        test();
}


Measured memory_bytes: 6252
#include<bits/stdc++.h>
using namespace std;
int n,k;
int min_func(int dp[], int ht[], int i){
    int j=max(0,i-k),min_ans=INT_MAX;
    for(;j<i;j++)min_ans = min(min_ans, dp[j]+abs(ht[j]-ht[i]));
    return min_ans;
}
int main(){
    scanf("%d %d",&n,&k);
    int ht[n];
    for(int i=0;i<n;i++)scanf("%d",&ht[i]);
    int dp[n];
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i] = min_func(dp, ht, i);
    }
    printf("%d",dp[n-1]);
    return 0;
}

Measured memory_bytes: 4480
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
import sys
input=sys.stdin.readline
n,m,k = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]
cd = [list(map(int,input().split())) for i in range(k)]
num = [0]*(n+1)
g = [[] for i in range(n+1)]
uf = UnionFind(n+1)
for a,b in ab:
  g[a].append(b)
  g[b].append(a)
  uf.union(a,b)
for c,d in cd:
  if uf.same(c,d) == True:
    g[c].append(d)
    g[d].append(c)
for i in range(1,n+1):
  print(uf.size(i)-len(g[i])-1,end=" ")


Measured memory_bytes: 125788
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double x1 = sc.nextDouble();
    double y1 = sc.nextDouble();
    double x2 = sc.nextDouble();
    double y2 = sc.nextDouble();
    System.out.println(Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
  }
}


Measured memory_bytes: 27976
#include<bits/stdc++.h>
using namespace std;
const int N=85,low=80*80*3;
int a[N][N],b[N][N];
bitset<N*N*10>dp[N][N];
int mx[N][N];
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        scanf("%d",&b[i][j]);
    dp[1][1].set(a[1][1]-b[1][1]+low,1);
    dp[1][1].set(b[1][1]-a[1][1]+low,1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        if(i==1&&j==1) continue;
        int x=abs(a[i][j]-b[i][j]);
        dp[i][j]=(dp[i-1][j]<<x)|(dp[i-1][j]>>x)|(dp[i][j-1]<<x)|(dp[i][j-1]>>x);
    }
    int ans=1e9;
    for(int i=0;i<=low*3;i++)
        if(dp[n][m][i])
        {
            ans=min(ans,abs(i-low));
        }
    printf("%d\n",ans);
}


Measured memory_bytes: 60928
#include <stdio.h>
#include <stdlib.h>

int main (void){
long long int A,B,C,N,ans=0,tmp;
scanf("%lld %lld %lld %lld",&A,&B,&C,&N);
if (A<B) {
  tmp=A;
  A=B;
  B=tmp;
}
if (B<C) {
  tmp=B;
  B=C;
  C=tmp;
}
if (A<B) {
  tmp=A;
  A=B;
  B=tmp;
}
for (int a = 0; a*A <= N; a++) {
  for (int b = 0; (a*A+b*B) <= N; b++) {
    if ((N-(a*A+b*B))%C==0) {
    ans++;
    //printf("%lld,%lld\n",a,b );
    }
  }
}
printf("%lld\n",ans );
        return 0;
}


Measured memory_bytes: 128
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/10/20 23:28:18
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,m,x; cin>>n>>m>>x;
  vector<int> C(n);
  vector<vector<int>> A(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin>>C[i];
    for (auto &a:A[i]) cin>>a;
  }
  constexpr int INF = 1e9;
  int ans = INF;
  for (unsigned int mask = 1; mask < (1u<<n); mask++) {
    int sum = 0;
    vector<int> L(m, 0);
    for (int i = 0; i < n; i++) {
      if ((mask & 1u<<i) == 0) continue;
      sum += C[i];
      for (int j = 0; j < m; j++)
        L[j] += A[i][j];
    }
    bool ok = true;
    for (auto l:L) ok &= l>=x;
    if (ok)
      ans = min(ans, sum);
  }
  cout << (ans != INF ? ans : -1) << endl;

  return 0;
}


Measured memory_bytes: 3608
def main():
  N, M, X = map(int, input().split())
  ans = float('inf')
  table = []
  for i in range(N):
    table.append(list(map(int, input().split())))
                 
  for i in range(2 ** N):
    tmp = [0] * (M+1)
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(M+1):
              tmp[k] += table[j][k]
    for l in range(1, len(tmp)):
      if tmp[l] < X:
        break
    else:
      if ans > tmp[0]:
        ans = tmp[0]
  if ans != float('inf'):
    print(ans)
  else:
    print(-1)  
    
if __name__ == '__main__':
  main()

Measured memory_bytes: 68492
#include<bits/stdc++.h>
#define INF 0X3f3f3f3f
#define ll long long
#define eps 1e-8
using namespace std;
typedef pair<ll,ll> node;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
ll n,a,b,m,t,num[maxn],sum,ans;
ll pow_mod(ll a,ll b,ll c)
{
    ll ans = 1;
    ll base = a%c;
    while(b)
    {
        if(b & 1)
            ans = (ans*base)%c;
        base = (base*base)%c;
        b >>= 1;
    }
    return ans;
}

int inv(int a)
{
    return a==1?1:(long long)(mod-mod/a)*inv(mod%a)%mod;
}
ll C(ll n,ll m)
{
    if(m<0)
        return 0;
    if(n<m)
        return 0;
    if(m>n-m)
        m=n-m;
    ll up=1,down=1;
    for(ll i=0; i<m; i++)
    {
        up=up * (n - i) % mod;
        down=down*(i+1) % mod;
    }
    return up*inv(down)%mod;
}
int main()
{
    cin >> n >> a >> b;
    ans = pow_mod(2,n,mod);
    ans = (ans - C(n,a) - C(n,b) + mod + mod) % mod;
    cout << ans - 1<< endl;
    return 0;
}


Measured memory_bytes: 256
n,t = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]

lians = []
for i in range(n):
  if li[i][1] <= t:
    lians.append(li[i][0])
if len(lians) == 0:
  print("TLE")
else:
  print(min(lians))

Measured memory_bytes: 3060
function Main(input) {
  input = input.split("\n");
  var x1 = parseInt(input[0].split(" ")[0]);
  var y1 = parseInt(input[0].split(" ")[1]);
  var x2 = parseInt(input[0].split(" ")[2]);
  var y2 = parseInt(input[0].split(" ")[3]);
  var ans = 0;
  var x3=x2-(y2-y1);
  var y3=y2+(x2-x1);
  var x4=x1-(y2-y1);
  var y4=y1+(x2-x1);
  var ans=x3+" "+y3+" "+x4+" "+y4;

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int Ceil(int a,int b){return ((a%b==0)?a/b:a/b+1);}

int main(){
	int n,k,a[100010],p=0,ans=0;
	cin>>n>>k;
	REP(i,n){
		cin>>a[i];
	}
	cout<<Ceil(n-1,k-1)<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define int long long
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }
const int mod = 1000000007;
int k;

int dfs(int u, int p, std::vector<std::vector<int> >& adj, int l, int cn = 0) {
	int res = k - cn - min(2ll, l);
	int cnn = 0;
	for (int v : adj[u]) {
		if (v != p) {
			res = res * dfs(v, u, adj, l + 1, cnn) % mod;
			cnn++;
		} 
	} 
	return res;
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	cin >> k;
	vector< vector<int> > adj(n); for (int o = 0; o < n - 1; o++) { int x, y; cin >> x >> y; x--; y--; adj[x].pb(y); adj[y].pb(x); }
	int ans = dfs(0, 0, adj, 0);
	cout << (ans + mod) % mod;
}

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

long N, A, B;
vector<long> H;

bool f(long mid) {
  vector<long> V = H;
  for (auto &v : V) v -= B * mid;
  long cnt = 0, tmp = A - B;
  for (auto v : V) if (v > 0) cnt += (v + tmp - 1) / tmp;
  return (cnt <= mid) ? true : false;
}

int main() {
  cin >> N >> A >> B;
  H.resize(N);
  for (auto &h : H) cin >> h;
  long ok = 1e9, ng = -1e9;
    while (ok - ng > 1) {
      long mid = (ok + ng) / 2;
      (f(mid)) ? ok = mid : ng = mid;
    }
  cout << ok << "\n";
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
#define MAX5 100010
#define MAX6 1000010
#define pb push_back
#define mp make_pair
typedef long long int ll;
vector<pair<ll,ll> >vec;
ll dp[MAX5][110],arr1[500],arr2[500];
ll rec(ll wt,ll i,ll n)
{
    //cout<<i<<" ";
    if(i>n-1)
        return 0;
    if(wt<=0)  
        return 0;
    if(dp[wt][i]!=-1)
        return dp[wt][i];
    else
    {
        if(wt-arr1[i]>=0)
        {
            return dp[wt][i]=max(arr2[i]+rec(wt-arr1[i],i+1,n),rec(wt,i+1,n));
        }
        else
        return dp[wt][i]=rec(wt,i+1,n);
    }
}
int main()
{
    ll n,wt;
    cin>>n>>wt;
    for(ll i=0;i<n;i++)
    {
        ll w1,v1;
        cin>>w1>>v1;
        arr1[i]=w1;
        arr2[i]=v1;
        //vec.pb(mp(w1,v1));
    }
    for(ll i=0;i<=wt+5;i++)
    {
        for(ll j=0;j<101;j++)
            dp[i][j]=-1;
    }
    //for(ll i=0;i<=wt+5;i++)
        //cout<<dp[i]<<" ";
    ll var=rec(wt,0,n);
    /*for(ll i=0;i<=wt;i++)
    {
        for(ll j=0;j<=n;j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<'\n';
    }*/
     //cout<<dp[i]<<" ";
    //cout<<endl;
    cout<<var<<'\n';
return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
	int N; cin >> N;
	set<string> S;
	REP(i,N){
		string s;
		cin >> s;
		S.insert(s);
	}
	cout << S.size() << endl;
}

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

#ifndef ONLINE_JUDGE
    #define gc getchar
    #define pc putchar
#else
    #define gc getchar_unlocked
    #define pc putchar_unlocked
#endif

using namespace std;

#define vi vector<int>
#define si set<int>
#define vs vector<string>
#define pii pair<int,int>
#define vpi vector<pii>
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define mpi map<int,int>
#define i64 long long int
#define endl '\n'
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf INT_MAX/2
#define infll LLONG_MAX/3
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define eps 1e-8
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define dbg(i) printf("yo %d\n", i)
#define foreach(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define sqr(a) (a) * (a)
#define clr clear()
#define CASE(a) printf("Case %d: ",a)

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


//i64 gcd(i64 a,i64 b){if(!b)return a;return gcd(b,a%b);}

//inline void fastRead(int *a){register char c=0;while(c<33)c=gc();*a=0;while(c>33){*a=*a*10+c-'0';c=gc();}}

//inline void fastWrite(int a){char snum[20];int i=0;do{snum[i++]=a%10+48;a=a/10;}while(a!=0);i=i-1;while(i>=0)pc(snum[i--]);pc('\n');}

//i64 bigmod(i64 num,i64 n){if(n==0)return 1;i64 x=bigmod(num,n/2);x=x*x%mod;if(n%2==1)x=x*num%mod;return x;}

//i64 modinverse(i64 num){return bigmod(num,mod-2)%mod;}

//i64 po(i64 a,i64 b){i64 ans=1;while(b--)ans *= a;return ans;}

//i64 ncr(i64 n,i64 r){if(n==r)return 1;if(r==1)return n;if(dp[n][r]!=-1)return dp[n][r];return dp[n][r]=ncr(n-1,r)+ncr(n-1,r-1);}


// bit manipulations

//bool checkbit(int mask,int bit){return mask & (1<<bit);}

//int setbit(int mask,int bit){ return mask  (1<<bit) ; }

//int clearbit(int mask,int bit){return mask & ~(1<<bit);}

//int togglebit(int mask,int bit){return mask ^ (1<<bit);}

vi v;

int f(int l,int r)
{
        int sum1 = abs(v[l]) + abs(v[r]-v[l]);
        int sum2 = abs(v[r]) + abs(v[r]-v[l]);

//        cout << l << " " << r << " " << sum1 << " " << sum2 << endl;
        return min(sum1,sum2);
}

int main()
{
        int n,k,inp;
        sff(n,k);

        while(n--)
        {
                sf(inp);
                v.pb(inp);
        }


        int ans = inf;

        For(i,v.sz)
        {
                int r = i + k - 1;
                if(r>=v.sz)
                        continue;

                ans = min( ans , f( i , r ) );
        }



        cout << ans << endl;









        return 0;
}




Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
using namespace std;
int s,sum,digit[23000005];
long long ans,tmp=1;
inline void init(){
	for(register int i=1;i<=23000000;i++){
		digit[i]=digit[i/10]+1;
	}
}
inline long long quick_pow(long long x,int p,int m){
	long long result=1;
	while(p>0){
		if(p&1==1){
			result*=x;result%=m;
		}
		p=p>>1;
		x*=x;x%=m;
	}
	return result;
}
int main(){
	init();
	scanf("%d",&s);
	for(register int i=1;i<10000000;i++){
		while(sum<s){
			sum+=digit[tmp];
			tmp++;
		}
		if(sum==s){
			ans++;ans%=1000000007;
		}
		sum-=digit[i];
	}
	for(register int i=1;i<=s/8;i++){
		switch(s%i){
			case 0:tmp=quick_pow(10,s/i-1,1000000007)*9-i+1;
				   tmp%=1000000007;tmp=(tmp+1000000007)%1000000007;
				   ans+=tmp;ans%=1000000007;break;
			default:ans++;ans%=1000000007;break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define ll long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()

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

    double pi = 3.14159265358979323846;
    int r;
    cin >> r;
    printf("%.4lf", 2 * pi * r);
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
#include<string.h>
#define pb push_back
#define endl "\n"
#define ll long long int
#define MOD 1000000007
#define mul(n) n<<1 //multiply by 2;
#define di(n) n>>1 //division by 2;
#define powof2(n) 1<<n //finding power of 2
#define ans(n) (n&(n-1)==0) //check if number is power of 2;
#define statusofxbit(n,x) (n&(1<<x-1)==0) //get the status of xth bit from the right;
#define setthexthbit(n,x) n|(1<<x-1)
#define togglexthbit(n,x) n^(1<<x-1)
#define equalno(a,b) if(a^b==0) cout<<1<<endl; else cout<<0<<endl;
#define xortwotogetthird c=a^b
#define resettherightmostsetbit(n) n&(n-1)
#define Bitlength(n) len=0; while(n){len+=1;n>>=1;};
#define noofsetbits(n) __builtin_popcount(n);
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    const int MAX = 200000;
    string s;
    cin >> s;
    int n = s.length();
    reverse(s.begin(), s.end());
    int a[MAX + 1], b[MAX + 1];
    for (ll i = 0; i < (n); i++){
        a[i] = s[i] - '0';
    }
    int num = 1;
    b[n - 1] = 0;
    for (ll i = 0; i < (n); i++) {
        b[i + 1] = (num * a[i] + b[i]) % 2019;
        num = (10 * num) % 2019;    
    }
    ll cnt[2019] = {};
    for (ll i = 0; i < (n + 1); i++){
        cnt[b[i]] ++;
    }
    ll ans = 0;
    for (ll i = 0; i < 2019; i++) {
        if (cnt[i] > 1) ans += (cnt[i] * (cnt[i] - 1)) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5332
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;cin>>n>>k;
	int ls[n+1]={};
	while(k--){
		int d;cin>>d;
		while(d--){
			int a;cin>>a;
			if(!ls[a]){ n--;ls[a]=1;}
		}
	}
	cout<<n;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  ans = a + b + c;
  int m = max(a, max(b, c));
  ans -= m;
  rep(i, k) {
    m *= 2;
  }
  ans += m;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Fri Mar 20 22:48:43 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import deque

h, w = na()
m = nsn(h)

def bfs():
    q = deque()
    al = 0
    f = False
    if m[0][0] == '#':
        al += 1
        f = True
    q.append((0, 0, al, f))
    d = [[inf] * w for _ in range(h)]
    res = inf
    dx, dy = [0, 1], [1, 0]
    while len(q):
        p = q.popleft()
        x, y, l, flag = p
        for i in range(2):
            nx, ny = x + dx[i], y + dy[i]
            nl = l
            if nx >= 0 and nx < w and ny >= 0 and ny < h and d[ny][nx] > nl:
                if m[ny][nx] == '#':
                    if not flag:
                        nl += 1
                    q.append((nx, ny, nl, True))
                else:
                    q.append((nx, ny, nl, False))
                d[ny][nx] = min(d[ny][nx], nl)
    return d[h - 1][w - 1]

print(bfs())

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
	//入力
	int n,s,k;
  	bool ans = false;
	cin >> n;
  	k=n;
	//処理
  	while (k != 0){
      	s += k%10;
    	k = k/10;
    }
  	if (n%s==0) ans = true; 
	//出力
    if(ans){
	cout << "Yes" << endl;
    }
  	else{
  	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int gcd(int a, int b) {
  if (a < b) {
    return gcd(b, a);
  }

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, X;
  cin >> N >> X;
  vector<int> xs;
  for (int i = 0; i < N; ++i) {
    int xi;
    cin >> xi;
    xs.push_back(xi);
  }

  vector<int> diffs;
  for (auto &e : xs) {
    diffs.push_back(abs(X - e));
  }

  int ans = INT_MAX;
  int first = diffs[0];
  for (int i = 0; i < N; ++i) {
    ans = min(ans, gcd(first, diffs[i]));
  }

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

Measured memory_bytes: 1400
k, a, b = map(int, input().split())

if b-a <= 1:
    print(k+1)
else:
    if k <= a-1:
        print(1+k)
    elif k == a:
        print(1+k)
    else:
        k -= a-1
        print(b + ((k-2)//2)*(b-a) + k % 2)


Measured memory_bytes: 38384
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
    ll n; cin>>n;
    n*=(n-1);
    n/=2;
    cout<<n;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1; //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

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

int main(void){
    int n; cin >> n;
    int t=0,x=0,y=0;
    for(int i=0;i<n;i++){
        int next_t,next_x,next_y; cin >> next_t >> next_x >> next_y;
        int dt = next_t-t, dx = abs(next_x-x), dy=abs(next_y-y), sum=dx+dy;
        if(sum <= dt && (sum)%2==dt%2){
            x=next_x;y=next_y;t=next_t;
            continue;
        }else{
            cout << "No"<< endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int k, s, ans = 0;
	cin >> k >> s;
	for(int x = 0; x <= k; x++) {
		for(int y = 0; y <= k; y++) {
			int z = s - x - y;
			if((0 <= z)&&(z <= k)) {
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# 長方形の4点のうち3点が必要なので自明からほど遠い
# x,yを2部グラフ、格子を辺とみなす
# 連結成分ごとに張られる......
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

mx =0
my = 0
for i in range(n):
    mx = max(mx,xy[i][0])
    my = max(my,xy[i][1])

*p, = range(mx+my+1)
rank = [1]*(mx+my+1)

for i in range(n):
    xy[i][1] += mx

def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    rx = rank[px]; ry = rank[py]
    if ry < rx:
        p[py] = px
    elif rx < ry:
        p[px] = py
    else:
        p[py] = px
        rank[px] += 1
    return 1

for x,y in xy:
    unite (x,y)

xp = [0]*(mx+my+1)
yp = [0]*(mx+my+1)

for i in range(mx+my+1):
    if i<=mx:
        xp[root(i)]+=1#p[i]では不十分
    else:
        yp[root(i)]+=1
ans = 0
for i in range(mx+my+1):
    ans += xp[i]*yp[i]
ans -= n
print(ans)


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

int main(){
 int n, k, x, y, i, sum=0;
 cin>>n>>k>>x>>y;
 if(n>k){
  for(i=1;i<=k;i++)sum+=x;
  for(i=k+1;i<=n;i++)sum+=y;
 }else for(i=1;i<=n;i++)sum+=x;
 cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;

int N,A[1010]; long long s[2];
bool c[1010];

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<=N;i++){
		scanf ("%d",&A[i]);
		if (A[i] > 0) s[i%2] += A[i];
	}

	int p = s[0] < s[1] ? 1 : 0;
	if (s[p] == 0){
		int n = 1;
		for (int i=1;i<=N;i++) if (A[n] < A[i]) n = i;
		printf ("%d\n%d\n",A[n],N-1);
		for (int i=N;i>n;i--) printf ("%d\n",i);
		for (int i=1;i<n;i++) puts("1");
	}
	else{
		for (int i=p?1:2;i<=N;i+=2) if (A[i] > 0) c[i] = 1;
		printf ("%lld\n",s[p]);

		vector<int> ans;
		while (N > 1){
			if (c[N] == 0){
				ans.push_back(N);
				N--;
			}
			else{
				if (N >= 3 && c[N-2]){
					ans.push_back(N-1);
					N -= 2;
				}
				else if (N >= 4){
					ans.push_back(N-2);
					c[N-2] = 1;
					N -= 2;
				}
				else{
					ans.push_back(1);
					c[N-1] = 1;
					N--;
				}
			}
		}

		printf ("%d\n",ans.size());
		for (auto &p : ans) printf ("%d\n",p);
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int coin = 0;
		if(A > B) {
			coin = A * 2 - 1;
		} else if(A == B) {
			coin = A * 2;
		} else {
			coin = B * 2 - 1;
		}
		System.out.println(coin);
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int cnt[100005];
int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++){
		int a;cin>>a;
		cnt[a]++;cnt[a+1]++;
		if(a>0)cnt[a-1]++;
	}
	int mx=0;
	for(int i=0;i<100005;i++){
		mx=max(mx,cnt[i]);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 3936
import numpy as np

N = int(input())
p = list(map(int, input().split()))
sort_p = sorted(p)
if p == sort_p:
    print('YES')
else:
    p = np.array(p)
    sort_p = np.array(sort_p)
    index = np.where(p != sort_p)
    if len(p[index]) == 2:
        p[index[0][0]],p[index[0][1]] = p[index[0][1]],p[index[0][0]]
        p = list(p)
        sort_p = list(sort_p)
        if p == sort_p:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')

Measured memory_bytes: 12500