akhauriyash/Code-Regression huggingface dataset:
h,w=map(int,input().split())
field=[list(input()) for i in range(h)]
ans=[[0 for i in range(w)]for j in range(h)]
if field[0][0]=='#':
  ans[0][0]=1

def black(i,j,f):
  if f==1:
    if field[i][j]=='#' and field[i-1][j]=='.':
      return 1
    else:
      return 0
  else:
    if field[i][j]=='#' and field[i][j-1]=='.':
      return 1
    else:
      return 0
for i in range(h):
  for j in range(w):
    if i==0 and j==0:
      continue
    elif i==0:
      ans[i][j]=ans[i][j-1]+black(i,j,2)
    elif j==0:
      ans[i][j]=ans[i-1][j]+black(i,j,1)
    else:
      ans[i][j]=min(ans[i-1][j]+black(i,j,1),ans[i][j-1]+black(i,j,2))
print(ans[-1][-1])

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

#define int long long
#define xxx int32_t
#define fuck_u return 0;

xxx main() {
    int n;
    cin>>n;
    int dp[3] = {0};
    for (int day=0; day<n; ++day){
		int happy[3];
		int tmp_dp[3] = {0};
		for (int i=0; i<3; ++i) 
			cin>>happy[i];
		for (int i=0; i<3; ++i){
			for (int j=0; j<3; ++j) {
				if (i!=j)
					tmp_dp[i] = max(tmp_dp[i], dp[j]+happy[i]);
			}
		}
		for (int i=0; i<3;++i)
			dp[i] = tmp_dp[i];
	}
	cout<<max(dp[0], max(dp[1], dp[2]))<<"\n";
	fuck_u
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<map>
#include<algorithm>
#include<math.h>
#define N 100005
using namespace std;
struct Node
{
    int a,b,c,d;
} s[N];
bool cmp(Node a,Node b)
{
    return a.b<b.b;
}
bool cnp(Node a,Node b)
{
    return a.d<b.d;
}
map<int ,int>ss;
int main()
{
    int m,n,i;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>s[i].a>>s[i].b;
        s[i].d=i;

    }
    sort(s,s+m,cmp);
    for(i=0;i<m;i++)
    {
       ss[s[i].a]++;
       s[i].c=ss[s[i].a];

    }
    sort(s,s+m,cnp);
    for(i=0;i<m;i++)
    {
        int len=0,lens=0;
        int z=s[i].a;
        int w=s[i].c;
        while(z)
        {
            len++;
            z/=10;
        }
        while(w)
        {
            lens++;
            w/=10;
        }
        len=6-len;
        for(int j=0;j<len;j++)
          printf("0");
        cout<<s[i].a;
        lens=6-lens;
        for(int j=0;j<lens;j++)
            printf("0");
        cout<<s[i].c;
        cout<<endl;

    }

	return 0;
}


Measured memory_bytes: 7808
#include<stdio.h>
int main()
{
	long long  a,b,c,d;
	long long  i,x[4],y;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	x[0]=a*c;
	x[1]=a*d;
	x[2]=b*c;
	x[3]=b*d;
	y=x[0];
	// for(i=0;i<4;i++) printf("%lld ",x[i]);
	for(i=0;i<4;i++){
		if(y<x[i]) y=x[i];
	}
	printf("%lld\n",y);
	return 0;
}

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

using namespace std;

#define ll long long int

int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll i,n,flag=0,ans=1000,x;
              cin>>n;
              vector<ll>A(n),X;
              for(i=0;i<n;i++)
              {
                  cin>>A[i];
              }
              for(i=0;i+1<n;i++)
              {
                  if(flag==0)
                  {
                      if(A[i]<A[i+1])
                      {
                          flag=1;
                          X.push_back(A[i]);
                      }
                  }
                  else
                  {
                      if(A[i]>A[i+1])
                      {
                          flag=0;
                          X.push_back(A[i]);
                      }
                  }
              }
              if(X.size()!=0 && A[n-1]>X[X.size()-1])
                X.push_back(A[n-1]);
              for(i=0;i+1<X.size();i+=2)
              {
                  x=ans/X[i];
                  ans%=X[i];
                  ans+=X[i+1]*x;
              }
              cout<<ans;
              return(0);
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
int N,M,s,ga,gb;
int d[100][100],inf=1e8;
int main(){
	while(true){
		cin>>N>>M>>s>>ga>>gb;
		if(N==0) break;
		rep(i,N) rep(j,N) d[i][j]=inf;
		rep(i,N) d[i][i]=0;
		rep(i,M){
			int a,b,c;
			cin>>a>>b>>c;
			d[a-1][b-1]=c;
		}
		rep(i,N) rep(j,N) rep(k,N) d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
		int ans=inf;
		rep(i,N){
			ans=min(ans,d[s-1][i]+d[i][ga-1]+d[i][gb-1]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <cmath>
#define LL long long

std::string repeat(int times, char c){
	std:: string r(times,c);
	return r;
}

bool isPrime(int& n){
	int seekTo;
	bool prime;

        for(int j=n;j<=n;j++){
            if(n==1){
				prime = false;
				break;
            } else if(n==2){
				prime = true;
				break;
            } else if(n%2==0){
				prime = false;
				break;
			} else {
				prime = true;
				seekTo = (int)std::sqrt(j);
				for(int i=3;i<=seekTo;i+=2){
					if(j%i==0){
						prime = false;
						break;
					}
				}
			}
        }

	return prime;
}

int main(){

	int n, i = 11;
	std::cin >> n;
	std::vector<int> ans = {};

	while(ans.size()<n){
		if(isPrime(i))ans.push_back(i);
		i+=10;
	}

	for(i=0;i<ans.size();i++){
		std::cout << ans[i];
		if(i!=ans.size()-1)std::cout << ' ';
		else std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include "cstdio"
int max(int x,int y)
{
    return x>y?x:y;
}
int min(int x,int y)
{
    return x>y?y:x;
}
int main()
{
    int a,b,c,d;
    while (scanf ("%d%d%d%d",&a,&b,&c,&d) != EOF)
    {
       a = max(a,c);
       b = min(b,d);
       printf ("%d\n",b-a>0?b-a:0);

    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < ((int)b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= ((int)a); --i)
#define sz(c) ((int)c.size())
#define all(c) c.begin(),c.end()

using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

void dump_impl(string str) {}
template <class H, class... T>
void dump_impl(string s, const H &head, const T&... tail) {
    int par = 0;
    rep(i, 0, sz(s)) {
        char ch = s[i];
        if (ch == ',' && par == 0) {
            cerr << " = " << head << ", ";
            dump_impl(s.substr(i + 1), tail...);
            return;
        } else {
            cerr << ch;
            if (ch == '(') par++;
            if (ch == ')') par--;
        }
    }
}
#define dump(...) do { cerr << "\x1b[33;1m"; dump_impl(#__VA_ARGS__ ",", __VA_ARGS__); cerr << "\x1b[0m" << endl; } while (0)

signed main() {
    int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
    int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};
    while (1) {
        int W, H;
        cin >> W >> H;
        if (W == 0 && H == 0) break;
        vvi A(H, vi(W));
        rep(i, 0, H) {
            rep(k, 0, W) {
                cin >> A[i][k];
            }
        }
        vector<vector<bool>> vis(H, vector<bool>(W));
        int ans = 0;
        rep(y, 0, H) {
            rep(x, 0, W) {
                if (vis[y][x]) continue;
                if (A[y][x] == 0) continue;
                queue<pii> q;
                q.push({y, x});
                vis[y][x] = true;
                while (sz(q)) {
                    int py, px;
                    tie(py, px) = q.front(); q.pop();
                    rep(dir, 0, 8) {
                        int yy = py + dy[dir];
                        int xx = px + dx[dir];
                        if (yy < 0 || xx < 0 || yy >= H || xx >= W) continue;
                        if (vis[yy][xx]) continue;
                        if (A[yy][xx] == 0) continue;
                        q.push({yy, xx});
                        vis[yy][xx] = true;
                    }
                }
                ans++;
            }
        }
        cout << ans << endl;
    }
}



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


int main() {
  string k;
  cin >> k;
  int cnt = 0;
  for (int i = 0; i < k.size(); i++) {
    if (k.at(i) == '0') cnt += 0;
    else if (k.at(i) == '1') cnt += 1;
    else if (k.at(i) == '2') cnt += 2;
    else if (k.at(i) == '3') cnt += 3;
    else if (k.at(i) == '4') cnt += 4;
    else if (k.at(i) == '5') cnt += 5;
    else if (k.at(i) == '6') cnt += 6;
    else if (k.at(i) == '7') cnt += 7;
    else if (k.at(i) == '8') cnt += 8;
    else if (k.at(i) == '9') cnt += 9;
  }
  if (cnt%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  }

Measured memory_bytes: 3756
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
ll k;
int p[5555];
ll c[5555];
ll cnt[5555];
bool used[5555];
vi v[5555];
ll ans;
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	cin>>n>>k;
	ans=-1000000000000009;
	rep(i,n)cin>>p[i],p[i]--;
	rep(i,n)cin>>c[i];
	rep(i,n)
	{
		memset(used,0,sizeof(used));
		memset(cnt,0,sizeof(cnt));
		ll gg=k;
		ll res=0;
		int num=0;
		int now=i;
		ll mx=-1000000000000009;
		cnt[now]=0;
		while(p[now]!=i)
		{

			cnt[p[now]]=cnt[now]+c[p[now]];
			now=p[now];
			v[i].pb(now);
			num++;
		}
		num++;
		v[i].pb(i);
		cnt[i]=cnt[now]+c[i];
	//	rep(j,num)cout<<v[i][j]<<" ";
	//	cout<<endl;
	//	rep(j,num)cout<<cnt[v[i][j]]<<" ";
	//	cout<<endl;
		if(gg<=num)
		{
			rep(j,gg)
				if(cnt[v[i][j]]>mx)mx=cnt[v[i][j]];
			ans=max(ans,mx); 
			continue;
		}
		if(cnt[i]<0)
		{ 
			rep(j,num)
				if(cnt[v[i][j]]>mx)mx=cnt[v[i][j]];
			ans=max(ans,mx);
			continue;
		}
		ll g=gg;
		ll q=gg/num;
	//	cout<<q<<endl;
		res+=q*cnt[i];
		gg%=num;
		rep(j,gg)
			if(cnt[v[i][j]]>mx)mx=cnt[v[i][j]];
		res+=mx;
		ans=max(ans,res);
		ll res1=0;
		mx=-100000000000009;
		rep(j,num)
			if(cnt[v[i][j]]>mx)mx=cnt[v[i][j]];
		res1+=(q-1)*cnt[i];
		res1+=mx;
		ans=max(ans,res1);
	//	cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 121312
N = int(input())
A = list(map(int, input().split()))
C = []

num = 0
for i in range(N):
    num += A[i]
    C.append(num)
A.reverse()
D = []
num = 0
for i in range(N):
    num += A[i]
    D.append(num)
D.reverse()
ans = float('inf')
for i in range(0, N - 1):
    ans = min(ans, abs(C[i] - D[i + 1]))
print(ans)

Measured memory_bytes: 28604
import sys
import bisect

n = int(input())
l = list(map(int, sys.stdin.readline().strip().split()))

l. sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        a = l[i]
        b = l[j]
        ab = a + b
        right = bisect.bisect_left(l, ab) - 1
        ans += (right - j)

print(ans)


Measured memory_bytes: 43884
/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 */
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=4e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

void solve() {
	int n;
	cin>>n;
	vector<pii> lol;
	fr(i,1,n) {
		int tim,ded;
		cin>>tim>>ded;
		lol.pb({ded,tim});
	}
	sort(all(lol));
	int hol=0;
	for(auto i:lol) {
		hol+=i.se;
		if(hol>i.fi) {
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 6384
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  var cnt = 0
  val l = new Array[Int](250001)
  val r = new Array[Int](250001)
  var a:Array[Int] = null

  def merge(left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      cnt += 1
    }
  }

  def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1
      w /= 2
    }

    def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] = {
      if(h==0) l
      else
        scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    a = readLine.split(" ").map(_.toInt)
    val l = getSortIndex(n)
    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(e._1,mid,e._2)
      }
    }
    merge(0,n/2,n)
    println(a.mkString(" "))
    println(cnt)
  }
}

Measured memory_bytes: 319876
#include <bits/stdc++.h>
#define ll 1000000000000000000
using namespace std;
int main(void){
    
    int n;
    unsigned long long int ans = 1;
    cin >> n;
    unsigned long long int a[n];
    int b=0;
    
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]==0) b = 1;
    }
    
    if(b==1) {
        cout << 0 << endl;
        return 0;
    }
    
    for(int i=0;i<n;i++) {
        
        
        if(a[i] > ll/ans) {
            cout << -1 << endl;
            return 0;
        }
        
        ans *= a[i];
    }
    
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x;
  int ans = 0;
  cin >> a >> b >> c >> x;
  for(int i=0; i<=a; i++)
    for(int j=0; j<=b; j++)
      for(int k=0; k<=c; k++)
        if(500 * i + 100 * j + 50 * k == x) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<vector<int>>rot(vector<vector<int>>v) {
	vector<vector<int>>rotated(v);
	for (int i = 0; i < v.size(); ++i) {
		for (int j = 0; j < v.size(); ++j) {
			rotated[i][j]=v[v.size()-j-1][i];
		}
	}
	return rotated;
}

pair<int,int> check(vector<vector<int>>&f, vector<vector<int>>&p, int l, int u) {
	pair<int,int>ans(10000,10000);;
	for (int x = l; x < l + p.size(); ++x) {
		for (int y = u; y < u + p.size(); ++y) {
			if (p[y - u][x - l] != -1) {
				ans=min(ans,make_pair(y,x));
				if (f[y][x] != p[y - u][x - l])return make_pair(10000, 10000);

			}
		}
	}
	return ans;
}
int main() {
	while (true) {
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<vector<int>>field(N,vector<int>(N));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin>>field[i][j];
			}
		}
		vector<vector<int>>picture(M,vector<int>(M));
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < M; ++j) {
				cin >> picture[i][j];
			}
		}
		pair<int,int>ans(10000,10000);
		for (int l = 0; l <= N - M; ++l) {
			for (int u = 0; u <= N - M; ++u) {
				for (int k = 0; k < 4; ++k) {
					picture=rot(picture);
					ans=min(ans,check(field,picture,l,u));
				}
			}
		}
		if (ans.first == 10000) {
			cout<<"NA"<<endl;
		}
		else {
			cout<<ans.second+1<<" "<<ans.first+1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3140
bingo=[list(map(int,input().split())) for i in range(3)]
N=int(input())
number=[list(map(int,input().split())) for i in range(N)]

#print(bingo)
#print(number)
check=[0,0,0,0,0,0,0,0,0]
ans=0
for i in range(N):
    for j in range(3):
        for k in range(3):
            if number[i][0]==bingo[j][k]:
                check[3*j+k]=1
                
                
                
for i in range(3):
    if check[0+3*i]==check[1+3*i]==check[2+3*i]==1:
        ans=1
    if check[i]==check[i+3]==check[i+6]==1:
        ans=1
        
if check[0]==check[4]==check[8]==1:
    ans=1
if check[2]==check[4]==check[6]==1: 
    ans=1
    
if ans==1:
    print("Yes")
else:
    print("No")
    
#print(check)

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

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    if(a==b&&a!=c&&b!=c)
      cout<<"Yes";
    else if(a==c&&a!=b&&c!=b)
      cout<<"Yes";
    else if(b==c&&b!=a&&c!=a)
      cout<<"Yes";
    else
      cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N, K;
	cin >> N >> K;
	vector<int> V(N);
	for(int i = 0; i < N; i++) cin >> V[i];

	int res = 0;
	for(int i = 0; i <= K and i <= N; i++){ // i個取ってK-i個戻す
		for(int j = 0; j <= i; j++){ // 左からj個, 右からi-j個取る
			vector<int> vec;
			for(int k = 0; k < j; k++) vec.push_back(V[k]);
			for(int k = 0; k < i-j; k++) vec.push_back(V[N-1-k]);
			sort(vec.begin(), vec.end());
			int val = accumulate(vec.begin(), vec.end(), 0);
			for(int k = 0; k < K-i and k < vec.size(); k++){
				if(vec[k] < 0) val -= vec[k];
			}
			res = max(res, val);
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, r;
	while (cin >> n >> r, n)
	{
		int a[51];
		for (int i = 1;i <= n;i++)a[i] = n - i + 1;
		for (int i = 0;i < r;i++)
		{
			int p, c;cin >> p >> c;
			int b[51];
			for (int j = 1;j < p;j++)b[j] = a[j];
			for (int j = p;j < p + c;j++)a[j - p + 1] = a[j];
			for (int j = 1;j < p;j++)a[c + j] = b[j];
		}
		cout << a[1] << endl;
	}
}

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

int main(){
  int N,M,cnt = 0, ans = 0;

  cin >> N >> M;
  
  int *a,*b;

  a = new int[M];
  b = new int[M];
  
  for(int i = 0;i<M;++i){
    cin >> a[i] >> b[i];

    if(a[i] >= N){
      ++cnt;
    }
  }
  
  sort(a,a+M);
  reverse(a, a+M);

  int counter = 0;
  for(int i=cnt+1; i<=M-1;++i){
    if(a[counter] < N){
      ans += N - a[counter];
    }else{
      --i;
    }
    ++counter;
  }

  cout << ans << endl;
			    
  delete[] a;
  delete[] b;
  return 0;
}



Measured memory_bytes: 3116
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int ABCD;
int x[4];

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

	cin >> ABCD;

	int ans = -1;

	rep(i, 0, 4)
	{
		x[3 - i] = ABCD % 10;
		ABCD /= 10;
	}

	rep(i, 0, 8)
	{
		int t = x[0];
		rep(j, 0, 3)
		{
			if (i&(1 << j))
			{
				t += x[j + 1];
			}
			else
			{
				t -= x[j + 1];
			}
		}
		if (t == 7)
		{
			ans = i;
			break;
		}
	}

	if (ans == -1)
	{
		cout << "No answers" << endl;
	}

	rep(i, 0, 3)
	{
		cout << x[i] << ((ans&(1 << i)) ? '+' : '-');
	}
	cout << x[3] << "=7" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
#define M 1006000
#define L 14
 
char H[M][L]; /* Hash Table */
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 
/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
 
int find(char str[]){
    long long key,i,h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}
 
int insert(char str[]){
 
    long long key, i, h;
    key = getKey(str);
    for(int i=0;;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0) return 1;
        else if(strlen(H[h]) == 0) {
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
        scanf("%s %s", com, str);
         
        if ( com[0] == 'i' ){
            insert(str);
        } else {
            if (find(str)){
            printf("yes\n");
            } else {
            printf("no\n");
            }
        }
    }
 
    return 0;
}
 

Measured memory_bytes: 14788
import sys
n =int(input())
h = map(int,input().split())
h = list(h)

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
    for j in range(i+1,i+2+1):
        if j<n :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[n-1])

Measured memory_bytes: 13980
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 1000000
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    char cube[SIZE];
    char under_cube;
    int i,count = 0,answer = 0;
    scanf("%s",cube);
    //最初のノードの指す先
    node *first = NULL;
    /* 文字の数だけループ */
    for ( i = 0; i < strlen(cube); i++)
    {
        if (count == 0)
        {
            /* stackがからの場合、挿入 */
            push(&first,cube[i]);
            count += 1;
        }
        else
        {
            if (first->elem == cube[i])
            {
                /* 1か0が連続している場合、stackに追加 */
                push(&first,cube[i]);
                count += 1;
            }
            else
            {
                /* 連続していない場合は、追加せず */
                answer += 2;
                pop(&first);
                count -= 1;
            }
            
        }
        
    }
    printf("%d\n",answer);
    return 0;
}


Measured memory_bytes: 4920
fn solve() {
    let stdin = std::io::stdin();
    let mut scn = Scanner {
        stdin: stdin.lock(),
    };
    let h: usize = scn.read();
    let w: usize = scn.read();
    let n: usize = scn.read();
    let a: Vec<usize> = scn.vec(n);
    let mut board = vec![vec![0; w]; h];
    let mut y = 0;
    let mut x = 0;

    let mut dir: i32 = 1;
    for (c, v) in a.iter().enumerate() {
        let mut colored = 0;
        while colored < *v {
            board[y as usize][x as usize] = c + 1;
            x += dir;
            if x >= w as i32 {
                y += 1;
                x = w as i32 - 1;
                dir *= -1;
            }
            if x < 0 {
                y += 1;
                x = 0;
                dir *= -1;
            }
            colored += 1;
        }
    }
    for y in 0..h {
        for x in 0..w {
            print!("{} ", board[y][x]);
        }
        println!("");
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


int main(){
    string s, t;
    cin >> s;
    t = s;
    reverse(all(s));
    ll ans = 0;
    rep(i, s.size()){
        if(s[i] != t[i]) ans++;
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 3640
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  double L;
  cin >> L;
  L /= 3;
  out(L * L * L)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int h, w;
    cin >> h >> w;
    vector<set<int>> vs(h);
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            char c;
            cin >> c;
            if(c == '#') vs[i].insert(j);
        }
    }
    int r = 0;
    for(int i = 0; i < h; i++)
    {
        int l = *vs[i].begin();
        if(l != r)
        {
            cout << "Impossible" << endl;
            return 0;
        }
        r = *vs[i].rbegin();
    }
    cout << "Possible" << endl;
}




Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long h,w;
    cin>>h>>w;
    if(h==1) cout<<1<<endl;
    else if ( w == 1 ) cout<<1<<endl;
    else{
    cout<< w*(h/2) + (h%2)*( (w+1) /2)<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

double t, x;

int main() {
    scanf("%lf%lf", &t, &x);

    printf("%lf\n", t / x);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ll long long
#define rg register
#define gc getchar()
#define rp(i,x,y) for(rg int i=x;i<=y;++i)

const int N=200000+10;
int n,q,fa[N];
ll mn[N<<1],as;
struct ed{int fr,to;ll wei;};
vector<ed>edge;

il int read()
{
    rg char ch=gc;rg int x=0;rg bool y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il ll readl()
{
    rg char ch=gc;rg ll x=0;rg bool y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il bool cmp(ed x,ed y){return x.wei<y.wei;}
il int fd(int x){return fa[x]==x?x:fa[x]=fd(fa[x]);}


int main()
{
// 	freopen("zm.in","r",stdin);freopen("zm.out","w",stdout);
    n=read();q=read();memset(mn,127/3,sizeof(mn));
    while(q--){int a=read()%n+1,b=read()%n+1;ll c=readl();mn[a]=min(mn[a],c+1);mn[b]=min(mn[b],c+2);edge.push_back((ed){a,b,c});}
    rp(i,1,n<<1)mn[i]=min(mn[i],mn[i-1]+2);rp(i,1,n)edge.push_back((ed){i,i%n+1,min(mn[i],mn[i+n])});sort(edge.begin(),edge.end(),cmp);
    rp(i,1,n)fa[i]=i;int sz=edge.size();rp(i,0,sz-1){int fafr=fd(edge[i].fr),fato=fd(edge[i].to);if(fafr^fato)as+=edge[i].wei,fa[fafr]=fato;}
    printf("%lld\n",as);
    return 0;
}


Measured memory_bytes: 14312
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>
#include <stack>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
ld eps = (ld)1 / 1e15;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[101];

int main()
{
    //freopen("race.in", "r", stdin), freopen("race.out", "w", stdout);
    fast_io;
    ll n, i, j, s = inf, k;
    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= 100; i++)
    {
        k = 0;
        for (j = 1; j <= n; j++)
            k += sqr(i - a[j]);
        s = min(s, k);
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int main(int argc, char** argv)
{
    char kkm[maxn];
    scanf("%s",&kkm[1]);
    int tot=0;
    ll ans=0;
    if(kkm[1]=='W') tot=1;
    for(int i=2;kkm[i]!='\0';i++)
    {
        if(kkm[i]=='W')
        {
            tot++;
            ans+=i-tot;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
a,b=map(int,input().split())
if a==4 or a==6 or a==9 or a==11 : a=2
elif a==2:a=3 
else: a=1
if b==4 or b==6 or b==9 or b==11 : b=2
elif b==2:b=3 
else:b=1

print("Yes" if a==b else "No")

Measured memory_bytes: 3060
#include <cstdio>
#include <map>
#include <vector>

#define MAXN 100003

std::map <int, int> mp;
std::vector <int> g[MAXN];

int ans, k;
bool viz[MAXN];
int t[MAXN];
int a[MAXN], b[MAXN];
int v[MAXN];
int ind[MAXN], per[MAXN];

int sef(int x) {
    if (x == t[x]) return x;
    else return t[x] = sef(t[x]);
}

inline void baga(int i) {
    if (a[i] == b[i])
        return ;
    ans++;
    int &u = mp[b[i]];
    if (u == 0)
        u = ++k;
    g[u].push_back(i);
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        a[n + 1] ^= a[i];
    }

    bool ok = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
        b[n + 1] ^= b[i];
        ok |= (b[i] == a[n + 1]);
        baga(i);
    }
    baga(n + 1);

    if (a[n + 1] != b[n + 1])
        ans--;

    int poz = 1;
    bool sol = 1;
    while(poz <= n + 1 && sol) {
        if (a[poz] != b[poz]) {
            int &u = mp[a[poz]];
            if (ind[u] < (int)g[u].size()) {
                v[poz] = g[u][ind[u]];
                per[g[u][ind[u]]] = poz;
                ind[u]++;
            }
            else sol = 0;
        }
        poz++;
    }

    if(sol == 0) {
        printf("-1\n");
        return 0;
    }

    for (int i = 1; i <= n + 1; i++) {
        if (viz[i] == 0 && v[i]) {
            int x = i;
            t[x] = i;
            ans++;
            viz[x] = 1;
            x = v[x];
            while (viz[x] == 0) {
                viz[x] = 1;
                t[x] = i;
                x = v[x];
            }
        }
    }

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j < (int)g[i].size(); j++) {
            int x = sef(per[g[i][j - 1]]), y = sef(per[g[i][j]]);
            if (x != y) {
                ans--;
                t[x] = y;
            }
        }
    }

    if (ans && ok)
        ans--;

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 12800
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;
#define ASCII 48
int main() {
	int n;	//回数
	int h;	//高さ
	int maxHeight = 0;	//最大高さ

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h;
		if (maxHeight - h > 1) {
			cout << "No" << endl;
			return 0 ;
		}
		if (h > maxHeight)maxHeight = h;
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)
const int MOD=1e9+7;

int main(){
    string s;
    cin >> s;
    long x[4]={0};
    F(4) x[i]=s[i]-'0';
    for(int i=0;i<8;++i){
        long sum=x[0];
        if(i<4) sum += x[1];
        else sum -= x[1];
        if(i%4<2) sum += x[2];
        else sum -= x[2];
        if(i%2==0) sum += x[3];
        else sum -= x[3];
        if(sum==7){
            cout << x[0];
            if(i<4) cout << '+';
            else cout << '-';
            cout << x[1];
            if(i%4<2) cout << '+';
            else cout << '-';
            cout << x[2];
            if(i%2==0) cout << '+';
            else cout << '-';
            cout << x[3] << "=7" << endl;
            break;
        }
        sum=0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

vector<vector<int>> id;
vector<vector<int>> to;
vector<int> ans;

int dfs(int v, int before=-1, int color=-1){
	int k = 1;
	rep(i, to[v].size())
	{
		if(to[v][i]==before)
			continue;
		int index = id[v][i];
		if(k==color)
			k++;
		ans[index] = k;
		dfs(to[v][i], v, k);
		k++;
	}
	return 0;
}
int main()
{
	int n;
	cin >> n;
	to.resize(n);
	id.resize(n);
	ans.resize(n);
	rep(i, n-1)
	{
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		id[a].push_back(i);
		to[b].push_back(a);
		id[b].push_back(i);
	}
	dfs(0);
	int mans = 0;
	rep(i,n-1){
		mans = max(mans, (int)to[i].size());
	}
	cout << mans << endl;
	rep(i, n - 1)
	{
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 12032
n = int(input())
stack = []
for _ in range(n):
    stack.append(int(input()))

maxv = -10**9
minv = stack[0]
for i in range(1, len(stack)):
    maxv = max(maxv, stack[i] - minv)
    minv = min(minv, stack[i])

print(maxv)

Measured memory_bytes: 15532
#include<stdio.h>

int selectionSort(int A[],int N){
  int i,j,k,count=0,minj;
  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj=j;
    }
    k=A[i];
    A[i]=A[minj];
    A[minj]=k;
    if(i!=minj)count++;
  }
  return count;
}


int main(){
  int A[100],N,i,count;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  count=selectionSort(A,N);
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2144
l=gets.chomp.to_i
a=gets.chomp.to_i
b=gets.chomp.to_i
c=gets.chomp.to_i
d=gets.chomp.to_i

m=a/c
n=b/d
if a%c>0
  m+=1
end
if b%d>0
  n+=1
end
puts l-[m,n].max

Measured memory_bytes: 6092
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	fast();
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int arr[n];
		for(int i=0;i<n;i++)
		cin>>arr[i];
		int ans=0;
		for(int i=1;i<n;i++)
		{
			if(arr[i]<arr[i-1])
			{
				ans+=(arr[i-1]-arr[i]);
				arr[i]=arr[i-1];
			}
		}
		cout<<ans<<endl;
	}
}








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

int n, s[100010];

bool bsearch( int key ){
    int l = 0, r = n;
    while( l < r ){
        int m = ( r + l )/ 2;
        if( s[m] == key ){
            return true;
        }
        else if( key < s[m] ){
            r = m;
        }
        else {
            l = m + 1;
        }
    }
    return false;
}

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

    int q, t, cnt = 0;
    cin >> q;
    for( int i = 0; i < q; i++ ) {
        cin >> t;
        
        cnt += bsearch( t );
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3368
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 3e5 + 20;
const ll inf = 1e18 + 7;

int n, m;
ll t[4 * N], how[4 * N];

void push(int v) {
	if (how[v] == 0) re;
	t[2 * v + 1] += how[v];
	t[2 * v + 2] += how[v];
	how[2 * v + 1] += how[v];
	how[2 * v + 2] += how[v];
	how[v] = 0;
}

void modify(int v, int tl, int tr, int l, int r, ll x) {
	if (tl > r || l > tr) re;
	if (l <= tl && tr <= r) {
		how[v] += x;
		t[v] += x;
		re;
	}
	push(v);
	int c = (tl + tr) >> 1;
	modify(2 * v + 1, tl, c, l, r, x);
	modify(2 * v + 2, c + 1, tr, l, r, x);
	t[v] = max(t[2 * v + 1], t[2 * v + 2]);
}

ll get(int v, int tl, int tr, int l, int r) {
	if (tl > r || l > tr || l > r) re -inf;
	if (l <= tl && tr <= r) re t[v];
	push(v); int c = (tl + tr) >> 1;
	re max(get(2 * v + 1, tl, c, l, r), get(2 * v + 2, c + 1, tr, l, r));
}

int a[N];
ii seg[N];
vi b[N], e[N];
ll dp[N];							 

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r, z;
		scanf("%d%d%d", &l, &r, &z);
		l--; r--;
		a[i] = z; seg[i] = {l, r};
		b[l].pb(i); e[r].pb(i);
	}
	ll cur = 0;
	for (int i = 0; i < n; i++) {
		for (auto x : b[i])
			cur += a[x];
		dp[i] = cur;
		for (auto x : b[i])
			modify(0, 0, n - 1, seg[x].fi, seg[x].se, -a[x]);
		ll ans = get(0, 0, n - 1, 0, i - 1);
		ans = max((ll)0, ans);
		dp[i] = ans + cur;
		modify(0, 0, n - 1, i, i, dp[i]);
		for (auto x : e[i]) 
			modify(0, 0, n - 1, seg[x].fi, seg[x].se, a[x]), cur -= a[x];
	}
	cout << *max_element(dp, dp + n + 1) << endl;
}

Measured memory_bytes: 43008