akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
    cin>>n;
    int s=0;
    m=n;
    while(m){
        s+=m%10;
        m/=10;
    }
    if(s>1 ||( s==1 && n==1))
        cout<<s;
    else
        cout<<10;
        return 0;

}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = input()
T = input()

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 
def lcm(x, y):
    return (x * y) // gcd(x, y)

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

success = False
fans = 0

_lcm = lcm(len(S), len(T))

def isImpble(k, _lcm):
    global success
    global S
    global T
    global fans
    
    ans = k * _lcm
    double_st = []
    
    for i in range(len(S)):
        if (len(T)*i)%len(S) == 0 and (len(T) * i)//len(S) <len(T):
            double_st += [(i * ans)//len(S) + 1]
    isImpossible = False

    for st in double_st:
        s_i = ((st-1) * len(S))//ans
        t_i = ((st-1) * len(T))//ans
        if S[s_i] != T[t_i]:
            isImpossible = True
            break

            
    if isImpossible:
        return True
    else:
        success = True
        fans = k*_lcm
        return False
        

imp = isImpble((len(S) * len(T))//_lcm, _lcm)

if not imp:
    for k in range(1, (len(S) * len(T))//_lcm ):
        imp = isImpble(k, _lcm)
        if success:
            break
    

if not success:
    print(-1)
else:
    print(fans)

Measured memory_bytes: 4328
import numpy as np

n,k,q = map(int, input().split())

a = np.array([0]*n)

for _ in range(q):
    ans = int(input())
    a[ans-1] += 1

for i in range(n):
    if q - a[i] < k:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 28104
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(x) memset(x, 0, sizeof x)
#define mem1(x) memset(x, -1, sizeof x)
#define MX 100005
ll arr[MX][3],arr2[MX],arr3[MX], dp[MX][3],n;
//ll rec(ll i, ll score)
//{
//    if(i==n-1) return score;
//    else if(i>=n) return 1e9;
//    else if(dp[i]<score && dp[i]!=-1) return dp[i];
//    else if(!i || dp[i]==-1 || score<dp[i])
//    {
//        ll ret1=1e9, ret2=1e9;
//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));
//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));
//        return dp[i]=min(ret1,ret2);
//    }
//}
int main()
{
    ll i,j,k,l, m;
    scanf("%lld",&n);
    for(i=0; i<n; i++) scanf("%lld%lld%lld",&arr[i][0],&arr[i][1],&arr[i][2]);
//    for(i=1; i<n; i++) dp[i]=1e9;
    for(i=1; i<n; i++)
    {
        for(j=0; j<3; j++)
        {
            ll mx=0;
            for(k=0; k<3; k++)
                if(k!=j) mx=max(arr[i-1][k],mx);
            arr[i][j]+=mx;
        }
    }
    printf("%lld\n",max(arr[n-1][0], max(arr[n-1][1],arr[n-1][2])));
    return 0;
}


Measured memory_bytes: 4480
// IN THE NAME OF ALLAH
#include <math.h>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include<cstring>

#define F first
#define S second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5 + 10 , M = 2e5+10 , MOD = 1e9 + 7 , MAXN = 1e5 + 10;
const ll inf = 2e9 + 10;

#define int ll
int l[N] , r[N] , pos[N] , d[N] , dis[N] , mn , mx;
vector <pii> vl[N] , vr[N];
vector <int> vec;
bool mark[N];
set <pii> s;

void dfs ( int u , int p)
{
      s.erase(mp(d[u] , u));
      mx = max(mx , p);
      mn = min(mn , p);
      vec.push_back(u);
      pos[u] = p;
      mark[u] = 1;
      for( int i = 0 ; i < vr[u].size() ; i++){
            if(!mark[vr[u][i].F]){
                  dfs(vr[u][i].F , p + vr[u][i].S);
            }
            else{
                  if(pos[vr[u][i].F] != p + vr[u][i].S){
                        cout << "No";
                        exit(0);
                  }
            }
      }
      for( int i = 0 ; i < vl[u].size() ; i++){
            if(!mark[vl[u][i].F]){
                  dfs(vl[u][i].F , p - vl[u][i].S);
            }
            else{
                  if(pos[vl[u][i].F] != p - vl[u][i].S){
                        cout << "No";
                        exit(0);
                  }
            }
      }

}
int32_t main()
{
      ios_base::sync_with_stdio(false);
      int n , m;
      cin>>n>>m;
      int now = 0;
      for( int i = 0 ; i < m ; i++ )
      {
            cin>>l[i]>>r[i]>>dis[i];
            vr[l[i]].push_back( mp(r[i] , dis[i]) );
            vl[r[i]].push_back( mp(l[i] , dis[i]) );
            d[r[i]]++;
      }
      for(int i = 1 ; i <= n ; i++)
            s.insert(mp(d[i] , i));
      while(s.size())
      {
            vec.clear();
            mn = inf;
            mx = 0;
            pii x = *s.begin();
            if(x.F > 0)
                  return cout << "No" , 0;
            s.erase(s.begin());
            dfs(x.S , now);
            int cnt = 0;
            if(mn < now)
                  cnt = now - mn;
            for(int i = 0 ; i < vec.size() ; i++)
                  pos[vec[i]] += cnt;
            now = mx + 1;
      }
      cout << "Yes";
      return 0;
}


Measured memory_bytes: 34804
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define test int t;cin>>t;while(t--)
#define INF 10000000
#define pi 3.141592
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n" 
#define pb push_back
//#include "debug.cpp"
//__builtin_popcount

int32_t main()
{
    fast
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.length();i++)
    {
        sum+=s[i]-'0';
    }
    if(sum%9)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
        
    
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

VL primes;
bool is_prime[1145];
int fact[1145] = {};

void factor(int n){
    if(is_prime[n]){
        fact[n]++;
        return;
    }

    for(int i=0;primes[i]<=n;i++){
        if(is_prime[n]){
            fact[n]++;
            return;
        }
        if(n%primes[i]==0){
            fact[primes[i]]++;
            n /= primes[i];
            i--;
        }
    }
}

void sieve(int n){
    for(int i=0;i<=n;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            primes.pb(i);
            for(int j=2*i;j<=n;j += i) is_prime[j] = false;
        }
    }
    return;
}

signed main(){
    int n;
    scanf("%lld",&n);
    sieve(n);

    for(int i=2;i<=n;i++) factor(i);

    //REP1(i,n) printf("%lld ",fact[i]);
    
    int ans = 1;
    for(int i=1;i<=n;i++){
        if(fact[i]){
            ans *= fact[i]+1;
            ans %= MOD;
        }
    }

    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

    int N;
    ll X;
    
    cin >> N >> X;

    vector<ll> x(N);

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

    for(int i = 0; i < N; i++){
        x[i] = abs(x[i]-X);
    }

    // x[i]の最大公約数を求める

    if(x.size() > 1){
        int ans = 0;
        ans = gcd(x[0], x[1]);

        for(int i = 2; i < N; i++){
            ans = gcd(ans, x[i]);
        }

        cout << ans << endl;
    }else{
        cout << x[0] << endl;
    }


    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define rep(i,n) for(i=0;i<n;i++)
double max(double a,double b){return a>b?a:b;}
int main(void)
{
  int n,m,i,j,k,t;
  double mat[100][100],dp[2][100],res;
  for(;;){
    scanf("%d%d",&n,&m); if(!n)break;
    rep(i,n)rep(j,n)scanf("%lf",mat[i]+j);
    t=0;res=0;
    rep(i,n)dp[1][i]=0,dp[0][i]=1;
    rep(i,m){rep(j,n)rep(k,n)dp[t^1][j]=max(dp[t^1][j],dp[t][k]*mat[j][k]);
      t^=1;
    }
    rep(i,n)res=max(res,dp[t^1][i]);
    printf("%.2f\n",res);
  }
  return 0;
}

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

double dist(vector<pair<int,int>> &p,int from,int to){
    int x1 = p[from].first, x2 = p[to].first;
    int y1 = p[from].second, y2 = p[to].second;
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int fact(int n){
    int res = 1;
    for(int i = 1;i <= n;i++) res *= i;
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    vector<int> root(n);
    iota(root.begin(),root.end(),0);
    double ans = 0;
    do {
        rep(i,n-1){
            int from = root[i];
            int to = root[i+1];
            ans += dist(p,from,to);
        }
    } while (next_permutation(root.begin(),root.end()));
    ans /= fact(n);
    printf("%.10lf\n",ans);
}

Measured memory_bytes: 3876
#include <bits/stdc++.h>
#define lg2 std::__lg

typedef long long ll;
const int N = 530000, mod = 924844033, root = 3597;
typedef int vec[N], *pvec;

vec fact, finv;

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

void init(int n) {
	int i;
	for (*fact = i = 1; i <= n; ++i) fact[i] = (ll)fact[i - 1] * i % mod;
	finv[n] = PowerMod(fact[n], mod - 2);
	for (i = n; i; --i) finv[i - 1] = (ll)finv[i] * i % mod;
}

inline ll C(int n, int r) {return (ll)fact[n] * finv[r] % mod * finv[n - r] % mod;}

namespace Poly {
	int l, n;
	vec rev, x, y;

	void NTT_init(int len) {
		if (l == len) return; n = 1 << (l = len);
		ll g = PowerMod(root, 1 << (21 - l));
		*x = 1, *rev = 0;
		for (int i = 1; i < n; ++i)
			x[i] = x[i - 1] * g % mod, rev[i] = rev[i >> 1] >> 1 | (i & 1) << (l - 1);
	}

	void DNTT(int *d, int *t) {
		int i, *j, *k, len = 1, delta = n, R;
		for (i = 0; i < n; ++i) t[rev[i]] = d[i];
		for (i = 0; i < l; ++i) {
			delta >>= 1;
			for (k = x, j = y; j < y + len; k += delta, ++j) *j = *k;
			for (j = t; j < t + n; j += len << 1)
				for (k = j; k < j + len; ++k)
					R = (ll)y[k - j] * k[len] % mod,
					k[len] = (*k - R < 0 ? *k - R + mod : *k - R),
					*k = (*k + R >= mod ? *k + R - mod : *k + R);
			len <<= 1;
		}
	}

	vec B1;

	void Mul(int deg, pvec a, pvec b, pvec c) {
		if (!deg) {*c = (ll)*a * *b % mod; return;}
		NTT_init(lg2(deg) + 1);
		int i; ll iv = mod - (mod - 1) / n;
		DNTT(a, c), DNTT(b, B1);
		for (i = 0; i < n; ++i) B1[i] = (ll)B1[i] * c[i] % mod;
		DNTT(B1, c), std::reverse(c + 1, c + n);
		for (i = 0; i < n; ++i) c[i] = c[i] * iv % mod;
	}
}

int n, E = 0;
int to[N], first[N], next[N];
vec f, g;

inline void addedge(int u, int v) {
	to[++E] = v, next[E] = first[u], first[u] = E;
	to[++E] = u, next[E] = first[v], first[v] = E;
}

int dfs(int x, int px = 0) {
	int i, y, S = 1;
	for (i = first[x]; i; i = next[i])
		if ((y = to[i]) != px) S += dfs(y, x);
	return ++f[S], ++f[n - S], S;
}

int main() {
	int i, u, v, ans;
	scanf("%d", &n), init(n);
	for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
	dfs(1), *f = f[n] = 0;
	for (i = 1; i < n; ++i) f[i] = (ll)fact[n - i] * f[i] % mod;
	Poly::Mul(2 * n - 1, f, finv, g);
	for (i = 1; i <= n; ++i)
		ans = (n * C(n, i) - (ll)finv[i] * g[n - i]) % mod,
		printf("%d\n", ans + (ans >> 31 & mod));
	return 0;
}

Measured memory_bytes: 32640
from math import ceil
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())
a = t1 * (a1 - b1)
b = t2 * (a2 - b2)
if a > 0:
    a *= -1
    b *= -1
if a + b < 0:
    print(0)
elif a + b > 0:
    if (-1 * a) % (a + b):
        print(((-1 * a) // (a + b)) * 2 + 1)
    else:
        print((-1 * a) // (a + b) * 2)
else:
    print("infinity")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#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 = (b) - 1;i >=a;--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}


using ll = long long;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int clamp(int n, int a, int b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

ll gcd(ll a, ll b) {
    ll v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    A--;
    ll a = A - A / C - A / D + A / lcm(C, D);
    ll b = B - B / C - B / D + B / lcm(C, D);
    cout << b - a << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S, T;
    cin >> S >> T;
    vector<vector<int>> A(26, vector<int>());
    for (int i = 0; i < S.size(); i++) {
        A.at(S.at(i) - 'a').push_back(i);
    }
    for(int i = 0; i < S.size(); i++) {
        if (S.at(i) != T.at(i)) {
            char c = S.at(i), d = T.at(i);
            int a = S.at(i) - 'a', b = T.at(i) - 'a';
            for (int j = 0; j < A.at(a).size(); j++) {
                S.at(A.at(a).at(j)) = d;
            }
            for (int j = 0; j < A.at(b).size(); j++) {
                S.at(A.at(b).at(j)) = c;
            }

            swap(A.at(a), A.at(b));
            
            if (A.at(a).size() > 0) {
                if (A.at(a).at(0) < i) {
                    cout << "No" << endl;
                    return 0;
                }
            }
            if (A.at(b).size() > 0) {
                if (A.at(b).at(0) < i) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;

}


Measured memory_bytes: 1800
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

// 入力
int N, M;
vector<vector<int> > G; // グラフ
int dp[100100];
int rec(int v) {
  if (dp[v] != -1) return dp[v]; // 既に更新済み

  int res = 0;
  for (auto nv : G[v]) {
    res = max(res, rec(nv) + 1);
  }
  return dp[v] = res; // メモしながらリターン
}

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);

  // 入力受け取り
  cin >> N >> M;
  G.assign(N, vector<int>());
  for (int i = 0; i < M; ++i) {
    int x, y; cin >> x >> y;
    --x, --y; // 0-indexed にする
    G[x].push_back(y);
  }

  // 初期化
  for (int v = 0; v < N; ++v) dp[v] = -1;

  // 全ノードを一通り更新しながら答えを求める
  int res = 0;
  for (int v = 0; v < N; ++v) res = max(res, rec(v));
  cout << res << endl;


  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 998244353;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
  
const ll MAX_N = 1e6 + 10;

struct SegTree {
    ll tree[4 * MAX_N], lazy[4 * MAX_N];

    void build(ll n) {
    	for(ll i = 0; i < 4 * MAX_N; i ++) {
    		lazy[i] = MAX_N;
    		tree[i] = n;
    	}
    }

    void push(ll curr, ll l, ll r) {
    	if(lazy[curr] == MAX_N) {return;}
        tree[curr] = lazy[curr];
        if(l != r) {
            lazy[curr * 2] = lazy[curr]; lazy[curr * 2 + 1] = lazy[curr];
        }
        lazy[curr] = MAX_N;
    }

    void upd(ll curr, ll l, ll r, ll ql, ll qr, ll val) {
        push(curr, l, r);
        if(ql <= l && r <= qr) {
            lazy[curr] = val;
            push(curr, l, r);
            return;
        } else if(l > qr || r < ql) {return;}
        ll m = (l + r) / 2;
        upd(curr * 2, l, m, ql, qr, val);
        upd(curr * 2 + 1, m + 1, r, ql, qr, val);
        tree[curr] = min(tree[curr * 2], tree[curr * 2 + 1]);
    }

    ll query(ll curr, ll l, ll r, ll ql, ll qr) {
        push(curr, l, r);
        if(ql <= l && r <= qr) {
            return tree[curr];
        } else if(l > qr || r < ql) {return MAX_N;}
        ll m = (l + r) / 2;
        return min(query(curr * 2, l, m, ql, qr), query(curr * 2 + 1, m + 1, r, ql, qr));
    }
};

SegTree lft, up;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n, q;
    cin >> n >> q;
    ll ans = (n - 2) * (n - 2);
    lft.build(n - 1);
    up.build(n - 1);
    ll mstlft = MAX_N, mstup = MAX_N;
    for(ll i = 0; i < q; i ++) {
    	ll t, a;
    	cin >> t >> a;
    	a --;
    	if(t == 1) {
    		ll width = up.query(1, 0, n - 1, a, a);
    		ans -= width - 1;
    		if(a < mstlft) {
    			lft.upd(1, 0, n - 1, 0, width, a);
    			mstlft = a;
    		}
    	} else {
    		ll width = lft.query(1, 0, n - 1, a, a);
    		ans -= width - 1;
    		if(a < mstup) {
    			up.upd(1, 0, n - 1, 0, width, a);
    			mstup = a;
    		}
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 128668
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string.h>
using namespace std;

#define HUNDRED 100
#define THOUSAND 10000
#define TENTHOUSAND 10000
#define HUNDREDTHOUSAND 100000

int kaibun(int number);

int main() {
	int a, b;
	int count = 0;

	cin >> a >> b;

	for (int i = 0; (a + i) <= b; i++) {
		if (kaibun(a + i) != -1) {
			count++;
		}
	}

	cout << count;

}

int kaibun(int number) {
	int temp[HUNDREDTHOUSAND];
	int temp1;
	int digit = 0;

	temp1 = number;

	for (int i = 0; temp1 > 0; i++) {
		temp[i] = (temp1 % 10);
		temp1 /= 10;
		digit++;
	}

	// initialize
	temp[digit] = -1;

	digit -= 1;

	for (int i = 0; temp[i] != -1; i++) {
		if (temp[i] != (int) (number / pow(10, digit))) {
			return -1;
		}
		int temp2;
		temp2 = (int) pow(10, digit);
		number %= temp2;
		digit--;
	}

	return 1;

}


Measured memory_bytes: 384
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , l[N] , r[N];
multiset<ll> lpts , rpts;

int main(){
  scanf("%d",&n);
  rep(i,0,n) scanf("%d%d",l+i,r+i);
  lpts.insert(l[0]);
  rpts.insert(l[0]);
  ll dL = 0 , dR = 0;
  ll ans = 0;
  rep(i,1,n) {
    dL -= r[i] - l[i];
    dR += r[i-1] - l[i-1];
    ll L = *lpts.rbegin()+dL;
    ll R = *rpts.begin()+dR;
    if(l[i] < L) {
      auto it=lpts.end();lpts.erase(--it);
      ans += L - l[i];
      lpts.insert(l[i]-dL);
      lpts.insert(l[i]-dL);
      rpts.insert(L-dR);
    } else if(l[i] > R) {
      auto it=rpts.begin();rpts.erase(it);
      ans += l[i] - R;
      rpts.insert(l[i]-dR);
      rpts.insert(l[i]-dR);
      lpts.insert(R-dL);
    } else {
      lpts.insert(l[i]-dL);
      rpts.insert(l[i]-dR);
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 10368
import math

N, D = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
  dist = L[i][0] ** 2 + L[i][1] ** 2
  if math.sqrt(dist) <= D:
    ans += 1

print(ans)

Measured memory_bytes: 45340
S = input()
s1,s2 = map(int, [S[:2],S[2:]])
if all(map(lambda x: x in range(1,13), [s1,s2])): ans = "AMBIGUOUS"
elif s1 in range(1,13): ans = "MMYY"
elif s2 in range(1,13): ans = "YYMM"
else: ans = "NA"
print(ans)

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

int main()
{
	string t, h;
        int n, tp = 0, hp = 0;

        cin >> n;

        while (n-- && cin >> t >> h) {
            int i = 0;
            for (int m = min(t.size(), h.size()); i < m && t[i] == h[i]; i++)
                ;
            if (t[i] == h[i])
                tp++, hp++;
            else if (t[i] > h[i])
                tp += 3;
            else
                hp += 3;
        }

        cout << tp << " " << hp << endl;

	return 0;
}



Measured memory_bytes: 3160
import qualified Data.Vector as V
import Data.Array

odd_solver::V.Vector Char->Int
odd_solver v = let m = div (V.length v) 2 in
               let s = div (V.length (last (filter same [V.slice (m-s) ((2*s)+1) v |s <- [0..m]]))) 2in
               m+s+1

even_solver::V.Vector Char->Int
even_solver v = let m = div (V.length v) 2 in
                let s = div (V.length (last (filter same [V.slice (m-s) (2*s) v | s <- [0..m]]))) 2 in
                m+s

same::V.Vector Char->Bool
same v        =if v == V.empty then True else V.foldl (\ b -> \ x -> ((V.head v)==x)&&b) True v

total_solver::String->Int
total_solver ls = let v = V.fromList ls in
                  if mod (V.length v) 2 == 1 then odd_solver v else even_solver v




impl_odd::Array Int Char->Int->Int
impl_odd ar size = let m = div size 2 in
                  m+1+(foldl_with_cond (\s -> \(i,j) -> s+1) (-1)  (\(i,j)->(ar!i==ar!(m+1))&&(ar!j==ar!(m+1))) [(m+1-j,m+1+j)|j<-[0..m]])


impl_even::Array Int Char->Int->Int
impl_even ar size = let m = div size 2 in
                   m+(foldl_with_cond (\s -> \(i,j)->s+1) 0 (\(i,j)->(ar!i==ar!(m+1))&&(ar!j==ar!(m+1))) [(m+j,m-j+1)|j<-[1..m]])



foldl_with_cond::(a->b->a)->a->(b->Bool)->[b]->a
foldl_with_cond _ now _    []    = now
foldl_with_cond f now cond (x:xs)= if cond x then foldl_with_cond f (f now x) cond xs
                                            else now

impl_total::String->Int
impl_total ls = let n = length ls in
                let ar = listArray (1,n) ls in
                if mod n 2 == 1 then impl_odd ar n else impl_even ar n

main::IO()
main=do
  str<-getLine
  print (impl_total str)


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

using namespace std;

int main(){
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i=i+1)
    {
        cin>>a[i];
    }
    int mn = 0, cnt = 0;
    for(i=0;i<n;i=i+1)
    {
        if(a[i] >= mn)
        {
            cnt = cnt + 1;
            mn = a[i];
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 256
n = int(input())
s_list = []
for i in range(n):
    s_list.append(input())

def countAB(str):
    count = 0
    for i in range(len(str)-1):
        if (str[i] == 'A') & (str[i+1] == 'B'):
            count += 1
    return(count)

def countRest(x, y, z):
    if(x > 0) | (y > 0):
        count = z + min(x, y)
    else:
        if(z > 1):
            count = z - 1
        else:
            count = 0
    return(count)

count = 0
count_bxa = 0
count_xa = 0
count_bx = 0
for s in s_list:
    count += countAB(s)
    if ((s[-1] == 'A') & (s[0] == 'B')):
        count_bxa += 1
    elif (s[-1] == 'A'):
        count_xa += 1
    elif (s[0] == 'B'):
        count_bx += 1

print(count + countRest(count_xa, count_bx, count_bxa))


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

int main() { 
 string s, t; 
 cin >> s >> t; 
 int ans = 0; 
 if(s[0] == t[0]) ans++; 
 if(s[1] == t[1]) ans++; 
 if(s[2] == t[2]) ans++; 
 cout << ans << endl; 
return 0; 
 }


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    for (auto c : S) {
        if (c == ',') cout << ' ';
        else cout << c;
    }
    cout << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007 
int p[100001];
int32_t main()
{
    fast;
    int n,m;
    cin>>n>>m;
    string s="";
    for(int i=0;i<n;i++)
    {
    	s+=(char)('0'+m);
    }
    string t="";
    for(int i=0;i<m;i++)
    {
    	t+=(char)('0'+n);
    }
    if(s<t)
    {
    	cout<<s;
    }
    else
    {
    	cout<<t;
    }


}

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

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


signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  int ans = 3000000000;
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
    if( i > 0 ){
      ans = min( ans, gcd(A.at(i-1), A.at(i)) );
    }
  }
  cout << ans << endl;
  
  
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long all = 0;
        for (int i=0; i<n; i++) {
            a[i] = sc.nextLong();
            all = all ^ a[i];
        }
        for (int i=0; i<n; i++) {
            System.out.print((a[i] ^ all) + " ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 55752
from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) == sum(b):
    print(n)
mp = 0
ans = 0
l = []
for i in range(n):
    if a[i] < b[i]:
        mp -= b[i] - a[i]
    elif a[i] >= b[i]:
        mp += a[i] - b[i]
        l.append(a[i] - b[i])
l.sort()
if mp < 0:
    print(-1)
else:
    for i in range(len(l) - 1):
        l[i + 1] += l[i]
    print(n - bisect_right(l, mp))

Measured memory_bytes: 19188
n=int(input())
F=[input().split() for _ in range(n)]
P=[list(map(int,input().split())) for _ in range(n)]

ans=-float("inf")
for i in range(1,2**10):
    cnt=0
    num=format(i,"b").zfill(10)
    for j,k in enumerate(F):
        cnt +=P[j][len([True for m in range(10) if k[m]==num[m]=="1"])]
    ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 43484
#include <iostream>

using namespace std;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    auto r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main() {
  int N,X,ans,x;
  cin >> N >> X >> x;
  ans = abs(x-X);
  while(cin >> x) ans = gcd(ans,abs(x-X));
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,K;
	cin >> N >> K;
  int product=1;
	if(N!=1){
		for (int i = 0; i < N-1; ++i)
		{
          
			product = product*(K-1);
		}
		cout << K*product << endl;
	}
    else{
      cout << K << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0){cout<<a-b;}
    else{cout<<b-a;}
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc079/tasks/abc079_d
#include <bits/stdc++.h>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>

using namespace std;
using namespace boost;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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

const int SZ = 10;
int cost[SZ][SZ], mcost[SZ][SZ];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, t;
    h = read();
    w = read();
    REP(i, SZ) REP(j, SZ) cost[i][j] = read();
    vector<vector<int>> v(h);
    REP(i, h) REP(j, w) {
        t = read();
        v[i].push_back(t);
    }
    // undirectedS は無向グラフ、directedS は有向グラフ
    adjacency_list<listS, vecS, directedS, no_property,
                   property<edge_weight_t, int>>
        graph1(SZ);
    REP(i, SZ) REP(j, SZ) {
        if (i != j) {
            add_edge(i, j, cost[i][j], graph1);
        }
    }

    // k からの最短距離を求める
    vector<int> dist(SZ);
    vector<int> par(SZ);
    REP(i, SZ) {
        dijkstra_shortest_paths(
            graph1, i, distance_map(dist.data()).predecessor_map(par.data()));
        REP(j, SZ) {
            mcost[i][j] = dist[j];
            // cout << mcost[i][j] << " ";
        }
        // cout << endl;
    }
    ll sum = 0;
    REP(i, h) REP(j, w) {
        int a = v[i][j];
        if (a >= 2 || a == 0) {
            sum += mcost[a][1];
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 512
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Measured memory_bytes: 27752
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			int tBit = 0;
			for(int i = 0; i < k; i++) {
				int j = sc.nextInt();
				if((tBit>>j&1)==0)
					tBit += 1<<j;
			}
			System.out.println("0:");
			for (int bit = 1; bit < (1<<n); bit++) {
				if((bit&~tBit) == 0 && (bit&tBit) != 0) {
					System.out.print(bit + ":");
					for (int j = 0; j < n; j++) {
						if (((bit>>j) & 1) == 1) {
							System.out.print(" " + j);
						}
					}
					System.out.println();
				}
			}
		}
	}
}


Measured memory_bytes: 65924
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N, M;
    cin >> N >> M;
    
    vector<int> X(M);
    vector<int> L(M-1);
    REP(i, M) {
        cin >> X[i];
    }
    sort(ALL(X));

    REP(i, M-1) {
        L[i] = X[i+1] - X[i];
    }

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }
    
    sort(RALL(L));

    int cnt = X[M-1] - X[0];
    // cout << cnt << endl;
    
    for(int i = 0; i < N-1; i++) {
        cnt -= L[i];
        // cout << cnt << endl;
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	int n;
	scanf("%d", &n);
	int arr[n];
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		mp[arr[i]]++;
	}
	sort(arr , arr+n);
	int m;
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int num;
		cin >> num;
		if (binary_search(arr, arr + n, num) && mp[num] > 0) {
			mp[num]--;
		} else
			return cout << "NO\n", 0;
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 13796
def absolute(N,K):
    return abs(N-K)
    
N,K=map(int,input().split())
 
N=N%K
valuelist = []
 
for i in range (0,2):
    i+=1
    N=absolute(N,K)
    valuelist.append(absolute(N,K))
            
print(min(valuelist))

Measured memory_bytes: 3060
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

getParms :: IO [Int]
getParms = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [a,b,c,x,y] <- getParms
  print $ f a b c x y

f :: Int -> Int -> Int -> Int -> Int -> Int
f a b c x y
  | 2*c < a + b = min (2*c * (min x y) + g a b x y) (2*c*max x y)
  | otherwise   = a*x + b*y
  where
    g a b x y
      | x < y     = (y-x)*b
      | otherwise = (x-y)*a

Measured memory_bytes: 380
import java.io.BufferedReader;
import java.io.IOException;

public class Main {

	public BufferedReader br;

	/**
	 * メイン処理
	 * @throws IOException
	 */
	public void Proc() throws IOException {
		int itemCount = Integer.parseInt(br.readLine());
		String[] srcItems = new String[itemCount];
		srcItems = br.readLine().split(" ");

		String[] bubble = new String[itemCount];
		bubble = srcItems.clone();
		String[] selection = new String[itemCount];
		selection = srcItems.clone();

		/*
		 * BubbleSort(C)
			1 for i = 0 to C.length-1
			2     for j = C.length-1 downto i+1
			3         if C[j].value < C[j-1].value
			4             swap C[j] and C[j-1]
		 */

		for(int i=0; i<itemCount; i++) {
			for(int j=itemCount-1; j>=i+1; j--) {
				int num1 = Integer.parseInt(bubble[j].substring(1));
				int num2 = Integer.parseInt(bubble[j-1].substring(1));
				if(num1 < num2) {
					String buff = bubble[j];
					bubble[j] = bubble[j-1];
					bubble[j-1] = buff;
				}
			}
		}

		/*
		 * 7 SelectionSort(C, N)
			8   for i = 0 to N-1
			9     minj = i
			10    for j = i to N-1
			11      if C[j].value < C[minj].value
			12        minj = j
			13    C[i] と C[minj] を交換
		 */

		for(int i=0; i<itemCount;i++) {
			int minj = i;
			for(int j=i; j<itemCount; j++) {
				int num1 = Integer.parseInt(selection[j].substring(1));
				int num2 = Integer.parseInt(selection[minj].substring(1));
				if(num1 < num2) {
					minj = j;
				}
			}
			String buff = selection[i];
			selection[i] = selection[minj];
			selection[minj] = buff;
		}


		StringBuilder ans = new StringBuilder();
		for(String item:bubble) {
			if(ans.length() > 0) {
				ans.append(" ");
			}
			ans.append(item);
		}
		String bubbleAns = ans.toString();
		ans = new StringBuilder();
		for(String item:selection) {
			if(ans.length() > 0) {
				ans.append(" ");
			}
			ans.append(item);
		}
		String selectionAns = ans.toString();

		System.out.println(bubbleAns);
		System.out.println("Stable");
		System.out.println(selectionAns);
		System.out.println((bubbleAns.equals(selectionAns)?"S":"Not s") + "table");

	}


	public static void main(String[] args)  {
		Main mn = new Main();
		mn.br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
		try {
			mn.Proc();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		} finally {
			try {
				mn.br.close();
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
		}
	}


}

Measured memory_bytes: 16996
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;cin >> N;vector<int> a(N);
    for(int i =0;i< N;i++) cin >> a[i];
    int S = a[0];
    for(int i = 1;i <N;i++) S ^=a[i];
    if (S == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
 
int atari(int,int);
int n,h;
int X[2000],Y[2000];
 
main(){
  int i,j;
   
 
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&X[i]);
 
  scanf("%d",&h);
  for(j = 0; j < h; j++)
    scanf("%d",&Y[j]);
     
   
  for(j = 0; j < h; j++)
    if(atari(n,Y[j]))
      printf("yes\n");
    else
      printf("no\n");
     
    
      
 
  return 0;
}
 
int atari(int v,int m)
{
  int p;
  if(m == X[v])
    return 1;
 
  if(v == -1)
    return 0;
 
  if(m <= 0)
    return 0;
 
  if(atari(v-1,m))
    return 1;
 
  if(atari(v-1,m-X[v]))
    return 1;
 
  return 0;
   
}

Measured memory_bytes: 584
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

	vll h(N);
	rep(i, N) cin >> h[i];

	vll dp(N, INF);
	dp[0] = 0;

	/*repl(i, 1, N)
	{
		dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));

		if (i >= 2)
		{
			dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		}
	}*/

	rep(i, N - 1)
	{
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));

		if (i < N - 2)
		{
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
		}
	}

	cout << dp[N - 1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll n, m;
    cin >> n >> m;
    ll a[m];
    for (ll i = 0; i < m; i++) cin >> a[i];
    sort(a, a + m);
    ll dist[m];
    dist[0] = 0;
    for (ll i = 0; i < m - 1; i++) {
        dist[i + 1] = a[i + 1] - a[i];
    }
    sort(dist, dist + m);
    ll ans = 0;
    if (n >= m) ans = 0;
    else{
        for (ll i = 0; i < m - n+1; i++) ans += dist[i];
    }
    cout << ans << endl;
}

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

main(){
  int X ;
  cin >> X ;
  if ( X == 7){
    cout << "YES" << endl ;
  }
  else if ( X == 5 ){
    cout << "YES" << endl ;
  }
  else if ( X == 3 ){
    cout << "YES" << endl ;
  }
  else{
    cout << "NO" << endl ; 
  }
}

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

class DisjointSet {
    public:
        vector<int> rank, p;

        DisjointSet() {}
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i=0; i<size; i++) makeSet(i);
        }

        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x, int y) {
            return findSet(x) == findSet(y);
        }

        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y) {
            if (rank[x] > rank[y]){
                p[y] = x;
            } else
            {
                p[x] = y;
                if (rank[x] == rank[y])
                {
                    rank[y]++;
                }
            }
        }
        
        int findSet(int x){
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }

};

int main(){
    int n, a, b, q;
    int t;
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);

    for (int i = 0; i < q; i++)
    {
        cin >> t >> a >> b;
        if (t == 0) ds.unite(a, b);
        else if (t == 1) {
            if (ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
}


Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
const int MOD = 1e9+17;
LL a[MAXN],c[MAXN];
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    LL n;
    cin>>n;
    LL sum = 0;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    	sum+=a[i];
    }
    bool can = true;
    if(sum%(((1LL+n)*n)/2)!=0)  can = false;
    LL cnt = sum/(((1LL+n)*n)/2);
    for (int i = 0; i < n; ++i)
    {
    	if(i==0) c[i] = a[0]-a[n-1];
    	else c[i] = a[i]-a[i-1];
    }
    LL cs = 0;
    for (int i = 0; i < n; ++i)
    {
    	if(((c[i]-cnt)%n)!=0||c[i]-cnt>0) can = false;
    	debug(c[i]);
    	debug(cnt);
    	debug((c[i]-cnt));
    	cs+=((c[i]-cnt)/n);
    	debug(cs);
    }
    if(abs(cs)!=abs(cnt)) can = false;
    if(can) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;        
}

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

int main(){
  int N;
  cin >> N;
  string S;
  cin>>S;
  
  int sum=0;
  for(int i=0;i<N-2;i++){
    if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
      sum++;
    }
  }
  cout<<sum <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
void main(void)
{
  int sum=0,n;
  char a[200000][11];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s",a[i]);
  }
  qsort(a,n,sizeof(a[0]),strcmp);
  for(int i=0;i<n;i++){
    if(strcmp(a[i],a[i+1])==0)
      sum++;
  }
  printf("%d",n-sum);
}

Measured memory_bytes: 5716
import heapq
import numpy as np
N, K = map(int,input().split())
v = list(map(int,input().split()))
res = 0
if N==1:
    print(max([0,v[0]]))
    exit()

for i in range(N):
    for j in range(N):
        if 1<=i+j<=K and i+j<=N:
            tmp = 0
            gem = []
            heapq.heapify(gem)
            for k in range(i):
                heapq.heappush(gem, v[k])
                tmp += v[k]
            for k in range(N-1,(N-1)-(j),-1):
                heapq.heappush(gem, v[k])
                tmp += v[k]
            rest = K - (i+j)
            while 1:
                if tmp != 0 and rest > 0:
                    rest -= 1
                    elem = heapq.heappop(gem)
                    if elem >= 0:
                        heapq.heappush(gem, elem)
                        break
                    tmp -= elem
                else:
                    break
            res = max([res,tmp])
print(int(res))


Measured memory_bytes: 12404