akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            if ((x == 0) && (y == 0)) {
                break;
            }
            if (x > y) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            System.out.println(x + " " + y);
        }
        sc.close();
    }
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)

typedef long long ll;

int main(){
    int n;
    cin>>n;
    vector<int> A(n);
    ll ans=0;
    map<int,int> mp;
    rep(i,n){
        int a;
        cin>>a;
        ans += mp[i-a];
        mp[a+i]++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 21056
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll R, G, B, N;
ll ans = 0;

int main() {
	cin >> R >> G >> B >> N;
	for (int i = 0; i*R <= N; i++) {
		for (int j = 0; i*R + j*G <= N; j++) {
			if ((N - i*R - j*G) % B == 0)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a,b;
  cin >>a >>b;
  if(a%2 == 0 || b%2 == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
using namespace std;
string s;
int ans,totg,totp;//totg>=totp
int main(){
	cin>>s;
	if(s[0]=='p') ans++;
	totg++;
	for(int i=1;i<s.size();i++)
	  if(totg<=totp)
	  	if(s[i]=='p') ans--,totg++;
	  	else totg++;
	  else
	    if(s[i]=='p') totp++;
	    else ans++,totp++;
	cout<<ans;
}

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

const int INF = numeric_limits<int>::max();

struct edge {
    int u, v, c;
};
struct Graph {
    vector<edge> es;
    vector<int> d;
    Graph(int n) {
        d.assign(n, INF);
    }
};

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            g.es.push_back({u, v, c});
        }
    }

    g.d[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (edge e : g.es) {
            if (g.d[e.u] != INF && g.d[e.v] > g.d[e.u] + e.c) {
                g.d[e.v] = g.d[e.u] + e.c;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << g.d[i] << endl;
    }
}


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

const long long MOD = 1000000007;

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

    vector<int> b(n + 1, true);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        b[a] = false;
    }

    vector<long long> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        if (b[i + 1]) {
            dp[i + 1] += dp[i];
            dp[i + 1] %= MOD;
        }
        if (b[i + 2] && (i != n - 1)) {
            dp[i + 2] += dp[i];
            dp[i + 2] %= MOD;
        }
    }

    /*
    for (int i = 0; i <= n; i++) {
        cout << dp[i] << endl;
    }
    */

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>


int main()
{
  double x1,y1,x2,y2;
  double dist;

  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

  dist = sqrt(pow(x1-x2,2)+pow(y1-y2,2));

  printf("%lf",dist);


  return(0);

}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdio>
#define mst(a,b) memset(a,b,sizeof(a))
#define rev(x) reverse(x,x+strlen(x))
using namespace std;
const int inf=1<<29;
typedef long long ll;
struct plant
{
    int a[10];
}b[100];
int main()
{
    int n,d,res=0;
    double c;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++)
            scanf("%d",&b[i].a[j]);
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            c=0.0;
            for(int k=0;k<d;k++){
                c+=(b[i].a[k]-b[j].a[k])*(b[i].a[k]-b[j].a[k]);
            }
            if(sqrt(c)==(int)sqrt(c)) res++;
        }
    }
    cout<<res<<endl;
    return 0;

}


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

int main(){

    int K,X,ans_min,ans_max;
    cin >>K>>X;
    ans_min=X-K+1;
    ans_max=X+K-1;

    for(int i=ans_min;i<ans_max+1;i++){
      cout<<i<<" ";
    }
    cout<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  for (int i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end(),greater<int>());
  int sum=0;
  for(int i=0;i<k;i++){
    sum+=l[i];
  }
  cout << sum << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int H, W; scanf("%d %d", &H, &W);
  int N; scanf("%d", &N);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  int r = 0, c = 0;
  int dir = 1;
  vector<vector<int> > grid(H, vector<int>(W, -1));
  for (int i = 0, color = 1; i < N; ++i, ++color) {
    for (int cnt = 0; cnt < A[i]; ++cnt) {
      grid[r][c] = color;
      c += dir;
      if (c == W) {
        c = W - 1;
        dir = -1;
        ++r;
      }
      else if (c == -1) {
        c = 0;
        dir = 1;
        ++r;
      }
    }
  }
  for (int i = 0; i < H; ++i) {
    printf("%d", grid[i][0]);
    for (int j = 1; j < W; ++j) {
      printf(" %d", grid[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vpii = vector<pii>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
int main() {
	int t, p, r;
	while (cin >> t >> p >> r, t) {
		vector<tuple<int, int, int, vi>> buf(t, make_tuple(0, 0, 0, vi(p + 1)));//-ac,pena,team
		rep(i, t) {
			get<2>(buf[i]) = i + 1;
		}
		rep(j, r) {
			int t, p, time;
			string mes;
			cin >> t >> p >> time >> mes;
			t--;
			get<3>(buf[t])[p] +=(mes[0]=='W'?1200:time);
			if (mes[0] == 'C') {
				get<0>(buf[t])--;
				get<1>(buf[t]) += get<3>(buf[t])[p];
			}
		}
		sort(ALL(buf));
		for (auto &a : buf) {
			cout << get<2>(a) <<' '<< -get<0>(a) <<' '<< get<1>(a) << endl;
		}
	}
}

Measured memory_bytes: 3208
package main
import "fmt"
func main(){
    // Your code here!
    var a,b,c,ans int
    fmt.Scan(&a)
    fmt.Scan(&b)
    fmt.Scan(&c)
    ans = c - (a-b)

    if ans < 0 {
        ans = 0
    }
    fmt.Println(ans)
}


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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
ll isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return i;
    }
    return 1;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%MOD;
    ll temp=power(a,b/2);
    if(b%2==0)
        return ((temp%MOD)*(temp%MOD))%MOD;
    else
        return ((((temp%MOD)*(temp%MOD))%MOD)*a%MOD)%MOD;
}

/*-----------------------------------------------------------------------------*/
//ll dp[100001][100001]={0};
ll fun(ll a,ll b)
{
    ostringstream str1;
    str1<<a;
    string s1=str1.str();
    ostringstream str2;
    str2<<b;
    string s2=str2.str();
    string s="";
    for(ll i=0;i<s1.length();i++)
    {
        s+=s1[i];
        s+=s2[i];
    }
    stringstream g(s);
    ll x=0;
    g>>x;
    return x;
}
int main()
{
    //ios_base::sync_with_stdio(false);
	//cin.tie(NULL);


    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n+1],b[n];
        for(ll i=0;i<=n;i++)
            cin>>a[i];
        for(ll j=0;j<n;j++)
            cin>>b[j];
        ll sum=0;
        for(ll i=0;i<n;i++)
        {
            if(a[i]<b[i])
            {
                sum+=a[i];
                b[i]-=a[i];
                a[i]=0;
                if(a[i+1]<b[i])
                {
                    sum+=a[i+1];
                    a[i+1]=0;
                }
                else
                {
                    sum+=b[i];
                    a[i+1]-=b[i];
                    b[i]=0;
                }
            }
            else
            {
                sum+=b[i];
                a[i]-=b[i];
            }
        }
        cout<<sum;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};


// dijikstra
/* int V;
vector<edge> G[10];
int d[10];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int main(){
    int n, k;
    cin >> n >> k;
    bool d[11];
    REP(i, 11){
        d[i] = false;
    }
    REP(i, k){
        int tmp;
        cin >> tmp;
        d[tmp] = true;
    }
    int i = n;
    while(1){
        int tmp = i;
        bool f = true;
        while(tmp){
            int x = tmp % 10;
            if(d[x]){
                f = false;
                break;
            }
            tmp /= 10;
        }
        if(f){
            cout << i << endl;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 256
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

#define maxn 100005
struct Node{
	int A,B,C;Node(){}Node(int A,int B,int C):A(A),B(B),C(C){}
	// int delta(){return A-B;}
	bool operator <(const Node&p)const{
		return A-B>p.A-p.B;
	}
	void readin(){read(A);read(B);read(C);}
};
int X,Y,Z;
Node num[maxn];
priority_queue<int>heap_max;
priority_queue<int,vector<int>,greater<int> >heap_min;
ll f[maxn],g[maxn];
int main(){
	read(X);read(Y);read(Z);int all=X+Y+Z;
	rep(i,1,all)num[i].readin();sort(num+1,num+all+1);
	ll ans=0;
	rep(i,1,all)num[i].A-=num[i].C,num[i].B-=num[i].C,ans+=num[i].C;
	// puts("");
	// rep(i,1,all)printf("%d %d %d\n",num[i].A,num[i].B,num[i].C);
	while (!heap_max.empty())heap_max.pop();
	while (!heap_min.empty())heap_min.pop();
	rep(i,1,X)heap_min.push(num[i].A),f[X]+=num[i].A;
	rep(i,X+1,all){
		heap_min.push(num[i].A);f[i]=f[i-1]+num[i].A;
		int x=heap_min.top();heap_min.pop();f[i]-=x;
		heap_max.push(x);
	}

	while (!heap_max.empty())heap_max.pop();
	while (!heap_min.empty())heap_min.pop();
	per(i,all,all-Y+1)heap_min.push(num[i].B),g[all-Y+1]+=num[i].B;
	per(i,all-Y,1){
		heap_min.push(num[i].B);g[i]=g[i+1]+num[i].B;
		int x=heap_min.top();heap_min.pop();g[i]-=x;
		heap_max.push(x);
	}

	// rep(i,1,all)printf("%lld %lld\n",f[i],g[i]);

	ll res=-(ll)1e18;
	rep(i,X,all-Y){
		res=max(res,f[i]+g[i+1]);
	}
	printf("%lld\n",ans+res);
	return 0;
}

Measured memory_bytes: 3340
// abc135c: City Savers
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define downto(i,s,e,d) for(int i=(s);i>(e);i-=(d))
#define in(x) cin>>(x)
#define out(x) cout<<(x)
#define oute(x) cout<<(x)<<endl

void p1(vi a){
  upto(i,0,a.size(),1) cout<<a[i]<<",";
}
void p2(vvi &x){
  for(auto v: x){
    cout<<"["; p1(v); cout<<"]\n";
  }
}

int main(){
  int n;in(n);
  // oute(n);//////

  vi a(n+1);
  upto(i,0,n+1,1){
    in(a[i]);
  }
  // p1(a);out("\n");///////

  vi b(n);
  upto(i,0,n,1){
    in(b[i]);
  }
  // p1(b);out("\n");///////

  ll m = 0;
  int i=0;
  while(i<n){
    int mini= min(a[i],b[i]);
    a[i]-=mini;
    b[i]-=mini;
    m+=mini;
    if(a[i]<=0 && b[i]>0){
      mini = min(a[i+1],b[i]);
      a[i+1]-=mini;
      m+=mini;
    }
    i++;
  }
  // p1(a);out("\n");///////
  // p1(b);out("\n");///////

  oute(m);

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define range(i,a,b) for(long long i = (a); i < (b); i++)
#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
 
template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

vector<int> win(10000, 0);

int main(){
	int n, h, w;
	while(cin >> n >> h >> w){
		rep(i,n){
			int x;
			cin >> x;

			if(i % 2){
				win[i * w - x]++;
				win[i * w + w - x]--;
			}else{
				win[i * w + x]++;
				win[i * w + x + w]--;
			}
		}
		//rep(i,n * w){ cout << win[i] << ' '; } cout << endl;
		rep(i,n * w - 1){
			win[i + 1] += win[i];
		}

		//rep(i,n * w){ cout << win[i] << ' '; } cout << endl;

		int ans = 0;
		rep(i,n * w){
			ans += win[i] <= 0;
		}
		cout << ans * h << endl;
	}
}



Measured memory_bytes: 3164
#include<iostream>
using namespace std ;
int main()
{
	int n=0 , m=0 , l=0 ;
	long long int a=0 ;
	cin >> n >> m >> l ;
	long long int nm[100][100] , ml[100][100] ;
	for(int i=0;i<n;i++)
	{
		for(int ia=0;ia<m;ia++)
		{
		cin >> 	a ;
		nm[i][ia]=a ;
		}
	}
	for(int i=0;i<m;i++)
	{
		for(int ia=0;ia<l;ia++)
		{
			cin >> 	a ;
			ml[i][ia]=a ;
		}
	}
	a=0 ;
	for(int i=0;i<n;i++)
	{
		for(int ia=0;ia<l;ia++)
		{
			for(int ib=0;ib<m;ib++)
			{
				a=a+nm[i][ib]*ml[ib][ia] ;
			}
			cout << a ;
			if(ia!=l-1) cout << " " ;
			a=0 ;
		}
		cout << endl ;
	}
	return 0 ;
}



Measured memory_bytes: 3248
N,K,Q=map(int, input().split())
score=[Q]*N
#print(score)
for j in range(Q):
  c=int(input())
  score[c-1] += -1
 
#print(score)

for j in range(N):
  if score[j]<K:
    print('Yes')
  else:
    print('No')
 





Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0);
#define fore(i, a, b) for(int i = a; i < b; i++)
#define fori(i, a, b) for(lli i = a; i <= b; i++)
#define pb push_back
#define popb pop_back
#define mk make_pair
#define fi first
#define se second
#define endl '\n'
#define MAX 60
typedef long long int lli;
typedef long double ld;
const double PI = acos(-1.0);
ld eps = 1e-9;

int main() {
	optimizar_io
	lli k;
	cin >> k;
	lli ans = 0;
	fori(i, 1, k) {
		fori(j, 1, k) {
			fori(h, 1, k) {
				lli aux = __gcd(i, j);
				ans += __gcd(aux, h);
			}
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;

struct State
{
    int len;
    char c;
    pair<int, int> prev;
    State()
    {
        // Nothing to do here.
    }
    State(int len, char c, int i, int j) :
            len(len), c(c), prev(make_pair(i, j))
    {
        // Nothing to do here.
    }
};

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

    int t = 1;
    // cin >> t;
    while (t--)
    {
        
        int h, w;
        cin >> h >> w;
        char grid[h][w];
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                cin >> grid[i][j];

        ll dp[h + 1][w + 1] ;
        for (int i = 0; i <= h; i++)
            dp[i][0] = 0;
        for (int i = 0; i <= w; i++)
            dp[0][i] = 0;
        
        dp[1][0] = 1;
        dp[0][1] = 0;
        
        for (int i = 1; i <= h; i++)
        {
            for (int j = 1; j <= w; j++)
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] = dp[i][j] % 1000000007;
                if (grid[i - 1][j - 1] == '#')
                    dp[i][j] = 0;
            }
        }
        cout << dp[h][w];
    }
    return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;

vector<int> w,r;
int main(){
    int n;
    string str;
    scanf("%d",&n);
    cin>>str;
    for(int i=0;i<n;i++){
        if(str[i]=='W') w.pb(i);
        else if(str[i]=='R') r.pb(i);
    }

    if(r.size()==0){
        printf("0");
        return 0;
    }
    reverse(r.begin(),r.end());

    int t=0,flag=1;
    ll ans=0;
    for(auto x:w){
        if(x<r[t]&&t<r.size()-1){
            ans++;
            t++;
        }
        else if(x<r[t]&&t==r.size()-1&&flag)
            ans++,flag=0;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 4740
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
int main(){
  ll a,b;cin>>a>>b;
  ll x,r,t;
  x=a*b;
  t=b;
  if(a<b)
  {
    t=a;
    a=b;
  }
  r=a%t;
  while(r!=0)
  {
    a=t;
    t=r;
    r=a%t;
  }
  cout<<x/t;
}
  
    
    

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

int main() {
  int h, w;
  cin >> h >> w;
  int a[h][w];
  int i, j, k, l;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> a[i][j];
    }
  }
  int cost[h][w], min_cost = 10000000;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cost[i][j] = 0;
      for (k = 0; k < h; k++) {
        for (l = 0; l < w; l++) {
          cost[i][j] += min(fabs(i - k), fabs(j - l)) * a[k][l];
        }
      }
      min_cost = min(min_cost, cost[i][j]);
    }
  }
  cout << min_cost << endl;
  return 0;
}



Measured memory_bytes: 3096
N = int(input())
Ws = list(map(int, input().split()))

s = Ws[0]
S = sum(Ws) - s
D = S - s
minD = abs(D)
for i in range(1, N-1):
    D -= 2*Ws[i]
    if abs(D)<minD:
        minD = abs(D)
print(minD)

Measured memory_bytes: 3064
def main():
	# a,b,k = map(int,input().split())
	# n,k = map(int,input().split())
	dish = []
	for i in range(5):
		dish.append(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(5)]
	# s = list(s)
	
	import itertools
	kumi = list(itertools.permutations(dish,5))
	# print(kumi)
	time = 0
	time_ans = []
	for i in range(len(kumi)):
		# print("---i = {}---".format(i))
		time += int(kumi[i][0])
		# print("dish 0's time = {}".format(time))
		while time % 10 != 0:
			time += 1
		time += int(kumi[i][1])
		# print("dish 1's time = {}".format(time))
		while time % 10 != 0:
			time += 1
		time += int(kumi[i][2])
		# print("dish 2's time = {}".format(time))
		while time % 10 != 0:
			time += 1
		time += int(kumi[i][3])
		# print("dish 3's time = {}".format(time))
		while time % 10 != 0:
			time += 1
		time += int(kumi[i][4])
		# print("dish 4's time = {}".format(time))
		
		time_ans.append(time)
		time = 0
	print(min(time_ans))


 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38512
/*Author: Gautam*/
 
 
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<int,int>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
int comp(const void* a, const void* b)  
{ return *(int*)a > *(int*)b ; }   
ll findNumberOfTriangles(int arr[], int n)  
{   
    qsort(arr, n, sizeof( arr[0] ), comp);  

    ll count = 0;  
    for (int i = 0; i < n - 2; ++i)  
    {  
        int k = i + 2;  
  
        for (int j = i + 1; j < n; ++j)  
        {   
            while (k < n && arr[i] + arr[j] > arr[k])  
            ++k;  
            if(k > j)  
            count += k - j - 1;  
        }  
    }  
  
    return count;  
} 
void solve()
{
    int n;
    cin>>n;
    int arr[n];
    forn(i,n)cin>>arr[i];
    cout<<findNumberOfTriangles(arr,n)<<endl;
}
int main()
{
    FastIO;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
import math
a = raw_input()
for i, b in enumerate(a.split()):
	if i==0:
		W=int(b)
	elif i==1:
		H=int(b)
	elif i==2:
		x=int(b)
	elif i==3:
		y=int(b)
	else:
		r=int(b)
if r<=x<=W-r and r<=y<=H-r:
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std ;
#define rep(i,n) for(int i = 0; i < (int)(n);++i)
using ll = long long;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> n >> m;
  vector<ll> v(n);
  rep(i,n)
    cin >> v[i];
  rep(x,m){
    int k = x+1;
    rep(i,n-1){
      if(v[i] % k > v[i+1] % k)
        swap(v[i],v[i+1]);
    }
  }
  rep(i,n) cout << v[i] << endl;
  return 0;
}

Measured memory_bytes: 3232
#include <iostream>

using namespace std;

int main()
{
    int n,cn,sum;
    cin>>n;
    cn=n;
    sum=0;
    while(cn){
        sum=sum+cn%10;
        cn=cn/10;
    }
    if(n%sum==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
	int n;
	int a[3];
	scanf("%d",&n);

	for (int i=0;i<n;++i){
		for (int j=0;j<3;++j) scanf("%d",a+j);
		bool z=false;
		for (int k=0;k<3;++k)
			if (a[k]*a[k]+a[(k+1)%3]*a[(k+1)%3]==a[(k+2)%3]*a[(k+2)%3])
				z=true;
		if (z) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <stdio.h>
#define MAX 101
using namespace std;

int main(int argc, char *argv[])
{
    int n;
    scanf("%d", &n);
    int arr[MAX] = {0};
    for (int i = 0; i < n; i++)

    {
        scanf("%d", &arr[i]);
    }
    printf("%d", arr[n - 1]);
    for (int j = n - 2; j >= 0; j--)
    {
        printf(" %d", arr[j]);
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 3152
#include <algorithm> // std::sort(begin,end), std::min, std::max
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility> // std::swap
#include <vector>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
//  << std::setprecision(15)

template <typename T> // 0<1<2<3<4
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <typename T> // 0>1>2>3>4
using pq_dsc = priority_queue<T>;

const ll M = 1000000007;

vector<ll> fac(5000001);  // n!(mod M)
vector<ll> ifac(5000001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

ll comb(ll a, ll b) { // aCbをmod計算
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}

int main() {
  ll x, y;
  cin >> x >> y;
  ll diff = abs(x - y);
  ll same = max(x, y) - diff * 2;
  if ((same % 3) || same < 0 || diff < 0 ) {
    cout << 0 << endl;
    return 0;
  }
  same /= 3;

  //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < same * 2 + diff + 10; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
    ifac[i + 1] =
        ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
  }

  ll ans = 0;
  ans = comb(same * 2 + diff, same) % M;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <bitset>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()
#define vi vector<int>

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;
vi U, V, W;
void add(int u, int v, int w) {
    U.pb(u); V.pb(v); W.pb(w);
}

int main(void) {
    int x;
    cin >> x;
    
    int N = __builtin_clz(1) - __builtin_clz(x-1) + 1;
    if (x==2) N++;
    
    bitset<26> L(x-1), mask((1<<25)-1);
    if (x!=2) for (int i=1; i<N; i++) {
        add(N-i, N-i+1, 1<<(i-1));
        add(N-i, N-i+1, 0);
    }

    if (L[0]==1) add(1, N, L.to_ullong()-1);
    add(1, N, L.to_ullong());
    mask[0] = 0;

    if (x!=2) for (int i=1; i<N-1; i++) {
        mask[i] = 0;
        if (L[i]==1) {
            bitset<26> t = L&mask;
            add(1, N-i, t.to_ullong());
        }
    }

    printf("%d %d\n", N, sz(U));
    rep(i, 0, sz(U)) printf("%d %d %d\n", U[i], V[i], W[i]);
    

    
    return 0;
}





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


int main(){
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (i % 2 == 0 && s[i] == 'p') ans--;
        else if (i % 2 == 1 && s[i] == 'g') ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

#define MAX 3010
#define INF (1<<29)
typedef pair<int, int> pii;

struct Edge {
    int to, cost;
    Edge (int to, int cost) :
        to(to), cost(cost) {}
};

int N, M, K;
vector<Edge> G[MAX];
int d[MAX];

void dijkstra(int src)
{
    d[src] = 0;

    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push(pii(0, src));

    while (!pq.empty()) {
        pii p = pq.top(); pq.pop();
        int v = p.second;

        for (int i = 0; i < (int)G[v].size(); i++) {
            Edge &e = G[v][i];
            if (d[v] + e.cost < d[e.to]) {
                d[e.to] = d[v] + e.cost;
                pq.push(pii(d[e.to], e.to));
            }
        }
    }  
}

int main()
{
    cin >> N >> M >> K;
    for (int i = 0; i < M; i++) {
        int a, b, l;
        cin >> a >> b >> l;
        a--; b--;
        G[a].push_back(Edge(b, l));
        G[b].push_back(Edge(a, l));
    }

    fill(d, d + MAX, INF);
    
    int src;
    for (int i = 0; i < K; i++) {
        cin >> src; src--;
        dijkstra(src);
    }
    
    int res = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < (int)G[i].size(); j++) {
            int k = G[i][j].to, c = G[i][j].cost;
            int maxi = max(d[i], d[k]), mini = min(d[i], d[k]);
            res = max(res, mini + (int)ceil((maxi + c - mini) * 0.5));
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5968
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int n = 100005;
int m;
vector<vector<pll>> graph(n,vector<pll>());

vector<ll>  Dijkstra(int start){
    vector<bool> seen(n,false);
    vector<ll> shortest(n,LINF);
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    pq.push(pll(0,start));

    while(!pq.empty()){
        ll dist = pq.top().first;
        int node = pq.top().second;
        pq.pop();
        if(seen[node]) continue;

        shortest[node] = dist;
        seen[node] = true;

        for(pll next:graph[node]){
            int next_node = next.second;
            ll next_cost = next.first;
            if(seen[next_node]) continue;
            pq.push(pll(next_cost + dist,next_node));
        }
    }

    return shortest;
}

int main(){
    int r;
    cin >> n >> m >> r;
    rep(i,m){
        int s,t,d;
        cin >> s >> t >> d;
        graph[s].push_back(pll(d,t));
    }

    vector<ll> dis = Dijkstra(r);

    rep(i,n){
        if(dis[i]==LINF) cout << "INF" << endl;
        else cout << dis[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 21520
import java.io.*;
import java.util.*;

public class Main {
	
	public static int gcd(int m, int n) {
		if(n == 0) return m;
		return gcd(n, m % n);
	}
	
	public static long lcm(int m, int n) {
		return ((long)m * n) / gcd(m, n);
	}
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<String> ans = new ArrayList<String>();
		
		while (true) {
			
			String s = br.readLine();
			if(s == null) break;
			StringTokenizer st = new StringTokenizer(s," ");
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			ans.add(String.valueOf(gcd(a,b)) + " " + String.valueOf(lcm(a,b)));
			
		}
		for(String q : ans) {
			System.out.println(q);
		}
		
	}
	
}

Measured memory_bytes: 9296
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		execute20_2();
	}
	
	private static void execute20_2() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] a = new long[n];
			for(int i=0;i<n;i++) a[i] = sc.nextInt();
			
			long ans=0;
			long max=a[0];
			
			for(int j=1;j<n;j++) {
				if(max>a[j]) {
					ans+=max-a[j];
				} else {
					max=a[j];
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 51296
N = int(input())
a = list(map(int, input().split()))

C = [0 for _ in range(N)] #奇数個、余裕あり
D = [0 for _ in range(N)] #偶数個
E = [0 for _ in range(N)] #奇数個、余裕なし

E[0] = a[0]

for i in range(1,N):
  if i % 2 == 0:#奇数個
    C[i] = max(C[i-2]+a[i],D[i-1])
    E[i] = E[i-2] + a[i]
  else:
    D[i] = max(D[i-2]+a[i],E[i-1])

if N % 2 == 0:
  print(D[N-1])
else:
  print(C[N-1])
  
#print(C)
#print(D)
#print(E)
    



Measured memory_bytes: 133612
import java.util.LinkedList;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Iterator;

class Grph {
	
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	private int time;
	private ArrayList<Integer> visited = new ArrayList<Integer>();
	//adjacency list of edges
	public Grph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		
		
		in.close();
	}
	
	public void printAdjMatrix() {
		int[][] adjMatrix = new int[totalVertex][totalVertex];
		//complete the following
		for (int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> currElement = adjList.get(i);
			for (int j = 0; j < currElement.size(); j++) {
				adjMatrix[i][currElement.get(j)] = 1;
			}
		}
		
		for (int i = 0; i < totalVertex; i++) {
			for (int j = 0; j < totalVertex; j++) {
				System.out.print(adjMatrix[i][j]);
				if (j < totalVertex - 1) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		
	}
	
	public void DFS() {
		int[] d = new int[totalVertex];
		int[] f = new int[totalVertex];
		for (int i = 0; i < totalVertex; i++) {
			if (!visited(i)) {
				DFS(i, d, f);
			}
		}
		
		for (int i = 0; i < totalVertex; i++) {
			System.out.println((i + 1) + " " + d[i] + " " + f[i]);
		}
		
	}
	
	public void DFS(int v, int[] d, int[] f) {
		time++;
		d[v] = time;
		visited.add(v);
		LinkedList<Integer> neighbors = adjList.get(v);
		for (int i = 0; i < neighbors.size(); i++) {
			if (!visited(neighbors.get(i))) {
				DFS(neighbors.get(i), d, f);
			}
		}
		time++;
		f[v] = time;
	}
	
	public boolean visited(int v) {
		for (int i = 0; i < visited.size(); i++) {
			if (visited.get(i) == v) {
				return true;
			}
		}
		return false;
	}
	
	
	
}

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Grph g = new Grph();
		g.loadAdjList();
		g.DFS();
	}

}


Measured memory_bytes: 28440
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d)){
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct UnionFind{
vector<int> par,depth;
UnionFind(int n){
par.resize(n); depth.resize(n);
for(int i=0; i<n; i++){
par[i]=i;
depth[i]=0;
}
}
int find(int x){
if(par[x]==x){
return x;
}
else{
return par[x]=find(par[x]);
}
}
bool same(int x, int y){
return find(x)==find(y);
}
void unite(int x, int y){
x=find(x); y=find(y);
if(x==y) return;
if(depth[x]<depth[y]) swap(x,y);
if(depth[x]==depth[y]) depth[x]++;
par[y]=x;
}
};
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    UnionFind uf(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i=0; i<m; i++){
        int x,y; cin >> x >> y;
        x--; y--;
        uf.unite(x,y);
    }
    int ans=0;
    for(int i=0; i<n; i++){
        if(uf.same(i,p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios_base::sync_with_stdio(false);; cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define inStrAftInSome cin.ignore(numeric_limits<streamsize>::max(),'\n')		//input string(with whitespace) after input something(char, int, bool, str)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define mt 			make_tuple
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define MOD 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<n; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define roff(i, n, f)	for(int i = n-1; i>=f; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef vector< int > 		vi;
typedef vector< vi >		vvi;
typedef pair<int, int> 		pii;
typedef tuple<int,int,int>  tiii;

int main()
{
	IOS;
	int n;	cin >> n;
	vi H(n+1);
	H[n] = INT_MAX;
	rep(i, n)	cin >> H[i];
	vi dp(n, INT_MAX);
	dp[0] = 0;
	rep(i, n-1){
		dp[i+1] = min(dp[i+1], dp[i]+abs(H[i]-H[i+1]));
		dp[i+2] = min(dp[i+2], dp[i]+abs(H[i]-H[i+2]));
	}
	cout << dp[n-1] << endl;
    return 0;
}


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

int main()
{
	int N, X;
	scanf("%d%d", &N, &X);
	int count{1}, pre{};
	for (int i{}; i < N; i++)
	{
		int L;
		scanf("%d", &L);
		if (pre + L > X) break;
		count++;
		pre += L;
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int gcd(int x, int y){
  if(y==0) return x;
  return gcd(y,x%y);
}


int main()
{
  int N;
  int a[110000];
  int res=0;
  int L[110000];
  int R[110000];
  cin >> N;

  rep(i,N) cin >> a[i];

  L[0] = 0;
  R[0] = 0;
  FOR(i,1,N){
    L[i] = gcd(L[i-1], a[i-1]);
  }
  FOR(i,1,N){
    R[i] = gcd(R[i-1], a[N-i]);
  }

  //  FOR(i,0,N){                                                               
  //    printf("L[%d]=%d, R[%d]=%d\n", i, L[i], i, R[i]);                       
  //  }                                                                         

  FOR(i,1,N){
    res = max(res, gcd(L[i-1],R[N-i]));
  }
  cout << res << endl;
}


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

int a[3001];
int n;

int main()
{

    scanf("%d",&n);
    long long ans = 0;
    for(int i = 1;i <= n; i++ )
    {
        scanf("%d", &a[i]);
        ans += a[i] - 1;
    }
    printf("%lld",ans);
    return 0;
}


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


int32_t main(){
	int n ;
	cin>>n;
	vector<int> v(n);
	vector< pair<int,int> > p;
	int sj = 0;
	for(int i = 0 ; i < n; i ++) cin>>v[i] , v[i] -= i+1 , p.push_back(pair<int,int>(v[i] , i)) , sj += v[i];
	sort(p.begin() , p.end());
	int ans = (int) 1e18;
	int kj = 0;
	for(int i = 0 ; i < n;  i++){
		kj += p[i].first;
		ans = min(ans , ((p[i].first)*(i+1) - kj) + ((sj - kj)  - (p[i].first)*(n - i - 1)));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8048
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
	ll i,j,k,m,n;
	ll a,b,c;
	cin>>a>>b>>c>>k;
	ll ans=0;
	ans+=1*min(a,k);
	k-=min(a,k);
	k-=min(b,k);
	ans-=1*min(c,k);
	cout<<ans<<"\n";
}

int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <queue>
#include <unordered_map>
using namespace std;

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

const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int x_1,y_1,x_2,y_2;
int r,c;
int check(int x,int y)
{
    if(x==0) return 3;
    if(x==r) return 1;
    if(y==0) return 0;
    if(y==c) return 2;
    return -1;
}
struct node
{
    int pos,id;
};
bool cmp(const node &a,const node &b){return a.pos<b.pos;}
bool cmp2(const node &a,const node &b){return a.pos>b.pos;}
vector<node> v[4];
void solve(int x,int y,int id)
{
    int f=check(x,y);
    if(f==0) v[0].push_back({x,id});
    if(f==1) v[1].push_back({y,id});
    if(f==2) v[2].push_back({x,id});
    if(f==3) v[3].push_back({y,id});
}
int main() {
    //freopen(".in", "r", stdin);
    scanf("%d%d",&r,&c);
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d%d",&x_1,&y_1,&x_2,&y_2);
        if(check(x_1,y_1)!=-1&&check(x_2,y_2)!=-1)
        {
            solve(x_1,y_1,i);
            solve(x_2,y_2,i);
        }
    }
    sort(v[0].begin(),v[0].end(),cmp);
    sort(v[1].begin(),v[1].end(),cmp);
    sort(v[2].begin(),v[2].end(),cmp2);
    sort(v[3].begin(),v[3].end(),cmp2);
    stack<int> st;
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<v[i].size();j++)
        {
            int id=v[i][j].id;
            if(st.empty()) st.push(id);
            else
            {
                if(id==st.top()) st.pop();
                else st.push(id);
            }
        }
    }
    if(st.empty()) printf("YES\n");
    else printf("NO\n");
    return 0;
}



Measured memory_bytes: 2520
class UnionFind
  def initialize(n)
    @parent = Array.new(n)
    @rank = Array.new(n)
    @size = Array.new(0)
    (0...n).each do |i|
      @parent[i] = i
      @rank[i] = 0
      @size[i] = 1
    end
  end

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

  def unite(x, y)
    x_root = find(x)
    y_root = find(y)
    return if x_root == y_root

    if @rank[x_root] < @rank[y_root]
      @parent[x_root] = y_root
      @size[y_root] += @size[x_root]
    else
      @parent[y_root] = x_root
      @size[x_root] += @size[y_root]
      if @rank[x_root] == @rank[y_root]
        @rank[x_root] += 1
      end
    end
    nil
  end

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

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

N, M = gets.split.map(&:to_i)
edge_list = M.times.map { gets.split.map(&:to_i) }
answers = []
last_ans = N * (N - 1) / 2
answers.unshift(last_ans)
uf = UnionFind.new(N + 1)
(M - 1).downto(1).each do |i|
  a, b = edge_list[i]
  unless uf.same?(a, b)
    last_ans -= uf.size(a) * uf.size(b)
  end
  answers.unshift(last_ans)
  uf.unite(a, b)
end

puts answers.join("\n")


Measured memory_bytes: 15172
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    String S = scan.nextLine();

    int count = 0;
    char pre = 0;
    for (int i = 0; i < S.length(); i++) {
      if (i == 0) {
        pre = S.charAt(i);
        continue;
      }
      if (pre == '0') {
        if (S.charAt(i) != '1') {
          count++;
        }
        pre = '1';
      } else {
        if (S.charAt(i) != '0') {
          count++;
        }
        pre = '0';
      }
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 26184