akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    vector<vector<int>> dp(n,vector<int>(3));

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i = 1; i<n; i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
    }
    cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;
    return 0;
}

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

int m, n;

int main()
{
	cin >> m >> n;
	
	if (m * 10000 < n || m * 1000 > n || n % 1000 != 0)
	{
		cout << "-1 -1 -1" << '\n';
		return 0;
	}
	
	for (int i = 0; i <= m; i++)
	{
		for (int j = 0; i + j <= m; j++)
		{
			for (int k = 0; i + j + k <= m; k++)
			{
				if (i + j + k == m && i * 10000 + j * 5000 + k * 1000 == n)
				{
					cout << i << ' ' << j << ' ' << k << '\n';
					return 0;
				}
			}
		}
	}
	
	cout << "-1 -1 -1" << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <iomanip>
#include <valarray>
#include <vector>


int main(int argc, char *argv[])
{
    std::cout << std::fixed << std::setprecision(0);
    int h,w;
    while(1){
        std::cin >> h >> w;
        if(h+w == 0)break;

        std::string out = "";
        for(int i = 0; i < h; ++i){
            for(int j = 0; j < w; ++j){
                out += "#";
            }
            out += "\n";
        }
        std::cout << out << std::endl;
    }

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a[3][3];
  REP(i,3)REP(j,3)cin>>a[i][j];

  ll n;
  cin>>n;
  REP(k,n){
    ll b;
    cin>>b;
    REP(i,3){
      REP(j,3){
        if(a[i][j]==b)
          a[i][j]=0;
      }
    }
  }

  bool ans=false;
  REP(i,3){
    bool flag=true;
    REP(j,3){
      if(a[i][j]!=0)
        flag=false;
    }

    if(flag)
      ans=true;
  }

  REP(j,3){
    bool flag=true;
    REP(i,3){
      if(a[i][j]!=0)
        flag=false;
    }

    if(flag)
      ans=true;
  }

  bool flag=true;
  REP(i,3){
    if(a[i][i]!=0)
      flag=false;
  }
  if(flag)
    ans=true;

  flag=true;
  REP(i,3){
    if(a[i][2-i]!=0)
      flag=false;
  }
  if(flag)
    ans=true;


  if(ans)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;



}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n, x, minv, maxv = -1000000000;
    cin >> n >> x;
    minv = x;
    for (int j=1; j<n; j++){
        cin >> x;
        maxv = max(maxv, x-minv);
        minv = min(minv, x);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3112
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


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

	vector<ll> num(k, 0);
	for (int i = 1; i <= n; ++i) {
		num[i%k]++;
	}
	ll cnt = 0;
	for (int a = 0; a < k; ++a) {
		int b = (k - a) % k;
		int c = (k - a) % k;
		if ((b + c) % k != 0) continue;
		cnt += num[a] * num[b] * num[c];
	}
	cout << cnt << endl;
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> ans(n+1);
    for(int i = 0; i < n-1; i++){
        int a;
        cin >> a;
        ans[a]++;
    }
    for(int i = 1; i <= n; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[100010];
int main() {
	// your code goes here
	ll n,dim1=-1,dim2=-1;
	cin>>n;
	for(ll i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(ll i=n-1;i>=1;i--)
	{
		if(a[i]==a[i-1])
		{
			if(dim1==-1)
			{
				dim1=a[i];
				i--;
			}
			else if(dim2==-1)
			dim2=a[i];
			if(dim1!=-1&&dim2!=-1)
			break;
		}
	}
	if(dim1!=-1&&dim2!=-1)
	cout<<dim1*dim2<<endl;
	else
	cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 1024
import numpy as np

H, W = map(int, raw_input().split())
a = []
for i in range(H):
	_a = list(raw_input())
	a.append(_a)
a = np.array(a)
b = a.copy()
while True:
	r_exist = False
	c_exist = False
	for i in range(len(a)):
		if not '#' in a[i, :]:
			b = np.delete(a, i, 0)
			r_exist = True
	a = b.copy()
	for i in range(len(b[0])):
		if not '#' in b[:, i]:
			a = np.delete(b, i, 1)
			c_exist = True
	b = a.copy()
	if not (r_exist or c_exist):
		break
for i in b:
	print ('').join(i)


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

int main() {
  int i=0, temp, k, n;
  int al, ac, ar, a0, a1, af;
  int min, minTemp;
  int r, l; 
  
  cin >> k >> n;
  cin >> al >> ac >> ar;
  
  a0 = al;
  a1 = ac;
  
  do {
    l = k - (ar -ac);
    r = k - (ac - al);
    if (r<l) {
     minTemp = r; 
    } else {
     minTemp = l; 
    }
    if (minTemp < min) {
      min = minTemp;
    }
    al = ac;
    ac = ar;
  } while (cin >> ar);
  
  af = ar;
  
  l = af - a0;
  r = k - (af - ac);
  if (r<l) {
    minTemp = r;
  } else {
    minTemp = l;
  }
  if (minTemp < min) {
    min = minTemp;
  }
  
  
  l = k - (a1 - a0);
  r = af - a0; 
  if (r<l) {
    minTemp = r;
  } else {
    minTemp = l;
  }
  if (minTemp < min) {
    min = minTemp;
  }
  
  cout << min << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(char a,char b)
{
    return a>b;
}
int main()
{
    char s[110],t[110];
    while(scanf("%s%s",s,t)!=EOF)
    {
        sort(s,s+strlen(s));
        sort(t,t+strlen(t),cmp);
        //printf("%s\n%s",s,t);
        if(strcmp(s,t)>=0)
        {
            printf("No\n");
        }
        else
            printf("Yes\n");
    }


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//入力
		int n = sc.nextInt();

		int t = sc.nextInt();
		int a = sc.nextInt();
		double mindiff = Double.MAX_VALUE;
		int check =0;
		int[] h = new int[n];
		for(int i=0;i<n;i++) {
			h[i] = sc.nextInt();
			double T =t-h[i]*0.006;
			double diff = Math.abs(a-T);
			if(mindiff>diff) {
				mindiff=diff;
				check = i;
			}

		}
		System.out.println(check+1);
	}

}

Measured memory_bytes: 22500
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    bool flag = true;

    for (int i = 0; i < S.length(); i++) {
        if (S.at(i) != T.at(i)) {
            flag = false;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main(){
    long N,A,count_even=0,answer;
    unordered_map <long,int> mp;

    cin >> N;

    for(long i=0;i<N;i++){
        cin >> A;
        if(mp.find(A)!=mp.end()){
            mp[A]++;
        }
        else{
            mp[A] = 1;
        }
    }

    for(auto itr=mp.begin();itr!=mp.end();itr++){
        if(!(itr->second%2)) count_even++;
    }
    
    answer = mp.size() - (count_even%2);
    cout << answer << "\n";
    return 0;
}

Measured memory_bytes: 4388
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003



int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);
	
	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);
	
	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);
	
	return ret;

}

int number(State &begin){
	int ret =0;
	
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}



int main(void){
	
	ll n;
	
	cin>>n;
	
	vector<ll> a(n);
	
	for(int i=0;i<n;i++)
		cin>>a[i];
	
	sort(a.begin(),a.end());
	
	cout<<a[n-1]-a[0]<<endl;
	
	
	
		
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);

    d = a / b;
    r = a % b;
    f = 1.0000 * a / b;

    printf("%d %d %f\n", d, r, f);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector <int> A(N);
  
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  int c = 0;
  
  while (true){
    bool j =false;
    
    for (int i=0; i<N; i++){
      if (A[i]%2 == 1){
        j = true;
      }
    }
      if (j){
        break;
      }
      for (int i =0; i<N; i++){
          A[i] /= 2;
        }
       c++;
  }

    cout << c << endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> cost(n);
    for (int i = 0; i < n; i++){
        cin >> cost.at(i);
    }
    
    vector<int> ans(n);
    ans.at(0) = 0;
    ans.at(1) = abs(cost.at(1)-cost.at(0));
    for (int i = 2; i < n; i++){
        ans.at(i) = min(ans.at(i-2)+abs(cost.at(i)-cost.at(i-2)), ans.at(i-1)+abs(cost.at(i)-cost.at(i-1)));
    }
    printf("%d\n",ans.at(n-1));
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int t = sc.nextInt();

        if(x - t >= 0) {
            System.out.println(x-t);
        } else {
            System.out.println(0);
        }
        sc.close();
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 10000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    char c;
    cin>>c;
    if(c>='a' && c<='z')
    	cout<<"a";
    else
    	cout<<"A";
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<stdio.h>
using namespace std;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

int main(){
	string S;
	int K,N;
	cin>>N>>K>>S;
	S[K - 1]+=32;
	cout<<S;


}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,r;
cin >> n>> r;
cout << (n >= 10 ? r : r + 100 * (10 - n)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll MOD=1000000007;
ll ksm(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
/***********************/
const long mod =1e9+7;
void run(){
}
long power(long a,long b){
	return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;
}
long Con(int n,int k){
	long x =1,y =1;
	for(int i=1;i<=k;i++){
		 x = x*(n-i+1) %mod;
		 y = y*i %mod;
	}
	return  x * power(y ,mod-2)%mod;
}
int main(){
//	for(scanf("%d",&_); _;_--) run();	
	long n,a,b;
	cin>> n >> a>> b ;
	long ans = power(2,n);
	ans -= Con(n,a);
	ans -= Con(n,b);
	ans--;
	cout<<(ans%mod +mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  unsigned long long int a,b;
  while(cin>>a>>b)
  cout<<__gcd(a,b)<<" "<<(a*b)/__gcd(a,b)<<endl;
}

Measured memory_bytes: 1148
#include<stdio.h>
int main(){
    double a,b,c,d,e,f,x,y;
    while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
        if(a<0){
            a=-a;
            b=-b;
            c=-c;
        }
        if(d<0){
            d=-d;
            e=-e;
            f=-f;
        }
        y=((c*d)-(a*f))/((b*d)-(a*e));
        x=((b*f)-(c*e))/((b*d)-(a*e));
        printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

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

int main() {
    int H, W;
    
    while(true) {
        cin >> H >> W;

        if(H == 0 && W == 0) { break; }

        for(int j = 0; j < W; j++){
            cout << "#";
        }
        cout << "\n";

        for(int i = 1; i < H-1; i++) {
            cout << "#";
            for(int j = 1; j < W-1; j++) {
                cout << ".";
            }
            cout << "#";
            cout << "\n";
        }

        for(int j = 0; j < W; j++){
            cout << "#";
        }
        cout << "\n"; 

        cout << endl;
    }   
    
    return 0;
}


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

#define MOD 998244353

#define INV2 499122177

long dp[3010];

int main() {
  int N, S; cin >> N >> S;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < 3010; i++) dp[i] = 0;
  dp[0] = 1;
  for (int i = 0; i < N; i++) dp[0] = dp[0] * 2 % MOD;
  for (int i = 0; i < N; i++) {
    for (int j = S - A[i]; j >= 0; j--) {
      dp[j+A[i]] = (dp[j+A[i]] + dp[j]*INV2%MOD)%MOD;
    }
  }
  cout<<dp[S]<<endl;
}

Measured memory_bytes: 3652
/*
Miles Morales : When will I know I'm ready?
Peter B. Parker : You won't. It's a leap of faith. That's all it is, Miles. A leap of faith.
*/
//KEEP IT SIMPLE STUPID

#include <bits/stdc++.h>

// #pragma GCC optimize("O3")
// #pragma GCC target("avx")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ll long long
#define MP make_pair
#define ERR cout << "================================================\n"
#define fi first
#define se second
#define PB push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n)-1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define print(v)          \
	for (auto x : v)      \
	{                     \
		cout << x << " "; \
	}
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define SP << " " <<
#define W(t)  \
	ll t;     \
	cin >> t; \
	while (t--)
#define FIO                           \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);
#define FAST                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll INF = 1e18;
const ll NEG_INF = -1 * (1e18);
using namespace std;

void usaco(string prob)
{
	freopen((prob + ".in").c_str(), "r", stdin);
	freopen((prob + ".out").c_str(), "w", stdout);
}

/* Function to check primality in O(sqrt(n)) */
bool prime(int n)
{
	if (n < 2)
		return false;
	for (int x = 2; x * x <= n; x++)
	{
		if (n % x == 0)
			return false;
	}
	return true;
}

/* Function to get prime factorization of n */
vector<int> getFactors(int n)
{
	vector<int> f;
	for (int x = 2; x * x <= n; x++)
	{
		while (n % x == 0)
		{
			f.push_back(x);
			n /= x;
		}
	}
	if (n > 1)
		f.push_back(n);
	return f;
}

void solve()
{
	/* Write Solution Here */
	ll n, ans = 0;
	cin >> n;
	vll a(n);
	forn(i, n) cin >> a[i];

	for (ll i = 1; i < n; i++)
	{
		if (a[i] < a[i - 1])
		{
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}

	cout << ans << "\n";
}

int main()
{
	//FIO
	//FAST

	//usaco("cowlands");

	ll TC = 1;
	/*
	Uncomment when multiple test cases
	*/

	// cin>>TC;
	for1(tt, TC)
	{
		solve();
	}
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 4752
def main():
    mod = 2019
    l,r = map(int,input().split())
    ans = 10**9
    for i in range(l,min(l+2020,r+1)):
        for j in range(i+1,min(l+2020,r+1)):
            ans = min(ans,(i*j)%mod)
    print(ans)
main()

Measured memory_bytes: 9176
fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map(String::toInt)
    val map = Array(H) { i ->
        readLine()!!.toCharArray()
    }

    val mapL = mapL(map, H, W)
    val mapR = mapR(map, H, W)
    val mapD = mapD(map, H, W)
    val mapU = mapU(map, H, W)

    var max = 0
    for (h in 0 until H) {
        for (w in 0 until W) {
            if (map[h][w] == '#') {
                continue
            }
            val sum = mapL[h][w] + mapR[h][w] + mapU[h][w] + mapD[h][w] - 3
            max = Math.max(max, sum)
        }
    }
    println(max)
}

private fun mapL(map: Array<CharArray>, height: Int, width: Int): Array<IntArray> {
    val result = Array(height) { i -> IntArray(width) }
    for (h in 0 until height) {
        for (w in 0 until width) {
            if (map[h][w] == '#') {
                continue
            }
            if (w == 0) {
                result[h][w] = 1
            } else {
                result[h][w] = result[h][w - 1] + 1
            }
        }
    }
    return result
}

private fun mapR(map: Array<CharArray>, height: Int, width: Int): Array<IntArray> {
    val result = Array(height) { i -> IntArray(width) }
    for (h in (height - 1) downTo 0) {
        for (w in (width - 1) downTo 0) {
            if (map[h][w] == '#') {
                continue
            }
            if (w == width - 1) {
                result[h][w] = 1
            } else {
                result[h][w] = result[h][w + 1] + 1
            }
        }
    }
    return result
}

private fun mapD(map: Array<CharArray>, height: Int, width: Int): Array<IntArray> {
    val result = Array(height) { i -> IntArray(width) }
    for (h in 0 until height) {
        for (w in 0 until width) {
            if (map[h][w] == '#') {
                continue
            }
            if (h == 0) {
                result[h][w] = 1
            } else {
                result[h][w] = result[h - 1][w] + 1
            }
        }
    }
    return result
}

private fun mapU(map: Array<CharArray>, height: Int, width: Int): Array<IntArray> {
    val result = Array(height) { i -> IntArray(width) }
    for (h in (height - 1) downTo 0) {
        for (w in (width - 1) downTo 0) {
            if (map[h][w] == '#') {
                continue
            }
            if (h == height - 1) {
                result[h][w] = 1
            } else {
                result[h][w] = result[h + 1][w] + 1
            }
        }
    }
    return result
}


Measured memory_bytes: 142944
def binary_search target_array, value
  right = target_array.size
  left = 0
  while right > left
    mid = (right + left) / 2
    return 1 if target_array[mid] == value
    if value < target_array[mid]
      right = mid
    else
      left = mid + 1
    end
  end
  0
end

gets.to_i
s = gets.chomp.split(' ').map(&:to_i)
gets.to_i
t = gets.chomp.split(' ').map(&:to_i)
count = 0
t.each do |value|
  count += binary_search s, value
end
puts count


Measured memory_bytes: 15636
#include<bits/stdc++.h>
#define mem(a,v) memset(a,v,sizeof a)
#define ll long long
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define f first
#define s second
#define fr(i,n) for(int j=i;j<n;j++)
#define rev(a) reverse(a.begin(),a.end())
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lb(a,v) lower_bound(all(a),v)
#define ub(a,v) upper_bound(all(a),v)
#define ins(v) insert(v)
#define pb(v) push_back(v)
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define sf1(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sf4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
using namespace std;
int main() {
	int n;
	scanf("%d",&n);
	int x,temp=-1,mx=0,c=0;
	for(int i=0;i<n;i++)
	{
		sf1(x);
		if(x>temp)
			mx=max(mx,c),c=0;
		else
			c++;
		temp=x;
	}
	mx=max(mx,c);
	printf("%d\n",mx);
	return 0;
}

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

class Fib {
public:
    Fib(int n) : _data(n+1) {
        _data[0] = 1;
        _data[1] = 1;
    }

    int operator()(int n) {
        if (n <= _size) {
            return _data[n];
        }
        _data[n] = (*this)(n-1) + (*this)(n-2);
        _size = n;
        return _data[n];
    }

private:
    int _size = 1;
    vector<int> _data;
};


int main() {
    int n;
    cin >> n;
    Fib f(n);
    cout << f(n) << endl;
}


Measured memory_bytes: 3136
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, Y):
    ans = 0


    c = Counter()
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            a = j - i
            b = abs(i-X) + 1 + abs(j-Y)
            c[min(a, b)] += 1


    for k in range(1, N):
        print(c[k])


    return ans


def main():
    N, X, Y = read_int_n()
    (slv(N, X, Y))

    # N = 2 * (10**3)
    # X = 1000
    # Y = 1500
    # (slv(N, X, Y))



if __name__ == '__main__':
    main()


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

int main() {
  string S;
  cin >> S;
  vector<vector<int>> info(S.size(), vector<int>(2));
  for (int i = 0; i < S.size(); i++){
    if (S[i] == 'R'){
      if (i > 0 && S[i - 1] == 'R'){
        info[i] = {info[i - 1][0], info[i - 1][1] - 1};
      }
      else {
        for (int j = i + 1; j < S.size(); j++){
          if (S[j] == 'L'){
            //Lについた時の回数を保存
            info[i] = {j, j - i};
            break;
          }
        }
      }
    }
    else {
      if (S[i - 1] == 'L'){
        info[i] = {info[i - 1][0], info[i - 1][1] + 1};
      }
      else {
        info[i] = {i - 1, 1};
      }
    }
  }
  vector<int> places(S.size());
  int place = 0;
  for (int i = 0; i < S.size(); i++){
    if (S[i] == 'R'){
      place = info[i][0] - (info[i][1] % 2);
    }
    else {
      place = info[i][0] + (info[i][1] % 2);
    }
    places[place] += 1;
  }
  cout << places[0];
  for (int i = 1; i < S.size(); i++){
    cout << " " << places[i];
  }
  cout << endl;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  vl v,c;
  REP(i,n){
    ll ip;
    cin >> ip;
    v.push_back(ip);
  }
  REP(i,n){
    ll ip;
    cin >> ip;
    c.push_back(ip);
  }
  ll ans = 0;
  REP(i,n){
    if(v[i]>c[i]) ans += v[i] - c[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void){
	int min=1<<30,i=0,j=0,k=0,n=0,buff=0;
	int p[5000]={0},keisan[5000]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	//input finished.
	for(i=0;i<=3;i++){
		for(j=0;j<n;j++){
			keisan[j]=p[j];
		}
		buff=i;
		keisan[0]-=i;
		for(k=0;k<n-1;k++){
			if(keisan[k]>0){
				buff+=keisan[k]*2;
				keisan[k+1]-=keisan[k];
				keisan[k]=0;
			}
		}
		if(keisan[n-1]>0){
			buff+=keisan[n-1];
		}
		if(buff<min){
			min=buff;
		}
	}
	cout<<min<<endl;
	//min=0;
	return 0;
}


Measured memory_bytes: 3144
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    K=int(input())
    X=int(input())
    Y=int(input())
    print(X*min(N,K)+Y*max(N-K,0))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#include<cstring>
//#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
const double eps=1e-6;
//vector<int>v1[55],v2[55];
//int a[maxn],b[maxn],c[maxn];
struct node
{
    int val,t;
}a[maxn*3];
int cmp(node x,node y)
{
    if(x.val==y.val) return x.t<y.t;
    return x.val<y.val;
}
int dp[maxn*3][4],c[4];
int main()
{
     int n,x,tot=0;
       cin>>n;

     rep(i,0,n*3+10)
       rep(j,1,4) dp[i][j]=0;
     rep(i,1,4) c[i]=0;

     rep(i,0,n)
      {scanf("%d",&x);a[tot].val=x;a[tot++].t=1;}
     rep(i,0,n)
      {scanf("%d",&x);a[tot].val=x;a[tot++].t=2;}
     rep(i,0,n)
      {scanf("%d",&x);a[tot].val=x;a[tot++].t=3;}
       ll res=0;

      sort(a,a+tot,cmp);
   /* rep(i,0,12)
      scanf("%d%d",&a[i].val,&a[i].t);*/

      rep(i,0,tot)
        if(a[i].t==1)
        {
            c[1]++;
            rep(j,1,4)
              dp[i][j]=c[j];
        }
        else if(a[i].t==2)
        {
            c[2]++;
            rep(j,1,4)
              dp[i][j]=c[j];
        }
        else if(a[i].t==3)
        {
            c[3]++;
            rep(j,1,4)
              dp[i][j]=c[j];
        }


        rep(i,0,tot)
        {
            int j=i,c1=0,c3=0;
             while(a[i].val==a[j].val)
             {  if(a[j].t==1) c1++;
                 else if(a[j].t==2)
                 {
                     dp[j][1]-=c1; //cout<<dp[j][1]<<" "<<c1<<endl;
                 }

                 j++;
             }
             j--;

           for(int k=j;k>=i;k--)
           {
               if(a[k].t==3)
                 c3++;
               else if(a[k].t==2)
               {
                   dp[k][3]+=c3;
               }
            // cout<<c3<<endl;
           }
           i=j;
        }
      /*rep(i,0,tot)
       cout<<a[i].val<<" "<< a[i].t<<endl;
      rep(i,0,tot)
       cout<<dp[i][1]<<" "<<dp[i][2]<<" "<<dp[i][3]<<endl;*/

      rep(i,0,tot-1)
        {
          if(a[i].t==2)
            {
                res+=1ll*dp[i][1]*(n-dp[i][3]);
            }


        }


        cout<<res<<endl;



}


Measured memory_bytes: 10756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll compute(ll n){
    ll a = n%4;
    if(a==0)
        return n;
    else if(a == 1)
        return 1;
    else if(a == 2)
        return n+1;
    else
        return 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll A,B;
    cin>>A>>B;
    ll nA = A/4 , nB = B/4;
    ll mA = A%4;
    ll ans=0;
    if(A==B){
        cout<<A<<'\n';
        return 0;
    }
    if(nA==nB){
        for(ll i = A ; i <= B ; i++){
            ans ^=i;
        }
    }else{
           ans = compute(B);
            for(ll i = mA ; i<=3 ;i++){
                ans ^=A++;
            }
           
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 998244353 
#define pb push_back
#define mb make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int maxw = 1e9+7;
const int maxv = 1e5+7;
int main(){
	IOS;
	int n,w; cin >> n >> w;
	int W[n],val[n];
	for(int i=0;i<n;i++)
		cin >> W[i] >> val[i];
	int dp[2][maxv];
	// memset(dp,maxw,sizeof(dp));
	// cout << dp[1][500] << endl;
	for(int i=0;i<2;i++)
		for(int j=0;j<maxv;j++)
			dp[i][j] = maxw;
	// cout << maxw << endl;
	dp[0][0] = 0 ;
	dp[1][0] = 0; 
	for(int i = 1;i<=n;i++){
		for(int j = 0 ; j < maxv ; j++){
			if(j<val[i-1])
				dp[i%2][j] = dp[(i-1)%2][j];
			else
				dp[i%2][j] = min(dp[(i-1)%2][j],dp[(i-1)%2][j-val[i-1]] + W[i-1]);
		}
	}
	for(int j = maxv-1;j>=0;j--){
		if(dp[n%2][j] <= w){
			cout << j << endl;
			break;
		}
	}

	return 0;
}




Measured memory_bytes: 1024
INF = 10 ** 15
MOD = 10 ** 9 + 7
money = (10,50,100,500)

def solve(N):
    coins = list(map(int,input().split()))
    tot = sum(coins[i]*money[i] for i in range(4))
    ans = [0] * 4
    tot -= N
    for i in range(3,-1,-1):
        X = tot//money[i]
        tot %= money[i]
        ans[i] = max(coins[i] - X,0)
    for i in range(4):
        if ans[i] == 0:
            continue
        print(money[i],ans[i])
    
def main():
    i = 0
    while True:
        N = int(input())
        if N == 0:
            break
        if i > 0:
            print('')
        i += 1
        solve(N)
if __name__ == '__main__':
    main()



Measured memory_bytes: 5620
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>

typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_

#define BIG 10000000000 //10

#define LAST 10000000 //10^7

#define MOD (LONG)(10e8 + 7)




int main(void) {
	ULONG N;
	cin >> N;
	vector<ULONG> A(N);
	for (ULONG n = 0; n < N; n++) {
		cin >> A[n];
	}

	ULONG curMoney = 1000;
	ULONG curStock = 0;

	for (int i = 0; i < N-1; i++) {
		ULONG curVal = A[i];
		
		int downID = -1;
		int upID = -1;
		for (int j = i + 1; j < N; j++) {
			if (A[j] < curVal) {
				downID = j;
				break;
			}
		}
		for (int j = i + 1; j < N; j++) {
			if (A[j] > curVal) {
				upID = j;
				break;
			}
		}

			if ((upID > downID && downID != -1)  || (upID == -1 && downID!= -1)) {
				//sell
				curMoney += curVal * curStock;
				curStock = 0;

			}
			else if ((upID < downID && upID != -1) || (upID != -1 && downID == -1)) {
				//buy
				ULONG buynum = curMoney / curVal;
				curStock += buynum;
				curMoney -= curVal * buynum;
	
			}
	}


	//sell
	curMoney += A[N-1] * curStock;
	curStock = 0;

	cout << curMoney << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<ll> vint;
int main() {
  ll N;
  cin >> N;
  vint v(N);
  for (ll i=0;i<N;i++) cin >> v[i];
  
  ll ans=0,max=0;
  for (ll i=0;i<N;i++) {
    if (v[i]>=max) {
      ans++;
      max=v[i];
    }
  }
  
  
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> input(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> input[i];
		}
		vector<int> output(n);
		int ans = 0;
		bool flag = true;
		while(flag)
		{
			flag = false;
			map<int, int> data;
			for(int i = 0; i < n; ++i)
			{
				++data[input[i]]; 
			}
			for(int i = 0; i < n; ++i)
			{
				output[i] = data[input[i]];
			}
			for(int i = 0; i < n; ++i)
			{
				if(input[i] != output[i])
				{
					flag = true;
					break;
				}
			}
			for(int i = 0; i < n; ++i)
			{
				input[i] = output[i];
			}
			++ans;
		}
		cout << ans - 1 << endl;
		for(int i = 0; i < n - 1; ++i)
		{
			cout << output[i] << " ";
		}
		cout << output[n - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
// const ll MOD = 998244353;
const double PI=3.14159265358979323846;

// 出典:https://pyteyon.hatenablog.com/entry/2019/03/11/200000
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    // void init(ll sz_) {
    //     par.resize(sz_);
    //     siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
    //     for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    // }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};



int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int ans = n-1;
    rp(i, 0, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(!uf.issame(a, b)) {
            uf.merge(a, b);
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 4740
n, m = map(int, input().split())
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x, y):
    p = find(x)
    q = find(y)
    if p == q:
        return None
    if p > q:
        p,q = q,p
    par[p] += par[q]
    par[q] = p
def same(x, y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
par = [-1 for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
ans = 0
for i in range(n):
    ans = max(ans, size(i))
print(ans)

Measured memory_bytes: 80564
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a <= b ? a : a - 1) << endl;
    
    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for (ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        if (a <= A) {
            ++cnt1;
        }
        else if (a > A && a <= B) {
            ++cnt2;
        }
        else {
            ++cnt3;
        }
    }
    prints()(min({cnt1, cnt2, cnt3}));
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

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

int main() {
  int N, M,c=0;
  cin >> N >> M;
  for(int x=1;x<=N;x++){
   for(int y=22;y<=M;y++){
     if(y%10<2){
       continue;
       }
     if(x==(y/10)*(y%10)){
       c++;
       }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

class Program
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToArray();
        var n = l[0]; var m = l[1]; var x = l[2];
        var al = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x))
            .OrderBy(x => x).ToArray();
        var cost = new int[2];
        for (var i = 0; m > i; i++)
        {
            if (al[i] < x) cost[0]++;
            if (al[i] > x) cost[1]++;
        }
        Console.WriteLine(cost.Min());
    }
}

Measured memory_bytes: 28400
#include<stdio.h>
#include<string.h>
int main(){
	char ang[1010];
	int sum;
	while(scanf("%s",ang) != EOF){
		if(strcmp(ang, "0")==0) break;
		for(int i=0; i<strlen(ang); i++){
			sum = sum + ang[i]-'0';
		}
		printf("%d\n",sum);
		sum=0;
	}
}


Measured memory_bytes: 2676
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

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

	int t=0;
	int out=0;
	int n;
	cin>>n;
	rep(i,n){
		int a;cin>>a;
		if(t<a)out+=a-t;
		t=a;
	}
	cout<<out<<endl;
}






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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main() {
    ll n, m;
    cin >> n >> m;
    if(n==1&&m==1) cout << 1 << endl;
    else if(n==1) cout << m-2 << endl;
    else if(m==1) cout << n-2 << endl;
    else cout << (n-2)*(m-2) << endl;
}


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


int main() {
    
    int N , A  ;
    
    cin >>N >> A ;
    
    N = N * N;
    
    N = N - A;
    
        cout << N << endl;
    
    }

Measured memory_bytes: 256
count = [0 for i in range(26)]
while True:
    try:
        str = input().lower()
    except EOFError:
        break
    for i in range(len(str)):
        for j in range(26):
            if ord(str[i])==97+j:
                count[j]+=1
                break
for i in range(26):
    print(f"{chr(97+i)} : {count[i]}")


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

//INSERT ABOVE HERE
signed main(){
  Int n,y;
  cin>>n>>y;
  auto NG=[](){cout<<"-1 -1 -1"<<endl;exit(0);};

  for(Int i=0;i<=n;i++){
    for(Int j=0;i+j<=n;j++){
      Int k=n-(i+j);
      Int sum=10000*i+5000*j+1000*k;
      if(sum==y){
        cout<<i<<" "<<j<<" "<<k<<endl;
        return 0;
      }
    }
  }
  NG();
  return 0;
}


Measured memory_bytes: 256