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

#define mod 1000000007
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323
#define debug(x) cout<<"Case "<<x<<": "
#define For(i,n) for(long long i=0;i<n;i++)
#define Frabs(i,a,b) for(long long i = a; i < b; i++)
#define Frabr(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;

//Handle:cyber_rajat
vector<ll> arr[100005];
bool visited[100005]={false};
vector<ll> output;

void dfs(ll start)
{
	visited[start]=true;
	for(ll i=0;i<arr[start].size();i++)
	{
		if(!visited[arr[start][i]])
			dfs(arr[start][i]);
	}
	output.pb(start);
}

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	ll n,m;
	cin>>n>>m;
	ll dp[n+5];
	for(ll i=1;i<=m;i++)
	{
		ll a,b;
		cin>>a>>b;
		arr[a].pb(b);
	}
	for(ll i=1;i<=n;i++)
	{
		if(!visited[i])
			dfs(i);
	}
	reverse(output.begin(),output.end());
	memset(dp,-1,sizeof(dp));
	for(ll i=n-1;i>=0;i--)
	{
		ll Curr_max=-1;
		for(ll j=0;j<arr[output[i]].size();j++)
		{
			Curr_max=max(Curr_max,dp[arr[output[i]][j]]);
		}
		dp[output[i]]=Curr_max+1;
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8948
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<memory.h>
#include<ctime>
#include<cstdio>
#include<map>
#include<stack>

using namespace std;

int main()
{
	string s;
	long long ans=0;
	cin>>s;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]!=s[i-1])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
ll A,B;
char c;
int main(void){
    scanf("%lld %c%lld",&A,&c,&B);
    printf("%lld\n",c^45?A+B:A-B);
    return 0;
}


Measured memory_bytes: 764
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

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

    int N;
    cin >> N;

    vector<pair<int, int>> e;

    int n = N;
    if (N % 2 == 1) n--;

    FOR(i, 1, n) {
        int t = n - i + 1;
        FOR(j, i + 1, n) {
            if (j == t) continue;
            e.push_back({i, j});
        }
    }

    if (N % 2 == 1) {
        FOR(i, 1, N - 1) {
            e.push_back({i, N});
        }
    }

    cout << e.size() << endl;

    for (auto kv: e) {
        cout << kv.first << " " << kv.second << endl;
    }
    return 0;
}


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

int n, q;
vi a;

bool Read() {
  cin >> n;
  if (cin.eof())
    return 0;
  a.resize(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cin >> q;

  return 1;
}

void Process() {
  ll sum = 0;
  unordered_map<int, int> freq;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    freq[a[i]]++;
  }
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    if (freq.count(b)) {
      sum -= ll(freq[b]) * b;
      sum += ll(freq[b]) * c;
      freq[c] += freq[b];
      freq.erase(b);
    }
    cout << sum << "\n";
  }
}

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

  while (Read())
    Process();

  return 0;
}

Measured memory_bytes: 6944
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
dp(i,j,0 or 1) = 青をi個使ってj個の連結成分がある。最後が赤or青
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if(r<0)return 0;
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nPr(int n, int r) {
	if (r<0)return 0;
	return r > n ? 0 : fact[n] * factinv[n-r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

ll n,k;

void init(){
	cin>>n>>k;
	nCr_computeFactinv(2010);
}

int main(void){
	init();
	// cerr<<(nCr(2,0)+nCr(2,1)).get()<<endl;
	if(n==k){
		cout<<1<<endl;
		reg(i,2,k)cout<<0<<endl;
	}else{
		reg(i,1,k){
			mint ans=nCr(k-1,i-1)*( nCr(n-k-1,i-2)+nCr(n-k-1,i-1)*2+nCr(n-k-1,i));
			cout<<ans.get()<<endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    string s;
    long long int ans = 0;

    cin >> s;

    int len = s.size()-1;

    for (int bit = 0; bit < (1<<len); bit++) {
        string t;
        string sub;
        int num = 0;
        
        for (int i = 0; i < len; i++) {
            if (bit & (1<<i)) {
                t += "+";
            }
            else {
                t += "-";
            }
        }

        string tmp;
        tmp = s[0];

        num += stoi(tmp);

        for (int i = 1; i < (int)s.size(); i++) {
            sub += s[i];
            if (t[i-1] == '+') {
                num += stoi(sub);
                sub = "";
            }
            else if (t[i-1] == '-') {
                num -= stoi(sub);
                sub = "";
            }
        }
        if (num == 7) {
            cout << s[0];
            for (int i = 1; i < (int)s.size(); i++) {
                cout << t[i-1] << s[i];
            }
            cout << "=" << num << endl;
            return (0);
        }
    }
}
            





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    ll n, k;
    cin >> n >> k;
    ll res = k;
    rep1(i, n)res *= k - 1;
    pri(res);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,a,b=map(int,input().split())
ans=(b*(n-1)+a-a*(n-1)-b)+1
if ans<0:
  print(0)
  exit()
print(ans)

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

#define say(a) cout<<a<<endl
#define say1(a,b) cout<<a<<" "<<b<<endl
#define loop(a,b) for(int i=a;i<b;i++)
#define pi acos(-1)
//vector<int> v[200009];

int main()
{
    int t=0,k=0;
    char c[4],d[4];
    scanf("%s %s",c,d);
    for(k=0;k<3;k++)
    {
        if(c[k]==d[k])
        {
            t++;
        }
    }cout<<t<<endl;
}




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

int main() {
  int n, m, a, d = 1;
  cin >> n >> m;
  a = n / 2;
  for (int i = 0; i < m; i++) {
    cout << a << " " << a + d << "\n";
    a--;
    d += 2;
    if (n % 2 == 0 && (d == n / 2 || d == n / 2 + 1)) d++;
  }
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  bool flg;
  while(true){
    C -= B;
    if(C <= 0){
      flg = true;
      break;
    }
    A -= D;
    if(A <= 0){
      flg = false;
      break;
    }
  }
  cout << (flg ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    float sum;
    cin >> n;
    vector<int> value(n);
    
    for (int i = 0; i<n; i++){
        cin >> value.at(i);
    }

    sort(value.begin(),value.end());
    sum = value.at(0);
    for(int i = 0;i<n - 1; i++){
        sum =(sum + value.at(i+1))/2;
    
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

bool isConnect(const vector<pair<int,int>>& vNC, uint& idx_inOut, const int a, const int b){
    for(uint i=0; i<vNC.size(); ++i){
        const int f = vNC[i].first;
        const int s = vNC[i].second;
        if(a<s && b>f){ idx_inOut=i; return true; }
    }
    return false;
}
void shrink(vector<pair<int,int>>& vNC, const uint idx, const int a, const int b){
    int& f = vNC[idx].first;
    int& s = vNC[idx].second;
    f = max(f, a);
    s = min(s, b);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N, M; cin >> N >> M;
    vector<pair<int,int>> vA(M); // not connected
    vector<pair<int,int>> vNC; // not connected
    for(uint i=0; i<M; ++i){
        int a, b; cin >> a >> b;
        vA[i] = {a, b};
    }
    sort(vA.begin(), vA.end());
    
    for(uint i=0; i<M; ++i){
        int a = vA[i].first;
        int b = vA[i].second;
        uint idx;
        if(isConnect(vNC, idx, a, b)){
            shrink(vNC, idx, a, b);
            continue;
        }
        vNC.push_back(pair<int,int>{a,b});
    }
    
    cout << vNC.size() << endl;
    
    return 0;
}

Measured memory_bytes: 1024
# D - Knapsack 1 Educational DP Contest / DP
import numpy as np

N,W = map(int,input().split())

dp = np.zeros(W+1, dtype=np.int64)
for _ in range(N):
    w,v = map(int,input().split())
    np.maximum(dp[w:], dp[:-w] + v, out = dp[w:])

ans = dp.max()
print(ans)

Measured memory_bytes: 14596
#include <stdio.h>
#include <math.h>

int main(){
    double x1, y1, x2, y2, distance;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    distance=sqrt((pow(x2-x1, 2)+pow(y2-y1, 2)));
    printf("%f\n", distance);

    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1000000007 ;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define dist(a,b) ( pow(a.X - b.X, 2) + pow( a.Y - b.Y, 2 ) )
typedef tuple <int, int, int> line;
typedef complex <double> point;
typedef vector <point> polygon;
ll n, arr[100000], k, mn = 1e18;
ll total, dp[100000];
///dp[idx] = min( abs(arr[i1] - arr[idx]), abs(arr[i2] - arr[idx]) );
ll solve(int idx)
{
    if( idx == n - 1 )
        return 0;
    if(idx > n - 1)
        return 1e18;
    if( dp[idx] != -1 )
        return dp[idx];
    //cout << idx << endl;
    dp[idx] = 1e18;
    for(ll i = 1; i <= k ; i++)
        dp[idx] = min( dp[idx], abs(arr[i + idx] - arr[idx]) + solve(i + idx) );
    return dp[idx];
}
int main()
{
    Hello
    memset(dp, -1, sizeof dp);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    for (int i = 6; i > -1; --i) {
        if (N >= pow(2, i)) {
            cout << pow(2, i) << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 384
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	m := make(map[rune]int, 26)
	for _, r := range s {
		m[r]++
	}

	if len(m) == 26 {
		fmt.Println("None")
	} else {
		az := "abcdefghijklmnopqrstuvwxyz"
		for _, r := range az {
			if _, ok := m[r]; !ok {
				fmt.Println(string(r))
				return
			}
		}
	}
}


Measured memory_bytes: 1280
n, m = map(int, raw_input().split())
a = []
for i in range(n):
    a.append(map(int, raw_input().split()))
b = [input() for j in range (m)]
c = 0
for i in range(n):
    for j in range(m):
        c += a[i][j] * b[j]
    print c
    c = 0

Measured memory_bytes: 6496
#include<iostream>
#include<string.h>
using namespace std;

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


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

int main(){
  int N;cin >> N;
  int cur,sum=1;
  cin >> cur;
  for(int i=1;i<N;i++){
    int x;cin >> x;
    if(x<cur){
      sum ++;
      cur = x;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n), b(n), c(n); REP(i, n) cin >> a[i] >> b[i] >> c[i];
  vector<vector<long long> > dp(2, vector<long long>(3, 0));
  REP(i, n) {
    dp[(i+1)&1][0] = max(dp[i&1][1] + a[i], dp[i&1][2] + a[i]);
    dp[(i+1)&1][1] = max(dp[i&1][0] + b[i], dp[i&1][2] + b[i]);
    dp[(i+1)&1][2] = max(dp[i&1][0] + c[i], dp[i&1][1] + c[i]);
  }
  long long ans = 0;
  REP(j, 3) ans = max(ans, dp[n&1][j]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int N;
vector<pair<int,int> > edges[100005];
int ans[100005];
signed main(){
    scanf("%lld",&N);
    rep(i,N-1){
        int u,v,w;
        scanf("%lld %lld %lld",&u,&v,&w);u--;v--;
        edges[u].pb(mp(v,w));
        edges[v].pb(mp(u,w));
    }
    rep(i,N)ans[i]=-1;
    queue<int> q;
    q.push(0);
    ans[0]=0;
    while(!q.empty()){
        int v=q.front();q.pop();
        rep(e,edges[v].size()){
            int nv=edges[v][e].first;
            int nc=edges[v][e].second;
            if(ans[nv]!=(int)-1)continue;
            ans[nv]=(ans[v]+nc)%2;
            q.push(nv);
        }
    }
    rep(i,N){
        printf("%lld\n",ans[i]);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {

    ll n;
    cin>>n;
    ll h[n];
    for(ll i=0; i<n; i++) 
    	cin>>h[i];

    ll dp[n+1];
    //dp[0] = h[0];
    dp[1] = abs(h[1] - h[0]);
    dp[2] = min(dp[1] + abs(h[2] - h[1]), abs(h[2] -h[0]));
    for(ll i=3; i<n; i++) {
    	dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout<<dp[n-1]<<"\n";	

    return 0;
}

Measured memory_bytes: 5152
#include <iostream>

using namespace std;

int u(int a, int b) {
  int r;

  do {
    r = a % b;
    a = b;
    b = r;
  } while (r != 0);

  return a;
}

main() {
  int n, c;
  int x[100000] = {-1};
  int dl[100000] = {-1};

  std::cin >> n;
  std::cin >> c;


  int current = c;
  for (int i = 0; i < n; i++) {
    int xi;
    std::cin >> xi;

    if (current > xi)
      dl[i] = current - xi;
    else
      dl[i] = xi - current;
    current = xi;
  }

  int r = dl[0];
  for (int i = 1; i < n; i++) {
    r = u(r, dl[i]);                                                                                                                                                                                                                
  }

  std::cout << r;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
	
int main(){
	int N, M;
	cin >> N >> M;
	vector<int> city(N, 0);
	rep(i, M){
		int a, b;
		cin >> a >> b;
		city[a - 1]++;
		city[b - 1]++;
	}
	rep(i, N) cout << city[i] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 1000009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
ll fact[N+2];
void precompute()
{
	fact[0]=1;
	rep(i,1,N)
		fact[i]=(fact[i-1]*i)%hell;
}
ll ncr(ll n,ll r)
{
	if(r>n)
		return 0;

	ll haha=fact[n];
	ll hihi=fact[r]*fact[n-r];
	hihi%=hell;
	hihi=power(hihi,hell-2,hell);
	haha*=hihi;
	haha%=hell;
	return haha;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
        
        ll n;precompute();
	cin>>n;
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll tot = power(10,n,hell);

	ll sub = power(8,n,hell);
	rep(i,1,n+1) {
		ll ans = ncr(n,i);
		ans*= (power(8,n-i,hell));
		ans%=hell;
		ans*=2;
		ans%=hell;

		sub+=ans;
		sub%=hell;
	}
	tot=(tot-sub+hell)%hell;
	cout<<tot<<endl;
	

}

Measured memory_bytes: 11456
// Problem : E - Bomber
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_e
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define endl '\n'
#define pb push_back
#define int long long
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()
#define fill(a, b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i, x, y) for (int i = (int)x; i < y; i++)
#define px(a)                        \
  for (auto x : a) cout << x << " "; \
  cout << '\n';
#define pxy(a, n) rep(i, 0, n){px(a[i])};
/*_________________________________________________________*/

const long long MOD = 1e9 + 7, N = 1e5 + 5;
int solve() {
  int n, m, t, ans = 0;
  cin >> n >> m >> t;
  int row[n], col[m];
  map<pii, int> a;
  fill(row, 0);
  fill(col, 0);
  rep(i, 0, t) {
    int x, y;
    cin >> x >> y;
    row[x - 1]++;
    col[y - 1]++;
    a[{x - 1, y - 1}] = 1;
  }
  int mxr = *max_element(row,row+n);
  int mxc = *max_element(col,col+m);
  vi v1,v2;
  rep(i,0,n) if(row[i]==mxr) v1.pb(i);
  rep(i,0,m) if(col[i]==mxc) v2.pb(i);
  for(int x: v1) for(int y : v2) if(a[{x,y}]==0) return(mxr+mxc);
  return mxr+mxc-1;
}
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--)
    // solve();
	cout << solve() << endl;
  // cout<<(solve()?"YES":"NO")<<endl;
}

Measured memory_bytes: 35028
N,K,S = map(int,input().split())
if S != 10**9:
    for _ in range(K):
        print(S,end = ' ')
    for _ in range(N - K):
        print(10**9,end = ' ')
else:
    for _ in range(K):
        print(10**9,end = ' ')
    for _ in range(N - K):
        print(1,end = ' ')
print()


Measured memory_bytes: 9244
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;

  i64 result = (i64)N * (N - 1) / 2;
  cout << result;
}
#endif


Measured memory_bytes: 3652
program main
  implicit none
  integer :: cnt(26), i, j
  character(100) :: w
  read (*, *) w
  cnt(:) = 0
  do i = 1, len_trim(w)
    j = iachar(w(i:i)) - iachar("a") + 1
    cnt(j) = cnt(j) + 1
  end do
  if (sum(mod(cnt, 2)) == 0) then
    write (*, "(a)") "Yes"
  else
    write (*, "(a)") "No"
  end if
end program main



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

using namespace std;


int main()
{
    unsigned long long x,y;
    cin >> x >> y;
    if(!(x%y))
    {
        cout << -1;
        exit(0);
    }
    else
    {
        for(int i = 2; i * x < 10e18; i++)
        {
            if((i*x)%y)
            {
                cout << i*x;
                exit(0);
            }
        }
    }
}


Measured memory_bytes: 256
from math import gcd

n, *a = map(int, open(0).read().split())

l = [0] * n
r = [0] * n
for i in range(n - 1):
    l[i + 1] = gcd(l[i], a[i])
for i in range(n - 1, 0, -1):
    r[i - 1] = gcd(r[i], a[i])
print(max(gcd(l[i], r[i]) for i in range(n)))


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

int A[1000000];
int n;
long long cnt;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
	for (int i = g; i < n; i++)
	{
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v)
		{
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n)
{
	for (int h = 1; ; )
	{
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--)
	{
		insertionSort(A, n, G[i]);
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--)
	{
		cout << G[i];
		if (i) cout << " ";
	}
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
	{
		cout << A[i] << endl;
	}
    return 0;
}

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

int main()
{
 int a[33];
  a[0]=0;
  a[ 1]=1 ;
  a[ 2]=1 ;
  a[3 ]=1 ;
  a[ 4]=2 ;
  a[5 ]=1 ;
  a[ 6]=2 ;
  a[ 7]=1 ;
  a[ 8]=5 ;
  a[9 ]=2 ;
  a[ 10]=2 ;
  a[ 11]=1 ;
  a[ 12]=5 ;
  a[ 13]=1 ;
  a[ 14]=2 ;
  a[ 15]=1 ;
  a[ 16]=14 ;
  a[ 17]=1 ;
  a[ 18]=5 ;
  a[ 19]=1 ;
  a[ 20]=5 ;
  a[ 21]=2 ;
  a[ 22]=2 ;
  a[ 23]=1 ;
  a[ 24]=15 ;
  a[ 25]= 2;
  a[ 26]= 2;
  a[ 27]= 5;
  a[ 28]= 4;
  a[ 29]= 1;
  a[ 30]= 4;
  a[ 31]= 1;
  a[ 32]= 51;
  int n;
  cin>>n;
  cout<<a[n];
  
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<ll> pow(n);
    vector<ll> dat(1e5+2);
    FOR(i,0,n){
        cin>>pow[i];
        dat[pow[i]]++;
    }
    sortAlr(pow);
    vector<ll> v(n+1);
    FOR(i,0,n) v[i+1] += v[i] + pow[i];
    FORr(i,1,1e5)dat[i-1] += dat[i];

    ll lb = 0;
    ll ub = 2e5+2;
    while(ub-lb!=1){
        ll md = (ub+lb)/2;
        ll cnt = 0;
        FOR(i,0,n){
            ll t = max((ll)0,min(md - pow[i],(ll)1e5+1));
            cnt += dat[t];
        }
        if(m>cnt) ub = md;
        else lb = md;
    }

    ll scr = 0;
    ll sum = 0;
    FOR(i,0,n){
        ll t = max((ll)0,min(ub - pow[i],(ll)1e5+1));
        ll cnt = dat[t];
        sum += cnt;
        scr += v[cnt] + pow[i]*cnt;
    }
    scr += lb*(m-sum);
    cout<<scr<<endl;
}

Measured memory_bytes: 2560
n, l = map(int, input().split())

taste = []
sum = 0

for i in range(n):
  taste.append( l + i)
  sum += l + i
  
#print("sum is",sum)
#print("tatse is", taste)

zero_apple = taste[0]

for i in range(0, n-1):
  if abs(taste[i]) > abs(taste[i+1]):
    zero_apple = taste[i+1]

#print(zero_apple)
print(sum - zero_apple)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	string s,t;
	int n;
	cin>>n>>s>>t;
	for(int i=n;i;i--)
	{
		int f=0;
		for(int j=0;j<i;j++)if(s[n-i+j]!=t[j])f=1;
		if(f==0)
		{
			cout<<n*2-i<<endl;
			return 0;
		}
	}
	cout<<2*n<<endl;
}

Measured memory_bytes: 256
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int main()
{
    ll x;
    cin >> x;
    ll a = x/500,b=x%500;
    ll ans = a*1000+b/5*5;
    cout << ans ;
    
}

Measured memory_bytes: 764
N = int(input())
a = list(map(int, input().split()))
b = set(ai // 400 for ai in a if ai < 3200)
m = len([ai for ai in a if ai > 3199])

if m == 0:
    print("{0} {0}".format(len(b)))
else:
    print("{0} {1}".format(max(len(b), 1), len(b) + m))


Measured memory_bytes: 2940
# cook your dish here
n=int(input())
a = list(map(int,input().split()))

j = 0
k = 0
for i in range(n):
    if a[i] %2 == 0:
        if a[i] % 4== 0:
            k += 1
        else:
            j += 1
l = n-j-k

if l <= k:
    print('Yes')
else:
    if j == 0 and l == k + 1:
        print('Yes')
    else:
        
        print('No')

Measured memory_bytes: 14252
n, l = (int(i) for i in input().split())
tst = 0
max = l
for i in range(n):
    tst = tst + i + l
    max = i + l
if max < 0:
    print(tst - max)
elif max == 0:
    print(tst)
elif max > 0 and l < 0:
    print(tst)
elif max > 0:
    print(tst - l)


Measured memory_bytes: 3064
# copyright by cs_tree

class xorbasis:
    sz = 60
    table = [0] * sz

    def __init__(self):
        sz = self.sz
        for i in xrange(sz):
            self.table[i] = 0

    def add(self, x):
        sz = self.sz
        table = self.table
        
        for i in xrange(sz - 1, -1, -1):
            if x == 0: break
            
            if table[i] == 0: table[i] = x
            x = min(x, x ^ table[i])

    def maxi(self, s = 0):
        sz = self.sz
        table = self.table
        
        for i in xrange(sz - 1, -1, -1): s = max(s, s ^ table[i])

        return s

n = input()
a = map(int, raw_input().strip().split())

bits = [0] * 60

for i in xrange(n):
    for j in xrange(60):
        if (a[i] & (1 << j)): bits[j] += 1

ans = 0
for j in xrange(60):
    if (bits[j] & 1):
        xj = (1 << j)
        ans += xj
        for i in xrange(n):
            if (a[i] & xj): a[i] ^= xj

mat = xorbasis()

for i in xrange(n): mat.add(a[i])

x = mat.maxi()
ans += (2 * x)

print ans

Measured memory_bytes: 45484
//
// Created by Myabu on 2020/01/30.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int N,M,X;
    cin>>N>>M>>X;

    vector<int> A(M);

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

    sort(A.begin(), A.end());
    
    int left_cost = 0;
    int right_cost = 0;

    for (int i = 0; i < M; ++i) {
        if(A[i] > X){
            right_cost ++;
        }else if(A[i] < N){
            left_cost++;
        }
    }
    
    cout<<min(left_cost, right_cost)<<endl;

    return 0;
}

Measured memory_bytes: 504
N,A,B = map(int,input().split())

def sum_of_num(num):
    list_a = []
    sums = 0
    while num > 0:
        list_a.append(num % 10)
        num = num // 10
    for i in range(len(list_a)):
        sums = sums + list_a[i]
    return sums

list_b = []
for i in range(1,N+1):
    if A <= sum_of_num(i) <=B:
        list_b.append(i)

sums = 0
for i in range(len(list_b)):
    sums = sums + list_b[i]

print(str(sums))

Measured memory_bytes: 9292
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int anc[101010];
int a[101010];
void find(int x)
{
	if(anc[anc[x]]!=anc[x])
	{
		find(anc[x]);
		anc[x]=anc[anc[x]];
	}
}
int cnt;
void link(int u,int v)
{
	find(u);
	find(v);
	if(anc[u]!=anc[v])
	{
		cnt--;
		anc[anc[v]]=anc[u];
	}
}
struct Node{
	Node(int _anc,int _val)
	{
		anc=_anc;
		val=_val;
	}
	int anc,val;
};
bool vis[101010];
bool operator < (const Node &A,const Node &B)
{
	return A.val>B.val;
}
priority_queue<Node> Q;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	cnt=n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		anc[i]=i;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		u++;
		v++;
		link(u,v);
	}
	for(int i=1;i<=n;i++)
	{
		find(i);
		Q.push(Node(anc[i],a[i]));
	}
	long long ans=0;
	for(int i=2*cnt-2;i>=1;i--)
	{
		if(Q.empty())
		{
			printf("Impossible\n");
			return 0;
		}
		while(vis[Q.top().anc]!=0&&i<=cnt)
		{
			Q.pop();
		}
		if(vis[Q.top().anc]==0)
		{
			cnt--;
			vis[Q.top().anc]=1;
		}
		ans+=Q.top().val;
		Q.pop();
	}
	printf("%lld\n",ans);
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();
	std::cout << (std::min_element(a, a + n) - a + 1) << std::endl;
	return 0;
}





Measured memory_bytes: 3548
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;


int main()
{
	int n;
	
	scanf("%d", &n);
	
	int Ans = 0;
	
	for (int i = 1; i <= n; i++)
	{
		int x = i;
		static int num[20]; int total = 0;
		while (x) { num[++total] = x % 10; x /= 10; }
		if (total & 1) Ans++;
	}
	
	printf("%d\n", Ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
typedef long long LL;
const int N=2;
const int M=1e6+50;
const int mod=998244353;
struct mat{
    LL c[N][N];
    void clear(){memset(c,0,sizeof(c));}
}a,t;
mat operator * (mat a,mat b){
    mat c;c.clear();
    for(int k=0;k<N;++k)
    for(int i=0;i<N;++i)
    for(int j=0;j<N;++j)
    if(a.c[i][k]&&b.c[k][j])
    c.c[i][j]=(c.c[i][j]+1ll*a.c[i][k]*b.c[k][j]%mod)%mod;
    return c;
}
int get(long long v){
	a.c[0][0]=t.c[0][0]=t.c[0][1]=t.c[1][0]=1;
    while(v){
        if(v&1)a=a*t;
        t=t*t;v>>=1; 
    }
    return a.c[0][1];
}
int n,Ans,x,f[M],inv[M];
LL m;
int main(){
    scanf("%d%lld",&n,&m);
    Ans=get(m+2*(n-1));
	m%=mod;f[1]=inv[1]=x=1;
	for(int i=2;i<=n;i++){
    	f[i]=(f[i-1]+f[i-2])%mod;
		inv[i]=(mod-1ll*(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=n+1;i<=2*n;i++)
	f[i]=(f[i-1]+f[i-2])%mod;
	for(int i=1;i<n;i++){
		Ans=(Ans-1ll*x*f[2*n-i*2]%mod+mod)%mod;
		x=1ll*x*m%mod*inv[i]%mod;
		m++;
	}
	printf("%d\n",Ans);
}

Measured memory_bytes: 4992
class PotentialUnionFind
  def initialize(n)
    @size = Array.new(n + 1, 1)
    @rank = Array.new(n + 1, 0)
    @diff_weight = Array.new(n + 1, 0)
    @parent = []

    (0..n).each do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      root = find(@parent[x])
      @diff_weight[x] += @diff_weight[@parent[x]]
      @parent[x] = root
    end
  end

  def unite(x, y, w)
    w += weight(x)
    w -= weight(y)
    x = find(x)
    y = find(y)
    return false if x == y

    if @rank[x] < @rank[y]
      @diff_weight[x] = -w
      @parent[x] = y
    else
      @parent[y] = x
      @diff_weight[y] = w

      @rank[x] += 1 if @rank[x] == @rank[y]
    end

    @size[x] += @size[y]
  end

  def weight(x)
    find(x)
    @diff_weight[x]
  end

  def diff(x, y)
    weight(y) - weight(x)
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

N, M = gets.split.map(&:to_i)

puf = PotentialUnionFind.new(N)

M.times do
  l, r, d = gets.split.map(&:to_i)

  if puf.same?(l, r)
    if puf.diff(l, r) != d
      puts 'No'
      exit
    end
  else
    puf.unite(l, r, d)
  end
end

puts 'Yes'


Measured memory_bytes: 5064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}


Int isprime(Int x){
  if(x<=1) return 0;
  for(Int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n+1);
  for(Int i=n;i>=0;i--) cin>>a[i];
  
  auto mgcd=[](Int a,Int b){
              if(a==0) return b;
              if(b==0) return a;
              return __gcd(abs(a),abs(b));
            };
  Int g=abs(a[n]);
  for(Int i=0;i<n;i++) g=mgcd(g,a[i]);

  vector<Int> cand;
  for(Int p=1;p<=n;p++){
    if(!isprime(p)) continue;
    cand.emplace_back(p);    
  }  
  for(Int p=1;p*p<=g;p++){
    if(g%p) continue;
    if(isprime(p)) cand.emplace_back(p);
    if(isprime(g/p)) cand.emplace_back(g/p);
  }
  
  cand=compress(cand);
  for(Int p:cand){
    vector<Int> b(a);    
    for(Int i=0;i<=n;i++) b[i]=((b[i]%p)+p)%p;
    for(Int i=n;i>=p;i--){
      b[i-p+1]+=b[i];
      b[i]=0;
      b[i-p+1]%=p;
    }
    Int flg=1;
    for(Int i=0;i<=n;i++) flg&=b[i]==0;    
    if(flg) cout<<p<<"\n";
  }
  cout<<flush;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  if (n == 2) {
    puts("4 7");
    puts("23 10");
    return 0;
  }

  auto is_prime = [&](int p) {
    for (int i = 2; i * i <= p; ++i) {
      if (p % i == 0) {
        return false;
      }
    }
    return true;
  };

  auto lcm = [&](ll x, ll y) {
    return x / __gcd(x, y) * y;
  };

  int p = 1;
  vector<vector<ll>> a(n + 1, vector<ll> (n + 1, 1));
  for (int i = 1; i <= n << 1; ++i) {
    if (i & 1) {
      ++p;
      while (!is_prime(p)) {
        ++p;
      }
      for (int j = 1; j < i; ++j) {
        if (j <= n && i - j <= n) {
          a[j][i - j] *= p;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (i & 1) {
      ++p;
      while (!is_prime(p)) {
        ++p;
      }
      for (int j = i; j <= n; ++j) {
        a[j][j - i] *= p;
      }
      ++p;
      while (!is_prime(p)) {
        ++p;
      }
      for (int j = i; j <= n; ++j) {
        a[j - i][j] *= p;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i][j] == 1) {
        if (i > 1) {
          a[i][j] = lcm(a[i][j], a[i - 1][j]);
        }
        if (j > 1) {
          a[i][j] = lcm(a[i][j], a[i][j - 1]);
        }
        if (i < n) {
          a[i][j] = lcm(a[i][j], a[i + 1][j]);
        }
        if (j < n) {
          a[i][j] = lcm(a[i][j], a[i][j + 1]);
        }
        ++a[i][j];
      }
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      printf("%lld%c", a[i][j], j == n ? '\n' : ' ');
    }
  }
  return 0;
}


Measured memory_bytes: 5120
s = gets(&:chomp)
sa = s.split(//)
check = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
su = sa.uniq.sort
check.length.times do |i|
    if check[i].eql?(su[i+1])
    else
       puts check[i]
       exit
    end
end
puts "None"

Measured memory_bytes: 8828
import math
def main():
    S = input()
    a = 0
    b = 0
    for s in S:
        if s == "A":
            a += 1
        elif s == "B":
            b += 1
    if (a == 3) or (b == 3):
        print("No")
    else:
        print("Yes")






    return 0
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 300001
typedef unsigned long long ull;
const ull B = 1000000007ULL;
 
int main(){
    int N,M;
    char s[MAX];
    scanf("%d%d%s",&N,&M,s);
    vector<ull> p(N+1),hash(N+1);
    p[0] = 1; hash[0] = 0;
    for(int i = 0 ; i < N ; i++){
        hash[i+1] = hash[i]*B + s[i];
        p[i+1] = p[i]*B;
    }
    int L = 0, R = 0;
    set<ull> st;
    while(M--){
        scanf("%s",s);
        if(s[0] == 'L' && s[1] == '+'){
            L++;
        }else if(s[0] == 'L' && s[1] == '-'){
            L--;
        }else if(s[0] == 'R' && s[1] == '+'){
            R++;
        }else{
            R--;
        }
        st.insert(hash[R+1]-hash[L]*p[R-L+1]);
    }
    printf("%d\n",(int)st.size());
    return 0;
}

Measured memory_bytes: 21776
from bisect import *
from collections import *

N, K, C = map(int, input().split())
S = input()
T = [i for i, x in enumerate(S, 1) if x == 'o']
sl = deque()
sr = deque()
i = 0
while len(sl) < K:
    sl.append(T[i])
    i = bisect_right(T, T[i]+C)
i = len(T)-1
while len(sr) < K:
    sr.appendleft(T[i])
    i = bisect_left(T, T[i]-C)-1
for x, y in zip(sl, sr):
    if x == y:
        print(x)

Measured memory_bytes: 65784
from functools import reduce
from collections import Counter
MOD = 10 ** 9 + 7
N, M = map(int, input().split())

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(lambda x, y : x * y % MOD, range(n, n - r, -1))
    under = reduce(lambda x, y : x * y % MOD, range(1,r + 1))
    return over * pow(under, MOD - 2, MOD)

C = Counter()
def fct(m):
    if m < 2:
        return 1
    r = m
    for i in range(2, int(m**0.5)+1):
        if m % i == 0:
            r = i
            break
    C.update([r])
    return m // r

m = fct(M)
while m != 1:
    m = fct(m)

cum = 1
for v in C.values():
    cum *= cmb(N+v-1, v)
    cum %= MOD

print(cum)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,max=0,x=0;
  cin>>n;
  int h[n];
  for(int i=0;i<n;i++)
    cin>>h[i];
  for(int i=1;i<n;i++)
  {
    if(h[i]>h[i-1])
    {
      if(x>max)
        max=x;
      x=0;
    }
    else
      x++;
  }
  if(max<x)
    max=x;
  cout<<max;
  return 0;
}    

Measured memory_bytes: 640
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    ab = []
    g = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(int, input().split())
        ab.append([a, b])
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)
    ans = 0
    for i in range(n):
        check = True
        for j in g[i]:
            if h[j] >= h[i]:
                check = False
        if check:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 106656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Math;

namespace ConsoleApp15
{
    class Class129
    {
        static int N;
        static void Main()
        {
            N = int.Parse(Console.ReadLine());
            DFS(0, 0, "a");
        }
        //位置、可能数、文字
        static void DFS(int i,int num,string s)
        {
            if (i < N-1)
            {
                for (int j = 0; j <= num+1; j++)
                {
                    DFS(i + 1, Max(j, num), s + ((char)(97+j)).ToString());
                }
            }
            else
                Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 16456
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7; 
const int N=1e2 + 5,M=1e5 + 5;
int arr[N];
int pre[N];
ll dp[N][M];
ll OO=1e12; 
 
ll n,m,k,cnt,SU,idx,len,MN,MX;
ll l,r,mid;
ll a,b,c,d;

ll Solve(int idx,ll rem){
	
		
	if(idx == n)
		return (rem < 0)? -OO : 0;
	
	ll &ret = dp[idx][rem];
	if(~ret)
		return ret;
	
	ll x = Solve(idx+1,rem);
	ll y = (rem >= arr[idx]) ? pre[idx] + Solve(idx+1,rem-arr[idx]) : -OO;
	
	
	return ret = max(x,y);
}



 
 
int main(){
	
	memset(dp, -1 ,sizeof dp);
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>arr[i]>>pre[i];
	

	cout<<Solve(0,m)<<endl;
	

	


}

Measured memory_bytes: 82304
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>

using namespace std;

long long N, K;

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

	long long halves = 0;
	
	if (K%2 == 0){
		halves = (N + (K/2)) / K;
	}

	long long full = N/K;
	
	long long ans = halves*halves*halves + full*full*full;

	cout << ans << endl;
}

Measured memory_bytes: 256