akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int cmp(const void* a, const void* b){
    long *x=(long *)a;
    long *y=(long *)b;
    return *x==*y?0:(*x>*y?1:-1);
}

long int gcd(long int a, long int b){
    long int tmp=0,ans;
    if(a<b){
        tmp=a;
        a=b;
        b=tmp;
    }
    ans=a%b;
    while(ans!=0){
        a=b;
        b=ans;
        ans=a% b;
    }
    return b;
}

main(){
    int N;
    long int X,ans=0;
    scanf("%d%li",&N,&X);
    long int x[N+1],x2[N];
    x[N]=X;
    for (int i = 0; i < N; ++i) {
        scanf("%li",&x[i]);
    }

    if(N==1){
        printf("%li",labs(X-x[0]));
        return 0;
    }

    qsort(x, (size_t) (N + 1), sizeof(long), cmp);
    for (int i = 0; i < N ; ++i) {
        x2[i]=x[i+1]-x[i];
    }

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

    printf("%li",ans);
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(true){
     c-=b;
    if(c<=0){
      cout<<"Yes"<<endl;
      break;
    }
    a-=d;
    if(a<=0){
      cout<<"No"<<endl;
      break;
    }
  }
}


Measured memory_bytes: 3632
def yakusu(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
N=int(input())
ans=0
for i in range(1,N+1,2):
  if len(yakusu(i))==8:
    ans+=1
print(ans)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

int n;
int a[N];
ll pref[N];

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
      pref[i] = pref[i - 1] + a[i];
    }
    for (int i = n; i > 0; i--) {
      ++ans;      
      if (a[i] > pref[i - 1] * 2) break;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1536
/*
 * OfficialHouse.cpp
 *
 *  Created on: 2014/07/24
 *      Author: WanWan1985
 */
#include <iostream>
#include <vector>
#include <map>
using namespace std;

#define FLOOR_NUM	(3)
#define HOUSE_NUM	(4)
#define ROOM_NUM	(10)

typedef struct {
	int iHouseNo;
	int iFloorNo;
	int iRoomNo;
	int iPersonNum;
} S_HouseInfo;

typedef unsigned int u_int;

class C_HouseInfo {
private:
	vector<S_HouseInfo> m_vecHouseInfo;
	map<int, vector<int> > m_mapFloorInfo;
public:
	void SetHouseInfo(vector<S_HouseInfo> a_vecHouseInfo);
	vector<map<int, pair<int, int> > > GetMapFloorInfo(int a_iHouseNo);
};

int main(void) {

	int iInfoNum = 0;
	cin >> iInfoNum;	// 情報数

	vector<S_HouseInfo> vecHouseInfo;
	for (u_int i = 0; i < iInfoNum; i++) {
		S_HouseInfo HouseData;
		int iHouseNo = 0;	// b棟
		int iFloorNo = 0;	// f階
		int iRoomNo = 0;	// r番目
		int iPersonNum = 0;	// v人
		cin >> iHouseNo >> iFloorNo >> iRoomNo >> iPersonNum;
		HouseData.iHouseNo = iHouseNo;
		HouseData.iFloorNo = iFloorNo;
		HouseData.iRoomNo = iRoomNo;
		HouseData.iPersonNum = iPersonNum;
		vecHouseInfo.push_back(HouseData);
	}

	C_HouseInfo HouseData;
	HouseData.SetHouseInfo(vecHouseInfo);


	for (int k = 0; k < HOUSE_NUM; k++) {
		vector<map<int, pair<int, int> > > vecMapInfo = HouseData.GetMapFloorInfo(k+1);

		map<int, vector<int> > Map;
		for (int i = 0; i < FLOOR_NUM; i++) {
			vector<int> tmp(ROOM_NUM, 0);
			for (int j = 0; j < vecMapInfo.size(); j++) {
				map<int, pair<int, int> > map = vecMapInfo.at(j);

				pair<int, int> pair = map[i + 1];
				tmp[pair.first - 1] += pair.second;
			}
			Map[i] = tmp;
		}

		for (u_int i = 0; i < FLOOR_NUM; i++) {
			vector<int> tmp = Map[i];
			for (int j = 0; j < tmp.size(); j++) {
				cout << " " << tmp.at(j);
			}
			cout << endl;
		}
		if (k != HOUSE_NUM - 1) {
			cout << "####################" << endl;
		}
	}


	return 0;
}

void
C_HouseInfo::SetHouseInfo(vector<S_HouseInfo> a_vecHouseInfo) {
	m_vecHouseInfo = a_vecHouseInfo;
}

vector<map<int, pair<int, int> > >
C_HouseInfo::GetMapFloorInfo(int a_iHouseNo) {

	vector<map<int, pair<int, int> > > vecMapInfo;
	for (int i = 0; i < m_vecHouseInfo.size(); i++) {

		map<int, pair<int, int> > mapResidenceInfo;
		S_HouseInfo HouseInfo = m_vecHouseInfo.at(i);
		if (a_iHouseNo == HouseInfo.iHouseNo) {
			mapResidenceInfo[HouseInfo.iFloorNo] = make_pair(HouseInfo.iRoomNo, HouseInfo.iPersonNum);
			vecMapInfo.push_back(mapResidenceInfo);
		}
	}
	return vecMapInfo;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
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;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N, M;
  cin >> N >> M;
  vvi AB(N, vi(2));
  cin >> AB;
  vvi CD(M, vi(2));
  cin >> CD;

  for(auto &ab:AB){
    i64 dist = INF;
    i64 ans = 0;
    i64 i = 0;
    for(auto &cd:CD){
      i++;
      if(abs(ab[0]-cd[0])+abs(ab[1]-cd[1])<dist){
        dist = abs(ab[0]-cd[0])+abs(ab[1]-cd[1]);
        ans = i;
      }
    }
    cout << ans << "\n";
  }


}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
int main(){
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    ll x=b-a;
    bool ok=0;
    for(ll i=0;i<n;i++){
        ll j=n-1-i;
        if(i*c-j*d<=x&&x<=i*d-j*c) ok=1;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<int> gcd_l(N + 1);
    vector<int> gcd_r(N + 1);
    gcd_l[1] = A[0];
    gcd_r[N - 1] = A[N - 1];
    for (int i = 1; i < N; i++) {
        gcd_l[i + 1] = __gcd(gcd_l[i], A[i]);
    }
    for (int i = N - 2; i >= 0; i--) {
        gcd_r[i] = __gcd(gcd_r[i + 1], A[i]);
    }

    int ma = 0;
    for (int i = 0; i < N; i++) {
        int g;
        if (i == 0) {
            g = gcd_r[i + 1];
        } else if (i == N - 1) {
            g = gcd_l[i];
        } else {
            g = __gcd(gcd_l[i], gcd_r[i + 1]);
        }
        ma = max(ma, g);
    }
    cout << ma << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int p1[110000],p2[110000];
int a[110000];
int lb[110000];
inline void jio(){puts("0");exit(0);}
bool lowb[110000];
long long ff[110000];
int ljrose[110000];
long long renleizhihui[110000];
int main()
{
	int n;scanf("%d",&n);
	memset(p1,0,sizeof(p1));
	memset(p2,0,sizeof(p2));
	int lben=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<1||a[i]>n)jio();
		if(a[i]==i)lb[++lben]=i;
		if(p1[a[i]]==0)p1[a[i]]=i;
		else if(p2[a[i]]==0)p2[a[i]]=i;
		else jio();
	}
	int ss=0;
	memset(lowb,false,sizeof(lowb));
	for(int i=1;i<=lben;i++)
	{
		lowb[lb[i]]=true;
		if(p1[lb[i]]!=lb[i])p1[lb[i]]^=p2[lb[i]]^=p1[lb[i]]^=p2[lb[i]];
		if(p2[lb[i]]!=0)lowb[p2[lb[i]]]=true;
		if(p2[lb[i]]==0)ss++;
		else if(p1[p2[lb[i]]]!=0)jio();
	}
	long long lbsl=1;
	for(int i=1;i<=n;i++)
	{
		int xx=0,yy=0;
		long long s=2;
		if(p2[i]!=0&&lowb[i]==false)
		{
			lowb[i]=true;
			xx=p1[i];yy=p2[i];
			lowb[xx]=lowb[yy]=true;
			while(true)
			{
				if(yy>0)
				{
					int xr=xx,yr=yy;
					if(p2[xr]!=0&&p1[yr]!=0)jio();
					if(p1[xr]!=0&&p2[yr]!=0)jio();
					if(p1[xr]!=0&&p1[yr]!=0)xx=p1[xr],yy=p1[yr];
					else if(p2[xr]!=0)xx=p1[xr],yy=p2[xr];
					else if(p2[yr]!=0)xx=p1[yr],yy=p2[yr];
					else if(p1[xr]!=0)xx=p1[xr],yy=0;
					else if(p1[yr]!=0)xx=p1[yr],yy=0;
					else xx=yy=0;
				}
				else
				{
					int xr=xx;
					if(p2[xr]!=0)xx=p1[xr],yy=p2[xr],s=s*2%1000000007;
					else if(p1[xr]!=0)xx=p1[xr],yy=0;
					else xx=yy=0;
				}
				lowb[xx]=lowb[yy]=true;
				if(xx==0&&yy==0)jio();
				if(xx==i||yy==i)
				{
					if(yy==i)xx^=yy^=xx^=yy;
					if(yy==0)break;
					if(p1[yy]!=0)jio();
					else
					{
						if(s%2==0)s=s/2;
						else s=(s+1000000007)/2;
						break;
					}
				}
			}
			lbsl=lbsl*s%1000000007;
		}
	}
	ff[0]=1;ff[1]=1;ff[2]=2;
	for(int i=3;i<=n;i++)ff[i]=(ff[i-1]+ff[i-2]*(i-1)%1000000007)%1000000007;
	memset(ljrose,0,sizeof(ljrose));
	for(int i=1;i<=n;i++)
	{
		if(lowb[i]==false)
		{
			long long sr=1;int j=a[i];
			lowb[i]=true;
			while(j!=i)lowb[j]=true,j=a[j],sr++;
			ljrose[sr]++;
		}
	}
	for(int i=2;i<=n;i++)
	{
		if(i%2==1)
		{
			renleizhihui[0]=1;renleizhihui[1]=2;renleizhihui[2]=4+i;
			for(int j=3;j<=ljrose[i];j++)renleizhihui[j]=(renleizhihui[j-1]*2+renleizhihui[j-2]*(j-1)%1000000007*i%1000000007)%1000000007;
			lbsl=lbsl*renleizhihui[ljrose[i]]%1000000007;
			continue;
		}
		renleizhihui[0]=1;renleizhihui[1]=1;renleizhihui[2]=1+i;
		for(int j=3;j<=ljrose[i];j++)renleizhihui[j]=(renleizhihui[j-1]+renleizhihui[j-2]*(j-1)%1000000007*i%1000000007)%1000000007;
		lbsl=lbsl*renleizhihui[ljrose[i]]%1000000007;
	}
	lbsl=lbsl*ff[ss]%1000000007;
	printf("%lld\n",lbsl);
	return 0;
}

Measured memory_bytes: 3072
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int m=sc.nextInt();
        char a[]=sc.nextString().toCharArray();
        char b[]=sc.nextString().toCharArray();
        int g=(int)gcd(n,m);
        long ans=(long)n*m/g;
        for (int i = 0; i < g; i++) {
        	if(a[n/g * i]!=b[m/g *i]) {ans=-1;break;}
		}

		
        out.println(ans);
        out.flush();
    }

    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }
    
    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

typedef long long lint;
typedef unsigned long long ulint;
const int MOD=1000000007;

int main(){
    int N,M;
    cin >> N >> M;
    lint fact[100001];
    fact[0]=1;
    for(int i=1;i<=100000;i++) fact[i]=i*fact[i-1]%MOD;

    switch(N-M){
        case 0:
            cout << (2*fact[N]%MOD*fact[M]%MOD) << endl;
            return 0;
        case 1:
        case -1:
            cout << (fact[N]*fact[M]%MOD) << endl;
            return 0;
        default:
            cout << 0 << endl;
            return 0;
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int n,k;
    cin >> n >> k;
    int d,a;
    vector<bool> motu(n,false);
    rep(i,k){
        cin >> d;
        rep(j,d){
            cin >> a;
            motu[a-1] = true;
        }
    }
    int ans=0;
    rep(i,motu.size()){
        if(!motu[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int n;

int a[10] = {1,2,4,8,16,32,64,128,256,512};
int flag[10] = {0};

bool dfs(int i,int sum){
      
    if(sum == n){
        return true;
    }

    if(i == 10){
        return false;
    }
    //not including i
    if(dfs(i+1,sum)){
        return true;
    }
    
    //including i
    if(dfs(i+1,sum + a[i])){
        flag[i] = 1;
        return true;
    }
}

void solve(){

    dfs(0,0);
}

int main(){

    int m;
    while(cin >> n){
        
        solve();
        for(int i = 0;i < 10;i++){
            if(flag[i]){
                m = i;
            }
        }

        for(int i = 0;i < m+1;i++){
            if(flag[i]){
                if(i < m){
                    cout << a[i] << " ";
                }else{
                    cout << a[i] << endl;
                }               
            }
        }
        for(int i = 0;i < 10;i++){
            flag[i] = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 2992
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 200000;
int main()
{
  long long a[N_MAX],f[N_MAX];
  long long n,k,i,t,s=0,p,l=0,r=0;
  cin >> n >> k;
  for(i=0;i<n;i++){
    cin >> a[i];
    s+=a[i];
  }
  for(i=0;i<n;i++)
    cin >> f[i];
  if(k>=s){
    cout << "0" << endl;
    return 0;
  }
  sort(a,a+n);
  sort(f,f+n,greater<long long>());
  for(i=0;i<n;i++){
    t=a[i]*f[i];
    r=max(t,r);
  }
  while(r>l+1){
    t=0;
    p=(l+r)/2;
    for(i=0;i<n;i++)
      t+=max(a[i]-p/f[i],(long long)0);
    if(t<=k) r=p;
    else l=p;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
int main(void)
{
	int a,b,i,w[7];
	for(i=0;i<7;i++){
		scanf("%d",&a);
		scanf("%d",&b);
		w[i]=a-b;
	}
	for(i=0;i<7;i++){
		printf("%d\n",w[i]);
	}
	return 0;
}


Measured memory_bytes: 2104
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> h(N);
	REP(i, N) cin >> h.at(i);
	vector<int> dp(N+1);
	dp[0] = 0;
	dp[1] = abs(h.at(0) - h.at(1));
	FOR(i, 2, N) dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));
	cout << dp[N-1] << endl;
}


Measured memory_bytes: 1024
n,A,B,C = map(int, input().split())
l = list([int(input()) for _ in range(n)])

big=10**9

def dp(cur,a,b,c):
  if cur==n:
    if a==0 or b==0 or c==0:
      return big
    else:
      return abs(A-a)+abs(B-b)+abs(C-c)-30
  else:
    ret0 = dp(cur+1,a,b,c)
    ret1 = dp(cur+1,a+l[cur],b,c)+10
    ret2 = dp(cur+1,a,b+l[cur],c)+10
    ret3 = dp(cur+1,a,b,c+l[cur])+10
    return min([ret0, ret1, ret2, ret3])

ret=dp(0,0,0,0)
print(ret)

Measured memory_bytes: 3188
#include<stdio.h>

int main()
{
  int l,i,j,k,v;

  scanf("%d",&l);

  int A[l];
  
  for(i=0;i<l;i++)
    {
      scanf("%d",&A[i]);
    }

  for(i=0;i<l;i++)
    {
      v = A[i];
      j=i-1;
      
      while(j>=0&&A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	  A[j+1]=v;
	}
      for(k=0;k<l-1;k++)
	{
	  printf("%d ",A[k]);
	}
      printf("%d\n",A[k]);
  
    }
  
  return 0;
}

  


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main(){
  long long int N,s=0,i;
  cin>>N;
  for(i=1;i<=N;i++)
  {
    if((i%3==0) || (i%5==0))
      continue;
    else
      s=s+i;
  }
  cout<<s;

  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	vi t(3);
	vvi l;
	while(1){
		rep(i,0,3) cin>>t[i];
		sort(all(t));
		l.push_back(t);
		if(cin.eof()) break;
	}
	int d[4]={};
	rep(i,0,l.size()){
		int a=l[i][0],b=l[i][1],c=l[i][2];
		if(a+b<=c) break;
		d[0]++;
		if(a*a+b*b==c*c) d[1]++;
		else if(a*a+b*b>c*c) d[2]++;
		else d[3]++;
	}
	cout<<d[0]<<" "<<d[1]<<" "<<d[2]<<" "<<d[3]<<endl;
}

Measured memory_bytes: 1248
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    char S[100];
    for(int i=0; i<N; i++)
    {
        cin >> S[i];
    }
    bool flag = 0;
    for(int i=0; i<N; i++)
    {
    	if(S[i]=='Y') flag = 1;
    }

    if(flag==true) cout << "Four" << endl;
    else cout << "Three" << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;


int main() {
    int n;
    cin >> n;
    string s1, s2;
    ll mod = 1000000007;
    ll ans = 1;
    cin >> s1 >> s2;
    bool isheight;
    for(int i=0;i<n;i++) {
        if(s1[i] == s2[i]) {
            if(i==0) {
                ans *= 3;
                isheight = true;
                continue;
            }
            if(isheight) {
                ans *= 2;
            }
            isheight = true;
        } else {
            if(i==0) {
                ans = 6;
                isheight = false;
                i++;
                continue;
            }
            if(isheight) {
                ans *= 2;
            } else {
                ans *= 3;
                //ans += 6;
            }

            isheight = false;
            i++;
        }
        ans %= mod;
    }
    cout << ans << endl;


}


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

void QSort(long long x[ ], int left, int right);
void Swap(long long x[ ], int i, int j);



int main(){
  int n;
  long long h;
  long long a[100000],b[100000];
  scanf("%d%lld",&n,&h);
  long long am=0;
  
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&a[i],&b[i]);
    if(a[i]>am){
      am=a[i];
      
    }
    
  }

  QSort(b,0,n-1);

  

  long long k=0;
  long long z;
  

  while(z<h){
    if(k<n){
      if(b[k]>am){
	z=z+b[k];
      }
      else{
	z=z+am;
      }
    }
    else{
      if((h-z)%am==0){
	printf("%lld\n",(h-z)/am+k);
	return 0;}
      else{
	printf("%lld\n",(h-z)/am+k+1);
	return 0;
      }
    }
    k++;
  }
  printf("%lld\n",k);
    
  
  return 0;
}

  /* クイックソートを行う */
void QSort(long long x[ ], int left, int right)
{
    int i, j;
    long long pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] > pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot > x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
   

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, j + 1, right);    /* 右の配列を Q ソートする */
}

  /* 配列の要素を交換する */
void Swap(long long x[ ], int i, int j)
{
    long long temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
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 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 = 505;
int H , W;
char s[N][N];
bool vis[N][N];

int main(){
    scanf("%d%d",&H,&W);
    rep(i,0,H) scanf("%s",s[i]);
    rep(i,0,W) vis[0][i] = true;
    for(int i=1;i<W;i+=2)
        for(int j=1;j<H-1;j++)
            vis[j][i] = true;
    rep(i,0,H){
        rep(j,0,W) putchar(vis[i][j] || s[i][j] == '#'? '#' : '.');
        puts("");
    }
    puts("");
    rep(i,0,H){
        rep(j,0,W) putchar(!vis[i][j] || s[i][j] == '#'? '#' : '.');
        puts("");
    }
    return 0;
}


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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=10000+5,D=998244353;
s64 mi(s64 x,int y=D-2)
{
	s64 ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1; 
	} 
	return ans;
}
char s1[N],s2[N];
const int n=1<<15;
s64 jie[N],niv_jie[N],dp[n],g[n];

int rev[n];s64 w[n];
void ntt(s64 a[],int flag)
{
	rep(i,1,n-1)rev[i]=rev[i/2]/2+i%2*n/2;
	rep(i,0,n-1)
	if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=1;i<n;i*=2)
	{
		int nn=i*2;
		s64 wn=mi(3,(D-1)/nn*flag+D-1);
		w[0]=1;
		rep(k,1,i-1)w[k]=w[k-1]*wn%D;
		for(int j=0;j<n;j+=nn)
		{
			s64 *a1=a+j,*a2=a1+i;
			rep(k,0,i-1)
			{
				s64 x=a1[k],y=a2[k]*w[k]%D;
				a1[k]=(x+y)%D;
				a2[k]=(x-y)%D;
			}
		}
	}
	if(flag==-1)
	{
		s64 niv_n=mi(n);
		rep(i,0,n-1)a[i]=a[i]*niv_n%D; 
	}
}
s64 DP(int a,int b)
{
	rep(i,0,a){dp[i]=1;g[i]=niv_jie[i+1];}
	while(b)
	{
	//	cerr<<b<<endl;
		ntt(g,1);
		if(b&1)
		{
			ntt(dp,1);
			rep(i,0,n-1)dp[i]=dp[i]*g[i]%D;
			ntt(dp,-1);
		//	cerr<<b<<endl;
			rep(i,a+1,n-1)dp[i]=0;
		}
		rep(i,0,n-1)g[i]=g[i]*g[i]%D;
		ntt(g,-1);
		rep(i,a+1,n-1)g[i]=0;
		b>>=1;
	}
	return dp[a];
}

int main()
{
	//freopen("1.in","r",stdin);
	scanf("%s%s",s1+1,s2+1);
	int n=strlen(s1+1);
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D;
	niv_jie[n]=mi(jie[n]);
	per(i,n,1)niv_jie[i-1]=niv_jie[i]*i%D;
	int a=0,b=0;
	rep(i,1,n)
	if(s1[i]=='1')
		if(s2[i]=='1')++a;
		else ++b;
	cout<<(jie[b]*jie[a]%D*jie[a+b]%D*DP(a,b)%D+D)%D;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#define N 30000
using namespace std;

int n;
int main()
{
	int i;
	cin >> n;
	if (n == 3) {cout << "2 5 63"; return 0;}
	cout << "2 4 3 9 ";
	n -= 4;
	for (i = 6; n >= 3 && i + 4 <= N; i += 6, n -= 3) printf("%d %d %d ", i, i + 2, i + 4);
	if (n % 2) n--, printf("%d ", i);
	for (i = 15; n; i += 12, n -= 2) printf("%d %d ", i, i + 6);
    return 0;
}

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

int main() {
	string a;
	cin >> a;
	unordered_map<char, char> b;
	b['A'] = 'X';
	b['B'] = 'Y';
	b['C'] = 'Z';
	b['D'] = 'A';
	b['E'] = 'B';
	b['F'] = 'C';
	b['G'] = 'D';
	b['H'] = 'E';
	b['I'] = 'F';
	b['J'] = 'G';
	b['K'] = 'H';
	b['L'] = 'I';
	b['M'] = 'J';
	b['N'] = 'K';
	b['O'] = 'L';
	b['P'] = 'M';
	b['Q'] = 'N';
	b['R'] = 'O';
	b['S'] = 'P';
	b['T'] = 'Q';
	b['U'] = 'R';
	b['V'] = 'S';
	b['W'] = 'T';
	b['X'] = 'U';
	b['Y'] = 'V';
	b['Z'] = 'W';
	for (char& i : a) cout << b[i];
	cout << endl;
}


Measured memory_bytes: 3148
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int rooms = 10;
		int floors = 3;
		int buildings = 4;
		int seplength = 20;
		String sep = "#";
		String sepline = "";
		for (int i = 0; i < seplength; ++i)
			sepline += sep;
		int manager[][][] = new int[buildings][floors][rooms];
		Scanner sc = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		int n = sc.nextInt();
		for (int i = 0; i < n; ++i) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();
			manager[b-1][f-1][r-1] += v;
		}
		for (int bi = 0; bi < buildings; ++bi) {
			if (bi > 0)
				out.append(sepline + "\n");
			for (int fi = 0; fi < floors; ++fi) {
				for (int ri = 0; ri < rooms; ++ri) {
					out.append(" " + manager[bi][fi][ri]);
				}
				out.append("\n");
			}
		}
		System.out.print(out);
	}
}


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

int a, n;
int x[100005];

int main() {
	cin >> a >> n;
	for (int i = 1; i <= n; i++) cin >> x[i];
	sort(x + 1, x + n + 1, greater<int>());
	int tot = 0;
	for (int i = 1; i <= n; i++) tot += x[i];
	if (tot >= a) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 640
using System;

namespace msol
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(RtM(n, ReadNumList()));
        }
        static long RtM(int n, int[] aList)
        {
            var stocks = 0L;
            var money = 1000L;
            for (var i = 0; i < n - 1; ++i)
            {
                if (aList[i] > aList[i + 1])
                {
                    // sell all
                    money += stocks * aList[i];
                    stocks = 0;
                }
                else if (aList[i] < aList[i + 1] && money >= aList[i])
                {
                    // buy all
                    stocks = money / aList[i];
                    money -= stocks * aList[i];
                }
            }
            // last day
            money += stocks * aList[n - 1];
            stocks = 0;
            return money;
        }
    }
}


Measured memory_bytes: 27428
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int n = scan.nextInt();
        int maxAttack = 0;

        for(int i = 0;i < n;i++){
            maxAttack += scan.nextInt();
        }
        scan.close();

        if(h <= maxAttack) System.out.println("Yes");
        else System.out.println("No");
    }
}

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

int main() {
    int n, m;
    cin >> n >> m;

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

    priority_queue<int> pq;
    for (int i = 0; i < n; i++) {
        pq.push(price[i]);
    }

    while (m != 0) {
        int top = pq.top();
        pq.pop();
        pq.push(top / 2);
        --m;
    }

    long res = 0;
    while (!pq.empty()) {
        res += pq.top();
        pq.pop();
    }

    cout << res << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdio.h>
#define ll long long
#define fr(j,p) for (int i=j; i<p ;i++)
#define fastScan ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define inar(x,n) fr(0,n) scanf("%d",&x[i])
const long long md=998244353;
using namespace std;

int modu(int x)
{
    if (x<0)return x*(-1);
    return x;
}
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    inar(arr,n);
    int cost[n];
    fr(0,n)cost[i]=1e9;
    cost[0]=0;
    cost[1]=modu(arr[1]-arr[0]);
    fr(2,n)
    {
        for (int j=1 ; j<=k&&(i-j>=0)  ; j++)
        cost[i]=min(cost[i-j]+modu(arr[i]-arr[i-j]),cost[i]);
    }
    cout<<cost[n-1];

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N;
  cin >> N;
  LINT a[N];
  LINT amax=0;
  REP(i, N) {
    cin >> a[i];
    amax=max(amax, a[i]);
  }

  if(N==2){
    cout << a[0] << " " << a[1] << endl;
    return 0;
  }
  
  LINT r=a[0]; //amax/2に最も近い値が入る
  REP(i, N){
    if(abs(r-amax/2)>abs(a[i]-amax/2)) r = a[i];
  }
  cout << amax << " " << r << endl;


  return 0;
}


Measured memory_bytes: 1024
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

print(ans)

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, M; cin >> N >> M;
  map<LL, LL> m;
  for (int i = 0; i < N; ++i) {
    int A; cin >> A;
    m[A]++;
  }
  for (int i = 0; i < M; ++i) {
    LL B, C; cin >> B >> C;
    m[C] += B;
  }

  LL sum = 0;
  for (auto it = m.rbegin(); it != m.rend(); ++it) {
    auto [k, v] = *it;
    if (v < N) {
      sum += k * v;
      N -= v;
    } else {
      sum += k * N;
      break;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 16032
import java.util.*;

public final class Main {


    static int N;

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        N = s.nextInt();

        String str = s.next();


        for (int i = 1;  i <= 2; i++) {

            char first = str.charAt(0);

            int[] arr = new int[N];

            arr[0] = i;
           tc: for (int j = 1; j <= 2; j++) {

                if (first == 'o') {

                    if (i == 1) {

                        arr[1] = 3-j;
                        arr[N-1] = 3-j;
                    } else {


                        arr[1] = 3-j;

                        arr[N-1] = j;
                    }
                } else if (first =='x') {

                    if (i == 2) {

                        arr[1] = 3-j;
                        arr[N-1] = 3-j;
                    } else {


                        arr[1] = 3-j;

                        arr[N-1] = j;
                    }
                }

                for (int n = 2; n < N-1; n++) {

                    int before = arr[n-1];

                    char c = str.charAt(n-1);

                    if (before==1) {
                        //sheep

                        if (c == 'o'){

                            arr[n] = arr[n-2];

                        } else {

                            arr[n]= 3- arr[n-2];
                        }

                    } else {
                        if (c == 'o'){

                            arr[n] = 3-arr[n-2];

                        } else {

                            arr[n]= arr[n-2];
                        }


                    }
                }

                for (int k = N-2; k < N; k++) {

                    int flag = arr[k];

                    int before = k-1;

                    int after = k+1 >= N ? 0 : k+1;
                    char c = str.charAt(k);



                    if (flag == 1) {
                        //sheep
                        if (c == 'o') {

                            if (arr[before] != arr[after]) continue tc;

                        } else {
                            if (arr[before] == arr[after]) continue tc;

                        }

                    } else {



                        if (c == 'o') {
                            if (arr[before] == arr[after]) continue tc;


                        } else {



                            if (arr[before] != arr[after]) continue tc;
                        }
                    }


                }
               for (int  r : arr) {

                   char a = r == 1 ? 'S' : 'W';

                   System.out.print(a);
               }

               return;

            }



        }System.out.print(-1);
    }

}

Measured memory_bytes: 36200
n,m = gets.split.map &:to_i
abs = []

m.times{
	a, b = gets.split.map &:to_i
	abs << [a,b]
}

abs.sort!{ |a, b| a[1] <=> b[1] }

count = 0
before = -1

abs.each{ |ab|
	if before > ab[0] && before <= ab[1] then
		next
	else
		count += 1
		before = ab[1]
	end
}

puts count


Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N;cin>>N;
    vector<int>memo(26,0);
    vector<int>ans(26,INF);
    REP(i,N){
        string S;cin>>S;
        REP(j,26)memo[j]=0;
        for(int j=0;j<S.size();j++){
            memo[(int)(S[j]-'a')]++;
        }
        REP(j,26)ans[j]=min(ans[j],memo[j]);
    }
    string aS="";
    REP(i,26){
        REP(j,ans[i])aS+=(char)('a'+i);
    }
    cout<<aS<<endl;
}

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

void dfs(ll v, vector<ll> way[], vector<bool> &state) {
    if(state[v] == true) return;
    state[v] = true;
    for (auto u : way[v])
    {
        dfs(u, way, state);
    }

}

int main() {
    ll N, M, P; cin >> N >> M >> P;
    vector<tuple<ll, ll, ll>> edges(M);
    vector<ll> A(M), B(M), C(M);
    vector<ll> go[N], back[N];
    vector<bool> go_state(N), back_state(N);
    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
        C[i] -= P;
        edges[i] = make_tuple(A[i], B[i], C[i]);
        go[A[i]].push_back(B[i]);
        back[B[i]].push_back(A[i]);
    }
    dfs(0, go, go_state);
    dfs(N-1, back, back_state);

    vector<bool> s(N, false);
    for(int i = 0; i < N; i++) s[i] = go_state[i] & back_state[i];

    vector<ll> dist(N, -INF);
    dist[0] = 0;
    for (int i = 0; i < N; i++)
    {
        for (auto &e : edges)
        {
            ll a, b, c;
            tie(a, b, c) = e;
            if(dist[a] != -INF) {
                dist[b] = max(dist[b], dist[a] + c);
            }
        }
    }

    auto cp = dist;
    for (int i = 0; i < N; i++)
    {
        for (auto &e : edges)
        {
            ll a, b, c;
            tie(a, b, c) = e;
            if(dist[a] != -INF) {
                dist[b] = max(dist[b], dist[a] + c);
            }
        }
    }

    for (int i = 0; i < N; i++)
    {
        if(s[i] && (cp[i] != dist[i])) {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << max(0ll, dist[N-1]) << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

const ll MOD = 1e9 + 7;

int main() {
    init_io();
    ll N;
    cin >> N;
    V<ll> dp(N + 1);
    ll pre = -1;
    V<ll> prec(2e5 + 10, -1);
    dp[0] = 1;
    for(ll i = 0; i < N; i++) {
        ll e;
        cin >> e;
        e--;
        if(e == pre) {
            dp[i + 1] = dp[i];
            continue;
        }
        if(prec[e] == -1) {
            pre = e;
            prec[e] = i;
            dp[i + 1] = dp[i];
            continue;
        }
        DEBUG(i);
        DEBUG(e + 1);
        DEBUG(prec[e]);
        DEBUG(dp[prec[e]]);
        dp[i + 1] = (dp[prec[e] + 1] + dp[i]) % MOD;
        prec[e] = i;
        pre = e;
    }
    DEBUG(dp);
    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
string s;
int k,a[35];
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++) a[s[i]-'a']=1;
    for(k=0;k<26;k++)if(!a[k])break;
    if(k==26)cout<<"None";
    else printf("%c",k+'a');
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define lli long long int
#define el '\n'
#define mem(a,b) memset(a, b, sizeof(a) )

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define F1(i,n)  for(lli i=1;i<=n;i++)
#define F0(i,n)  for(lli i=0;i<n;i++)
#define FRev(i,n)  for(lli i=n-1;i>=0;i--)
#define ever (;;)

int main()
{
    optimize();
    ll t,n,x,y,k,z,m,a,b;
    string s,ss;
    cin>>s;
    x=s.length();
    if(s[x-1]=='s')
    {
      for(ll i=0;i<x;i++)
      {
        cout<<s[i];
      }
      cout<<"es"<<el;
    }
    else
    {
      cout<<s<<'s'<<el;
    }
    

    return 0;
}
//

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, maximum = 0;
	vector<string> ans;
	map<string, int> con;
	cin>>N;
	
	for(int i = 0; i < N; i++){
		string x;
		cin>>x;
		
		con[x]++;
		maximum = max(maximum, con[x]);
	}
	
	for(pair<string, int> p : con){
		if(maximum == p.second) {
			ans.push_back(p.first);
		}
	}
	
	sort(ans.begin(), ans.end());
	
	
	for(int i = 0; i < ans.size(); i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 25584
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> p(N, 0);
	int v[210][3];
	for (int i = 0; i < N;i++) {
		for (int j = 0; j < 3;j++) {
			cin >> v[i][j];
		}
	}

	for (int c = 0; c < 3;c++) {
		for (int i = 0; i < N;i++) {
			int f[101] = { 0 };

			for (int j = 0; j < N;j++) {
				f[v[j][c]]++;
			}

			if (f[v[i][c]] == 1) {
				p[i] += v[i][c];
			}
		}
	}

	for (auto ans : p) {
		cout << ans << endl;
	}

}

Measured memory_bytes: 3216
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

void unq(auto &a){
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
}

const int N=200005;

int dp[105][105][2];

void solve(){
  int h,w;
  cin>>h>>w;
  vector<string>a(h);
  cin>>a;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      dp[i][j][0]=dp[i][j][1]=1e9;
    }
  }
  if(a[0][0]=='.'){
    dp[0][0][0]=0;
  }
  else{
    dp[0][0][1]=1;
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='#'){
	if(i){
	  dp[i][j][1]=min(dp[i][j][1],dp[i-1][j][0]+1);
	  dp[i][j][1]=min(dp[i][j][1],dp[i-1][j][1]);
	}
	if(j){
	  dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][0]+1);
	  dp[i][j][1]=min(dp[i][j][1],dp[i][j-1][1]);
	}
      }
      else{
	if(i){
	  dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][0]);
	  dp[i][j][0]=min(dp[i][j][0],dp[i-1][j][1]);
	}
	if(j){
	  dp[i][j][0]=min(dp[i][j][0],dp[i][j-1][0]);
	  dp[i][j][0]=min(dp[i][j][0],dp[i][j-1][1]);
	}
      }
    }
  }
  cout<<min(dp[h-1][w-1][0],dp[h-1][w-1][1]);
  
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 384