akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int count = 0;
    string a,b,str,rts;
    
    cin >> a >> b;
    int A = atoi(a.c_str());
    int B = atoi(b.c_str());
    
    for(int i=A;i<=B;i++){
        str = rts = to_string(i);
        reverse(rts.begin(), rts.end());
        if(str == rts){
            count++;
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
// Abu Hurayra (HurayraIIT)
// IIT, Jahangirnagar University

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;

typedef long long LL;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int> vi; 

#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(0);  cin.tie(0);
#define sz(a) int((a).size())
#define space " "
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define pi acos(-1.0)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define MOD 1000000007
#define PRECISION(x) cout << fixed << setprecision(x); 
 
 
int main()
{
    fast_io
    
    LL n , m , k , i;
    cin >> n >> m >> k ;
    LL a[n] , b[m] , pre_a[n] , pre_b[m];
    for(i=0;i<n;i++)
    {
        cin >> a[i] ;
        if(!i) pre_a[i] = a[i];
        else pre_a[i] = a[i] + pre_a[i-1];
    }
    for(i=0;i<m;i++)
    {
        cin >> b[i] ;
        if(!i) pre_b[i] = b[i];
        else pre_b[i] = b[i] + pre_b[i-1];
    }
    if(k<pre_b[0] && k<pre_a[0])
    {
        cout << 0 << endl;return 0;
    }
    LL mx = -1 , cnt = 0 , rem = k ;
    LL up = upper_bound(pre_a,pre_a+n,k+1)-pre_a;
    mx = max(mx,up);
    for(i=0;i<m;i++)
    {
        if(pre_b[i]>k) break;
        cnt = i+1 ;
        rem = k - pre_b[i] ;
        if(!rem) {mx=max(mx,cnt);break;}
        int upper = upper_bound(pre_a,pre_a+n,rem+1)-pre_a;
        cnt += upper;
        mx = max(mx,cnt);
    }
    mx = max(mx,cnt);
    cout << mx << endl;
    
    return 0;
}


 

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

int main(void){
  int n;cin >> n;
  int h[n];rep(i,n)cin >> h[i];
  int dp[1000000];
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(int i=2;i<n;i++){
    dp[i] =  min(dp[i-1] + abs(h[i]-h[i-1]),dp[i-2] + abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<cstdio>
#include<cmath>
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
	int n;
	cin>>n;
	bool h=false;
	rep(w,n){
	if(h)cout<<endl;
		int in[9][9]={0};
		rep(j,9)rep(k,9)cin>>in[j][k];
		int out[9][9]={0};
		rep(i,9){
			rep(j,9){
				int co=0;
				rep(k,9)if(in[i][k]==j+1)co++;
				if(co>1)rep(k,9)if(in[i][k]==j+1)out[i][k]=1;
			}
		}
		rep(i,9){
			rep(j,9){
				int co=0;
				rep(k,9)if(in[k][i]==j+1)co++;
				if(co>1)rep(k,9)if(in[k][i]==j+1)out[k][i]=1;
			}
		}
		rep(i,3)rep(j,3){
			map<int,int>m;
			rep(a,3)rep(b,3)m[in[3*i+a][3*j+b]]++;
			rep(k,9)if(m[k+1]>=2)rep(a,3)rep(b,3)if(in[3*i+a][3*j+b]==k+1)out[3*i+a][3*j+b]=1;
		}
		rep(i,9){
			rep(j,9)
				if(out[i][j]==0)cout<<" "<<in[i][j];
				else cout<<"*"<<in[i][j];
			cout<<endl;
		}
		h=true;
	}
}

Measured memory_bytes: 1196
/**********************************************************
* @Author: 			   Kirito
* @Date:   			   2020-04-12 20:13:44
* @Last Modified by:   Kirito
* @Last Modified time: 2020-04-12 20:16:40
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn=111111;

int gd(int x, int y)
{
	return y == 0? x : gd(y, x % y);
}

int gcd(int a, int b, int c)
{
	return gd(gd(a, b), c);
}

int main()
{
	int k;
	while(cin >> k)
	{
		ll ans = 0;
		for(int i = 1; i <= k; i++)
			for(int j = 1; j <= k; j++)
				for(int m = 1; m <= k; m++)
					ans += gcd(i, j, m);
		cout << ans << endl;
	}
	return 0;
}

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

int score[5];

signed main()
{
	rep(i,5) cin >> score[i];
	rep(i,5) if (score[i] < 40) score[i] = 40;
	int sum = 0;
	rep(i,5) sum += score[i];
	cout << sum / 5 << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-13;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	int ret=0;
	int cont=0;
	for(int i=0;i<a;i++){
		if(i==0||p[i]==p[i-1])cont++;
		else{
			ret+=(cont/2);
			cont=1;
		}
	}
	ret+=cont/2;
	printf("%d\n",ret);
}

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

int main()
{
	int n,x[100005];
	memset(x,0,sizeof(x));
	cin >> n;
	int a[n],max = 0;
	
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if(a[i] > max) max = a[i];
		x[a[i]]++;
		x[a[i] + 1]++;
		x[a[i] + 2]++;
	}
	
	int max2 = 0;
	for(int i = 0;i <= max + 2;i++){
		if(x[i] > max2) max2 = x[i];
	}
	cout << max2;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    vector<int> cnt(13);
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    if (cnt[0] > 0) { cout << 0 << '\n'; return 0; }
    vector<int> base, search;
    for(int i = 1; i <= 12; i++) {
        if (cnt[i] >= 3) { cout << 0 << '\n'; return 0; }
        else if (cnt[i] == 1) search.push_back(i);
        else if (cnt[i] == 2) base.push_back(i), base.push_back(24 - i);
    }

    int size = search.size();
    int upper = 1 << size;
    int ans = 0;
    for (int b = 0; b < upper; b++) {
        vector<int> tmp(base.begin(), base.end());
        tmp.push_back(0);
        tmp.push_back(24);
        for (int i = 0; i < size; i++) {
            if ((b >> i) % 2) tmp.push_back(search[i]);
            else tmp.push_back(24 - search[i]);
        }
        int minD = 24;
        for (int i = 0; i < tmp.size()-1; i++) for (int j = i+1; j < tmp.size(); j++)
            minD = min(minD, abs(tmp[i] - tmp[j]));
        ans = max(ans, minD);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

vector<int> Z_algorithm(const string& s){ // Z_algorithm
    int n = (int)s.size();
    vector<int> res(n);
    res[0] = n;
    int i = 1, j = 0;
    while(i < n){
        while(i + j < n && s[i + j] == s[j])j++;
        res[i] = j;
        if(j == 0){ i++; continue; }
        int k = 1;
        while(i + k < n and k + res[k] < j)res[i + k] = res[k], k++;
        i += k, j -= k;
    }
    return res;
}

int main(){

    int N;
    cin >> N;

    string S;
    cin >> S;

    int ans = 0;
    rep(i, N){
        vector<int> vec = Z_algorithm(S.substr(i));
        rep(j, (int)vec.size()){
            int lcp = min(vec[j], j);
            chmax(ans, lcp);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string s;
int q[100005];
int w;
int f[100005][2];
int i;
int ans[100005];
int main() {
	cin>>s;
	int l=s.length();
	for(i=0;i<l;i++) 
		if(s[i]=='L') q[i+1]=0;
		else q[i+1]=1;
	int k=1;
	for(i=2;i<=l;i++) 
		if(q[i]==q[i-1]) k++;
		else w=max(w,k),k=1;
	if(w%2) w++;
	for(i=1;i<=l;i++) if(!q[i]) break;
	for(;i<=l;i++) if(!q[i]) f[i][0]=f[i-1][0]+1;
	for(i=l;i>0;i--) if(q[i]) break;
	for(;i>0;i--) if(q[i]) f[i][1]=f[i+1][1]+1;
	for(i=1;i<=l;i++) {
		if(!((w-f[i][q[i]])%2)&&!q[i]) ans[i-f[i][q[i]]]++;
		if(((w-f[i][q[i]])%2)&&!q[i]) ans[i-f[i][q[i]]+1]++;
		if(!((w-f[i][q[i]])%2)&&q[i]) ans[i+f[i][q[i]]]++;
		if(((w-f[i][q[i]])%2)&&q[i]) ans[i+f[i][q[i]]-1]++;
	}	
	for(i=1;i<=l;i++) cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

long long a[200010];
int main(){
	int i,n;
	long long sum=0,ans,b;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		a[i] -= i+1;
		sum += a[i];
	}
	
	sort(a,a+n);
	b = a[n/2];
	for(i=0;i<n;i++){
		ans += abs(a[i]-b);
	}
	
	cout << ans << endl;
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, k, n) for (int i = k; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

vector<vector<int> > G;
vector<bool> visited;

deque<int> path;
void dfs(int v, int mode) {
    if (mode == 1) {
        visited[v] = true;
        for (auto e : G[v]) {
            if (! visited[e]) {
                path.push_front(e);
                dfs(e, 1);
                break;
            }
        }
    } else {
        visited[v] = true;
        for (auto e : G[v]) {
            if (! visited[e]) {
                path.push_back(e);
                dfs(e, 2);
                break;
            }
        }
    }
}

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    visited.resize(n, false);
    path.push_front(0);
    visited[0] = true;
    path.push_back(G[0].back());
    visited[G[0].back()] = true;

    dfs(0, 1);
    dfs(G[0].back(), 2);

    cout << path.size() << endl;
    stl_rep(itr, path) {
        cout << *itr + 1 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s;
    cin >> s;
    int cnta = 0, cntb = 0, cntc = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'a')
        {
            cnta = 1;
        }
        if (s[i] == 'b')
        {
            cntb = 1;
        }
        if (s[i] == 'c')
        {
            cntc = 1;
        }
    }
    if (cnta == 1 && cntb == 1 && cntc == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int n, m;
vector<vi> v(3), vt(3), vn(3);
int bfs() {
	int a, b, c;
	v[0].eb(0), v[1].eb(0), v[2].eb(0);
	rep(i, 0, 3) {
		cin >> a;
		rep(j, 0, a) {
			cin >> b;
			v[i].eb(b);
		}
	}
	int cnt = 0;
	deque<tuple<int, vector<vi>, int>> dq;
	dq.eb(mt(cnt, v, 0));
	while(!dq.empty()) {
		tie(cnt, vt, c) = dq.front(); dq.pop_front();
		if (cnt > m)
			break;
		if (vt[1].back() == 0 && (vt[0].back() == 0 || vt[2].back() == 0)) {
			return cnt;
		}
		++cnt;
		if (vt[0].back() < vt[1].back() && c != 3) {
			vn = vt;
			vn[0].eb(vt[1].back()); vn[1].pop_back();
			dq.eb(mt(cnt, vn, 3));
		}
		if (vt[0].back() > vt[1].back() && c != 3) {
			vn = vt;
			vn[1].eb(vt[0].back()); vn[0].pop_back();
			dq.eb(mt(cnt, vn, 3));
		}
		if (vt[1].back() > vt[2].back() && c != 6) {
			vn = vt;
			vn[2].eb(vt[1].back()); vn[1].pop_back();
			dq.eb(mt(cnt, vn, 6));
		}
		if (vt[1].back() < vt[2].back() && c != 6) {
			vn = vt;
			vn[1].eb(vt[2].back()); vn[2].pop_back();
			dq.eb(mt(cnt, vn, 6));
		}
	}
	return -1;
}
void solve() {
	rep(i, 0, 5) {
		cin >> n >> m;
		if (n == 0 && m == 0) {
			break;
		}
		print(bfs());
	}
}
int main() {
	solve();
	return 0;
}



Measured memory_bytes: 3156
#include <stdio.h>
int main (){
  int N,M,A[1000],B[1000],i,cost=0,min;
  scanf("%d %d",&N,&M);
  scanf("%d %d",&A[0],&B[0]);
  min= A[0];
  for (i=1 ; i<M ;i++){
    scanf("%d %d",&A[i],&B[i]);
    if (min>A[i]){
      min=A[i];
    }
  }
  for(i=0 ; i<M ; i++){
    scanf("%d %d",&A[i],&B[i]);
    if( A[i]<N ){
      cost=cost+B[i]-N;
    }
  }
  cost=cost-N+min;
  printf("%d\n",cost);
  return 0;
}
 

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

int main(){
  int n,m,x; cin >> n >> m >> x;
  int le=0; int bi=0;
  rep(i,m){
    int a; cin >> a;
    if(a>x) bi++;
    else le++;
  }
  cout << min(le,bi);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int a;
  int b;
  int c;
  std::cin >> a >> b >> c;

  bool flag = false;
  if(a < b) {
    if(b < c) {
      flag = true;
    }
  }
  if(flag) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    vec a(N); cin >> a;
    int s = 0;
    REP(i, N) s ^= a[i];
    REP(i, N) a[i] ^= s;
    REP(i, N) cout << a[i] << " ";
    cout << endl;

    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  vector<int> dp(n, INF);
  dp[0] = 0;
  REP(i, n-2) {
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
    dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
  }
  dp[n-1] = min(dp[n-1], dp[n-2] + abs(h[n-1] - h[n-2]));

  cout << dp[n-1] << endl;
}


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

int main() {
  int N,ans=1;
  cin >> N;
  vector<int> D(N,0);
  for (int i=0;i<N;i++){
    cin >> D.at(i);
  }
  sort(D.begin(),D.end());
  for (int i=0;i<N-1;i++){
    if (D.at(i)<D.at(i+1)){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int N, X;
    cin >> N >> X;

    int m[110];
    int sum = 0;

    int MIN = INT32_MAX;
    for (int i = 0; i < N; i++)
    {
        cin >> m[i];
        sum += m[i];
        if (MIN > m[i])
            MIN = m[i];
    }

    int rest = X - sum;

    cout << N + rest / MIN;

    return 0;
}

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

int main(void){
    
    int N,M;
    cin >> N >> M;
    
    string ans;
    if(N>=2){
        ans ="1";
        for(int i = 0; i < N-1 ; i++)ans += "0";
        
        int s;
        char c;
        map<int,char> mp;
        for(int i = 0; i < M;i++){
            cin >> s >> c;s--;
            if(s == 0&&c =='0'){ans = "-1";break;}
            else if(mp[s]==0||mp[s]==c){ans[s] = c;mp[s]=c;}
            else {ans ="-1";break;}
        }
    }else{
        ans = "0";
        int s;
        char c;
        map<int,char> mp;
        for(int i = 0; i < M;i++){
            cin >> s >> c;s--;
            if(mp[s]==0||mp[s]==c){ans[s] = c;mp[s]=c;}
            else {ans ="-1";break;}
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

def erat():
    end = 10 ** 6 + 1
    t = [False if i == 0 or i == 1 else True for i in range(end)]
    ret = [0 for i in range(end)]

    for i in range(2, end):
        if t[i]:
            for j in range(i * 2, end, i):
                t[j] = False
                if not ret[j]:
                    ret[j] = i
            ret[i] = i
    return ret

tmp = A[0]
for i in A[1:]:
    tmp = gcd(tmp, i)
isS = True if tmp == 1 else False
isP = True

e = erat()

D = dict(iter([(i, False) for i in range(10 ** 6 + 1)]))
for i in A:
    tmp = set()
    while i != 1:
        tmp.add(e[i])
        i //= e[i]
    for i in tmp:
        if D[i]:
            isP = False
            break
        else:
            D[i] = True
    if not isP:
        break

if isP:
    print('pairwise coprime')
elif isS:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 317492
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define inf 1000000000

int n,ary[N][N];
int pary[N],eary[N],color[N];

int dijkstra(){
  int i,u,v,mincost,sum=0;
  
  for(i=0;i<n;i++){
    color[i]=WHITE;
    pary[i]=inf;
  }
  pary[0]=0;
  eary[0]=-1;

  while(1){
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && pary[i]<mincost){
	mincost=pary[i];
	u=i;
      }
    }
    if(mincost==inf)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && ary[u][v]!=inf){
	if(pary[u]+ary[u][v]<pary[v]){
	  pary[v]=pary[u]+ary[u][v];
	  eary[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
}
int main(){

  int i,j,u,k,v,c,judge;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      ary[i][j]=inf;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      ary[u][v]=c;
    }
  }
  dijkstra();
  for(i=0;i<n;i++){
    if(pary[i]!=inf){
      judge=pary[i];
    }
    else{
      judge=-1;
    }
    printf("%d %d\n",i,judge);
  }
  return 0;
}




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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

const int mod = 1000000007;


int main() {
    ll x;
    cin >> x;

    ll k = x / 500;
    x %= 500;

    ll l = x / 5;

    cout << k * 1000 + l * 5 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define INF 1e9+5
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define pf push_front
#define pb push_back
#define popf pop_front
#define popb pop_back

ll a,b,n,ans;

int main(){
	scanf("%lld%lld%lld", &a,&b,&n);
	if(b<=n){
		ans=(a*(b-1))/b-a*((b-1)/b);
	}
	printf("%lld", max(ans, a*n/b-a*(n/b)));

	return 0;
}


Measured memory_bytes: 3812
import itertools

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]

ok = True        
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      flg = False
      for x,y in itertools.product([-1,0,1],repeat=2):
        if not (abs(x) + abs(y) == 1):
          continue
        nx = i + x;ny = j + y
        if 0 <= nx < H and 0 <= ny < W:
          if S[nx][ny] == '#':
            flg = True
      if not flg:
        ok = False
        break
if ok:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(int argc, char **argv) {
    int a, b;

    cin >> a >> b;

    if (a * b % 2 == 0) {
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

typedef long long LL;
const int MN = 100005;

int N, M; LL K;
LL x[MN];
int per[MN], vis[MN], stk[MN], tp;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%lld", &x[i]);
	for (int i = N; i >= 2; --i) x[i] -= x[i - 1];
	for (int i = 1; i <= N; ++i) per[i] = i;
	scanf("%d%lld", &M, &K);
	while (M--) {
		int p;
		scanf("%d", &p);
		std::swap(per[p], per[p + 1]);
	}
	for (int i = 1; i <= N; ++i) if (!vis[i]) {
		tp = 0;
		int u = i;
		do vis[u] = 1, stk[tp++] = u, u = per[u]; while (u != i);
		for (int j = 0; j < tp; ++j) per[stk[j]] = stk[(j + K) % tp];
	}
	LL s = 0;
	for (int i = 1; i <= N; ++i) s += x[per[i]], printf("%lld\n", s);
	return 0;
}

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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int tab[200010];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    for (int i = 1 ; i <= n ; i++)
        cin >> tab[i];
    double cur = 0.0;
    for (int i = 1 ; i <= k ; i++)
        cur += log(tab[i]);
    for (int i = k + 1 ; i <= n ; i++)
    {
        double last = cur;
        cur -= log(tab[i - k]);
        cur += log(tab[i]);
        if (cur > last)
            cout << "Yes\n";
        else
            cout <<  "No\n";
    }
    return 0;
}

Measured memory_bytes: 4708
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <chrono>

using namespace std;


class BPowerSocket {
public:
    void solve(std::istream &in, std::ostream &out) {
        int A, B;
        in >> A >> B;
        int n = 0;
        int answer = 1;

        while (answer < B) {
            n++;
            answer = A * n - (n - 1);
        }

        out << n << endl;
    }
};

int main()
{
    int A, B;
    cin >> A >> B;
    int n = 0;
    int answer = 1;

    while (answer < B) {
        n++;
        answer = A * n - (n - 1);
    }

    cout << n << endl;
}

Measured memory_bytes: 384
x = input().split(' ')
a = int(x[0])
b = int(x[1])
c = int(x[2])

if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
else:
    print(c, b, a)

Measured memory_bytes: 6724
s = input()
K = int(input())

l = []

for i in range(K):
    for j in range(len(s)-i):
        l.append(s[j:j+i+1])
l.sort()

ind = 0
cnt = 0
while cnt <K-1:
    if l[ind+1] != l[ind]:
        cnt += 1
    ind += 1
print(l[ind])

Measured memory_bytes: 4340
/*author - Ashutosh Chitranshi*/
#include<bits/stdc++.h>
using namespace std;
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define mp make_pair
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll a[n],b[n];
    for(int i=0;i<n;i++)
    	cin >> a[i] >> b[i];
    sort(a,a+n);
    sort(b,b+n);
    if(n%2==1)
    {
    	cout << b[n/2]-a[n/2]+1 << "\n";
    }
    else
    {
    	cout << b[n/2]-a[n/2]+b[n/2-1]-a[n/2-1]+1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 6732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    // https://atcoder.jp/contests/abc170/tasks/abc170_a

    class A_170_FiveVariables
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            int[] array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            for (int i = 0; i < array.Length ; i++)
            {
                if (array[i] == 0)
                {
                    Console.WriteLine(i + 1);
                }
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28276
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  int N, a;
  cin >> N;
  int rs = 0;
  set<int> s;
  REP(i, N) {
    cin >> a;
    if (a < 3200) {
      s.emplace(a / 400);
    } else {
      rs++;
    }
  }
  const int sz = s.size();
  const int resmin = max(1, sz);
  const int resmax = sz + rs;
  cout << resmin << " " << resmax << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}

ll inf = 2e18; 
ll mod = 1e9 + 7;

void resposta(vector<pll> &a, int k){
    ll ans = 1;
    int i;
    for(i=0;i<k;i++){
        ans *= a[i].second;
        ans %= mod;
        if(ans < 0) ans += mod;
    }
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, i, j;
    cin >> n >> k;
    vector<pll> a(n);
    bool hasP = false;
    for(i=0;i<n;i++){
        ll x; cin >> x;
        a[i] = {abs(x), x};
        if(x > 0) hasP  = true;
    }
    if(n == k){
        resposta(a, k);
        return 0;
    }
    sort(all(a));
    ll ans = 1;
    if(k%2 == 1 && (!hasP)){
        resposta(a, k);
        return 0;
    }
    reverse(all(a));
    if(k%2 == 0 && (!hasP)){
        resposta(a, k);
        return 0;
    }
    // for(i=0;i<n;i++){
    //     cout << a[i].first << " " << a[i].second << "\n";
    // }
    ll minP = inf, minN = inf;
    int imp, imn;
    int cntN = 0;
    for(i=0;i<k;i++){
        if(a[i].second < 0){
            cntN++;
            minN = a[i].second;
            imn = i;
        }else{
            minP = a[i].second;
            imp = i;
        }
    }
    ll nxtP = inf, nxtN = inf;
    for(i=k; i < n;i++){
        if(a[i].second < 0){
            if(nxtN == inf) nxtN = a[i].second;
        }else{
            if(nxtP == inf) nxtP = a[i].second;
        }
    }
    if(cntN%2 == 0){
        resposta(a, k);
        return 0;
    }
    if(minP == inf){
        a[imn] = {abs(nxtP), nxtP};
        resposta(a, k);
        return 0;
    }
    assert(minP != inf && minN != inf);
    ll op1, op2;
    if(nxtN == inf){
        op1 = -inf;
    }else{
        op1 = minN * nxtN;
    }
    if(nxtP == inf){
        op2 = -inf;
    }else{
        op2 = nxtP * minP;
    }
    if(op1 > op2){
        a[imp] = {abs(nxtN), nxtN};
    }else{
        a[imn] = {nxtP, nxtP};
    }
    resposta(a, k);
    return 0;
}

Measured memory_bytes: 6348
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);


int main()
{
	IOS
	


	ll n;
	cin>>n;
	ll a[n],b[n],c[n];
	rep(i,n)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	ll dp[n][3];

	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];


	rep1(i,n-1)
	{
		dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][2],dp[i-1][0]);
		dp[i][2] = c[i] + max(dp[i-1][1],dp[i-1][0]);
	}

	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;


    return 0;
}

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

int n;
vector<int> s[3200];

int main() {
	cin >> n;
	int k = sqrt(2 * n);
	++k;
	if (k * (k - 1) != 2 * n) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl << k << endl;
	int m = 1;
	for (int i = 0; i < k - 1; ++i)
		for (int j = i + 1; j < k; ++j) {
			s[i].emplace_back(m);
			s[j].emplace_back(m);
			++m;
		}
	for (int i = 0; i < k; ++i) {
		cout << k - 1;
		for (int j = 0; j < k - 1; ++j)
			cout << " " << s[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 4328
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;




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

	vector<int>v(5);
	int m = 10;
	for (auto &i : v) {
		cin >> i;
		if(i%10)m = min(m, i % 10);
		M += (i / 10*10) + (!!(i % 10)) * 10;
	}
	if (m != 10) {
		M -= 10;
		M += m;
	}
	cout << M << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;


int main(){
    ll c=0,d=0,k=0,n,m,h,w,p,q,ans=0;
    string s,s1,s2;
    cin >> n >>k;
    for(int i=0;i<n;i++){
        cin >> h;
        if(h>=k){
            c++;
        }

    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
    char s[20];
    scanf("%s",s);
    for(int i = 0 ; i<strlen(s);i++){
        if(s[i] == ','){
            printf(" ");
        }
        else
            printf("%c",s[i]);
    }
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

//bipartite matching
const int MAX_V = 210;

int V; 
vector<int> g[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void init() {
	rep(i, MAX_V) g[i].clear();
}

inline void add_edge(int u, int v) {
	g[u].push_back(v);
	g[v].push_back(u);
}

bool dfs(int v) {
	used[v] = true;

	for (int u : g[v]) {
		int w = match[u];
		if (w < 0 || (!used[w] && dfs(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}

	return false;
}

int bipartite_matching() {
	int res = 0;
	memset(match, -1, sizeof(match));

	for (int v = 0; v < V; ++v) {
		if (match[v] < 0) {
			memset(used, 0, sizeof(used));
			res += dfs(v);
		}
	}

	return res;
}

const int MX = 110;

bool us[MX * MX];
int A[MX][MX], B[MX][MX], C[MX][MX];

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

	rep(i, N) rep(j, M) {
		cin >> A[i][j];
		--A[i][j];
	}

	V = N + N;

	rep(j, M) {
		init();
		rep(p, N) rep(q, M) {
			int x = A[p][q];
			if (!us[x]) {
				add_edge(p, x / M + N);
			}
		}
		int mt = bipartite_matching();

		rep(p, N) {
			int c = match[p] - N;
			int to = -1;
			rep(q, M) {
				int x = A[p][q];
				if (!us[x] && x / M == c) {
					to = x;
				}
			}
			B[p][j] = to;
			us[to] = 1;
		}
	}

	rep(j, M) {
		rep(i, N) {
			rep(p, N) if (B[p][j] / M == i) {
				C[i][j] = B[p][j];
			}
		}
	}

	rep(i, N) {
		rep(j, M) {
			printf("%d%c", B[i][j] + 1, j == M-1 ? '\n' : ' ');
		}
	}

	rep(i, N) {
		rep(j, M) {
			printf("%d%c", C[i][j] + 1, j == M-1 ? '\n' : ' ');
		}
	}

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

LL n;

int ans = 0;

inline bool check(LL K) {
	if (K == 1) return false;
	LL x = n;
	while (x % K == 0) x /= K;
	return (x - 1) % K == 0;
}

int main() {
	scanf("%lld", &n);
	LL x = n - 1;
	for (int i = 1; i <= x / i; i++) {
		if (x % i == 0) {
			if (i > 1 && (n % i)) ans++;
			if (x / i != i && (n % (x / i))) ans++;
		}
	}
	for (int i = 1; i <= n / i; i++) {
		if (n % i == 0) {
			if (check(i)) ans++;
			if (n / i != i && check(n / i)) ans++; 
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 3050
int n,a[N],head[N],to[N<<1],nxt[N<<1],cnt;
int mn[N],se[N],is[N];
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
}
int dfs(int x) {
	int i;
	for(i=head[x];i;i=nxt[i]) if(a[to[i]]<a[x]&&!dfs(to[i])) return 1;
	return 0;
}
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	int x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(i=1;i<=n;i++) {
		if(dfs(i)) printf("%d ",i);
	}
	puts("");
}


Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <thread>
#include <unordered_set>
#include <vector>
#include <memory.h>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <stdio.h>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <random>
#include <string>
#include <cassert>


#define getcx _getchar_nolock

using namespace std;
 
namespace std
{
	string to_string(string const& s) { return '"' + s + '"'; }
	string to_string(char c) { return string(1, c); }
	string to_string(const char* s) { return to_string((string)s); }
	string to_string(bool b) { return (b ? "true" : "false"); }
 
	template <class T1, class T2>
	string to_string(pair<T1, T2> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
 
	template <class T>
	string to_string(T c)
	{
		string s = "[";
		for (auto vvv : c) { s += to_string(vvv) + ","; }
		s += "]";
		return s;
	}
 
	void debug_impl() { cerr << endl; };
 
	template <typename T1, typename... T2>
	void debug_impl(T1 a, T2 ... b)
	{
		cerr << " " << to_string(a);
		debug_impl(b...);
	}
}
 
template <typename T>
struct reversion_wrapper
{
	T& iterable;
};
 
template <typename T>
auto begin(reversion_wrapper<T> w) { return std::rbegin(w.iterable); }
 
template <typename T>
auto end(reversion_wrapper<T> w) { return std::rend(w.iterable); }
 
template <typename T>
reversion_wrapper<T> reverse(T&& iterable) { return { iterable }; }
 
template<class T>T gcd(T a, T b) { while (a && b)if (a > b)a %= b; else b %= a; return a + b; }
template<class T>T powmod(T a, T b, T mod) { if (b == 0)return 1 % mod; T res = powmod(a, b / 2, mod); res *= res; res %= mod; if (b & 1) { res *= a; res %= mod; } return res; }
template<class T>T inv(T a, T mod) { return powmod(a, mod - 2, mod); }
 
#ifdef __ASD__
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_impl(__VA_ARGS__)
#define endl "\n"
#else
#define dbg(...) ;
#define endl "\n"
#endif
 
#define lng long long

lng const MOD = 998244353;


int main()
{
#ifdef __ASD__
	auto start_t = chrono::steady_clock::now();
	freopen("input.txt", "r", stdin);
	//freopen("1nul", "w", stderr);
	//freopen("output.txt", "w", stdout);
#else
	ios_base::sync_with_stdio(false);
#endif

	int n, x, y;
	cin >> n >> x >> y;

	vector<int> res(n);

	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {

			int d = abs(i-j);
			d=min(d, abs(i-x)+abs(j-y)+1);
			d=min(d, abs(j-x)+abs(i-y)+1);
			if (i==j)d=1;
			dbg(i,j,d);
			res[d]++;
		}
	}

	for(int i=1;i<n;i++)cout<<res[i]<<endl;

#ifdef __ASD__
	auto finish_t = chrono::steady_clock::now();
	cerr << "Elapsed " << chrono::duration_cast<chrono::milliseconds>(finish_t - start_t).count() << " ms" << endl;
#endif
	return 0;
}

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

int main() {
  ll N; cin >> N;
  ll a[N];
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll b[N];
  fill(b, b+N, INF);
  for (ll i = 0; i < N; i++) {
    *upper_bound(b, b+N, a[N-1-i]) = a[N-1-i];
  }
  ll res = 0;
  for (ll i = 0; i < N; i++) {
    if (b[i] != INF) {res++;}
  }
  cout << res << endl;
}
  

Measured memory_bytes: 1792
n = int(input())
s = input()
cw = 0
cb = 0
di = []
a = -1
b = 0
mn = float("inf")
for i in range(n):
    if s[i] == ".":
        cw += 1
    else:
        di.append(i)
        cb += 1
for k in range(len(di)):
    if mn > cw - di[k] + 2*k:
        mn = cw - di[k] + 2*k
print(min(min(cw,cb),mn))

Measured memory_bytes: 17316
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    let ans = if (0..(N / 7 + 1)).any(|i| (N - 7 * i) % 4 == 0) {
        "Yes"
    } else {
        "No"
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int N, M, Q, a[50], b[50], c[50], d[50];
int A[10];
int ans = 0;

void dfs(int n) {
    if(n == N) {
        int sum = 0;
        rep(i, Q) if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
        chmax(ans, sum);
        return;
    }
    Rep(i, A[n], M+1) {
        A[n+1] = i;
        dfs(n+1);
    }
}

int main() {
    cin >> N >> M >> Q;
    rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    A[0] = 1;
    dfs(0);
    cout << ans << endl;
}


Measured memory_bytes: 3604