akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
using namespace std;
const int INF=101;

int count(char *front,int fn,char *back,int bn){
	char *p=&front[fn-bn];
	if(p<front)p=front;
	int n= &front[fn]-p;
	for(;*p!='\0';p++){
		if(strncmp(p,back,n)==0)return n;
		n--;
	}
	return 0;
}
bool substr(char *a,char *b){
	int n=strlen(a);
	for(;*b!='\0';b++){
		if(strncmp(a,b,n)==0)return true;
	}
	return false;
}
int delete_substr(char str[][10+1],int n,bool flag[]){
	for(int i=0;i<n;i++){
		if(flag[i]){
			for(int j=i+1;j<n;j++){
				strcpy(str[j-1],str[j]);
				flag[j-1]=flag[j];
			}
			i--;
			n--;
		}
	}
	return n;
}
int main(){
	char str[10][10+1];
	int str_len[10];
	static char dp[1<<10][10][10*10+1];
	int len[1<<10][10];
	int n;
	bool flag[10];
	while(cin>>n, n){
		memset(flag,false,sizeof(flag));
		for(int i=0;i<n;i++){
			cin>>str[i];
			for(int j=0;j<i;j++){
				if(substr(str[j],str[i])){
					flag[j]=true;
				}
				else if(substr(str[i],str[j])){
					flag[i]=true;
				}
			}
		}
		n= delete_substr(str,n,flag);
		for(int i=0;i<n;i++){
			str_len[i]=strlen(str[i]);
		}
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<n;j++){
				len[i][j]=INF;
				dp[i][j][0]='\0';
			}
		}
		for(int i=1;i<(1<<n);i++){
			for(int j=0;j<n;j++){
				if(!(i&1<<j))continue;
				int pre= i&~(1<<j);
				if(pre==0){//空文字列
					len[1<<j][j]=str_len[j];
					strcpy(dp[1<<j][j],str[j]);
					break;
				}
				for(int k=0;k<n;k++){
					if(!(pre&1<<k))continue;
					int tmp= count(str[k],str_len[k],str[j],str_len[j]);
					int l= len[pre][k]+str_len[j]-tmp;
					char s[101];
					if(len[i][j] < l)continue;
					strcpy(s,dp[pre][k]);
					strcat(s,str[j]+tmp);
					if(l < len[i][j] || l==len[i][j]&&strcmp(s,dp[i][j])<0){
						len[i][j]= l;
						strcpy(dp[i][j],s);
					}
				}
			}
		}
		int min=0;
		for(int i=1;i<n;i++){
			if(len[(1<<n)-1][i]<len[(1<<n)-1][min]
				|| len[(1<<n)-1][i]==len[(1<<n)-1][min] && strcmp(dp[(1<<n)-1][i],dp[(1<<n)-1][min])<0){
				min=i;
			}
		}
		cout<<dp[(1<<n)-1][min]<<endl;
	}
}

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <string>
int main(){
  std::string s;
  getline(std::cin,s);
  std::vector<int> apv,ppv;
  int apos=0,ppos=0;
  while(apos=s.find("apple",apos),ppos=s.find("peach",ppos),apos!=std::string::npos||ppos!=std::string::npos){
    if(apos!=std::string::npos)
      apv.push_back(apos),apos+=5;
    if(ppos!=std::string::npos)
      ppv.push_back(ppos),ppos+=5;
  }
  std::vector<int>::iterator it=apv.begin();
  while(it!=apv.end())
    s.replace(*it,5,"peach"),it++;
  it=ppv.begin();
  while(it!=ppv.end())
    s.replace(*it,5,"apple"),it++;
  std::cout<<s<<std::endl;
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  string s;
  int a;
  map<string, map<int, int>> mp;
  for (int i = 0; i < n; i++) {
    cin >> s;
    cin >> a;
    mp[s][a] = i + 1;
  }
  for(auto i: mp) {
    int b = i.second.size();
    int ans[b];
    for (auto j: i.second) {
      ans[b - 1] = j.second;
      b--;
    }
    for (auto j: ans) cout << j << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,l[10],m,n,v1,v2;
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
   l+0,l+1,l+2,l+3,l+4,l+5,l+6,l+7,l+8,l+9,&v1,&v2)!=EOF){
    m=0;
    for(i=0;i<10;i++) m+=l[i];
    n=m*3600/(v1+v2)*v1;
    for(i=0;i<10;i++) if((n-=l[i]*3600)<=0) break;
    printf("%d\n",i+1);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	int l[100002],r[100002];
	memset(l,0,sizeof(l));
	memset(r,0,sizeof(r));
	
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		l[a]++;
		r[b]++;
	}
	
	int can = 0;
	int ans = 0;
	for(int i = 1;i <= n+1;i++){
		can += l[i+1];
		if(can >= i){
			ans = i;
		}
		can -= r[i+1];
	}
	
	cout << ans << endl;
	return 0;
}


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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

const ll inf = numeric_limits<ll>::max();

void solve(){
    ll n;
    cin>>n;
    ll h[n + 1], dp[n+1][2];

    rep(i, 1, n) cin>>h[i];

    dp[1][0] = dp[1][1] = 0;
    dp[2][0] = 0ll + llabs(h[2] - h[1]);
    dp[2][1] = inf;

    rep(i, 3, n){
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + llabs(h[i] - h[i-1]);
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + llabs(h[i] - h[i-2]);
    }

    cout<<min(dp[n][0], dp[n][1]);

}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 2560
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> v1, v2;
    for(int i = 0 ; i < n ; i++) {
        int t;
        scanf("%d", &t);
        if(t < 0) v1.push_back(-t);
        else v2.push_back(t);
    }
    reverse(v1.begin(), v1.end());
    int ans = 2147483647;
    for(int i = min((int)v1.size(), k) ; i >= 0 && k-i-1 < (int)v2.size(); i--) {
        //v1 pick i
        int v1val = (i == 0) ? 0 : v1[i-1];
        int v2val = (k - i == 0) ? 0 : v2[k-i-1];
        ans = min(ans, v1val*2+v2val);
        ans = min(ans, v1val+v2val*2);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1020
import java.util.*;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N=sc.nextInt(),K=sc.nextInt(),p[]=new int[N];
		for(int i=0;i<N;i++) {
			p[i]=sc.nextInt();
		}
		Arrays.sort(p);
		int sum=0;
		for(int i=0;i<K;i++) {
			sum+=p[i];
		}
		System.out.println(sum);
	}
}

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

#define ll long long

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,y;
    cin>>x>>y;
    ll ans = 0;
    if(x==3){
        ans+=100000;
    }
    if(x==2){
        ans+=200000;
    }
    if(x==1){
        ans+=300000;
    }
    if(y==1){
        ans+=300000;
    }
    if(y==2){
        ans+=200000;
    }
    if(y==3){
        ans+=100000;
    }
    if(x==1 && y==1) ans+=400000;
    cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define REP(i, x, y) for (int i = x; i < y; i++)

const int8_t  INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF  = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
    ios::sync_with_stdio(0);
    int r, g, b, n, ans = 0;
    cin >> r >> g >> b >> n;
    REP(ir, 0, 3001)
    {
        if (ir * r > n) break;
        REP(ig, 0, 3001)
        {
            if (ir * r + ig * g > n) break;
            ans += (((n - ir * r - ig * g) % b) == 0);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int data[201][3];
  int dataa[201][3];
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>data[i][j];
      dataa[i][j]=data[i][j];
    }
  }

  for(int i=0;i<3;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(j!=k && data[j][i]==data[k][i]){
	  dataa[j][i]=0;
	  dataa[k][i]=0;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<dataa[i][0]+dataa[i][1]+dataa[i][2]<<endl;
  }
  return 0;
}
		 

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define int long long
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> P;
typedef vector<P> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,k;
  cin>>n>>k;
  V a(n);
  rep(i,n)cin>>a[i];
  
  int res=0;
  for(int d=60;d>=-1;--d){
    if(d!=-1 && !(k&(1LL<<d)))continue;
    //����͂Ȃ�

    int tmp=0;
    for(int e=60;e>=0;--e){
      int mask=1LL<<e;
      int num=0;
      rep(i,n)if(a[i]&mask)num++;
      
      if(e>d){
        if(k & mask)tmp+=mask*(n-num);
        else tmp+=mask*num;
      }
      else if(e==d){
        tmp+=mask*num;
      }
      else {
        tmp+=mask*max(num,n-num);
      }
    }
    chmax(res,tmp);
  }
  out(res);
  
  
  return 0;
}



Measured memory_bytes: 1024
A, B = map(int, input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A_list = prime_factorize(A)
B_list = prime_factorize(B)

A_and_B = set(A_list) & set(B_list)
print(len(A_and_B)+1)

Measured memory_bytes: 3064
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11700
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include<math.h>
#define pi 3.14159265358979
#define int long long
using namespace std;


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
// #ifndef ONLINE_JUDGE
//    freopen ("INPUT.txt" , "r" , stdin);
//    freopen ("OUTPUT.txt" , "w" , stdout);
// #endif

    clock_t clk;
	clk = clock();

// --------------Code s0tarts here---------------------------------------------------------------------

    int a,b,x;
    cin>>a>>b>>x;
    long double aa=a,bb=b,xx=x;
    if(xx<(aa*aa*bb)/2)
    {
        long double t=((2*xx)/(aa*bb));
        t=(bb/t);
        long double ans=atan(t)*((180.0)/pi);
        cout<<fixed<<setprecision(10)<<ans;
    }
    else
    {
        long double t=(2*xx)/(aa*aa)-bb;
        t=bb-t;
        t=(t/aa);
        long double ans=atan(t)*((180.0)/pi);
        cout<<fixed<<setprecision(10)<<ans;
    }
    
// -------------------------------------Code ends here------------------------------------------------------

    clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi s(1<<n);
    multiset<int> a,b;
    rep(i,1<<n)cin>>s[i],a.insert(-s[i]);
    RSORT(s);
    a.erase(-s[0]);
    b.insert(-s[0]);
    rep(i,n){
        vi v;
        for(int x:b){
            auto itr=a.upper_bound(x);
            if(itr==a.end()){
                cout<<"No"<<endl;
                return;
            }
            int y=*itr;
            v.pb(y);
            a.erase(itr);
        }
        for(int y:v){
            b.insert(y);
        }
        // cout<<"a:";
        // for(int x:a)cout<<x<<sp;cout<<endl;
        // cout<<"b:";
        // for(int x:b)cout<<x<<sp;cout<<endl;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 16116
A = list(map(int,input().split()))
dx = A[2] - A[0]
dy = A[3] - A[1]
sta = "U" * dy + "R" * dx + "D" * dy + "L" * dx
stb = "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D"
stc = "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U"
st = sta + stb + stc
print(st)

Measured memory_bytes: 3060
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (ll)(x).size()
#define trav(x) for(auto& it: x)
#define all(x) x.begin(), x.end()
#define stp fixed<<setprecision(20)
#define db(x) cout<<#x<<": "<<x<<endl
#define tc ll tt; cin>>tt; while(tt--)
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rFor(i, st, en) for(ll i=st; i>=en; i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define printv(x) For(i, 0, sz(x)){cout<<x[i]<<" ";} cout<<endl;
#define print2v(x) For(i, 0, sz(x)){For(j, 0, sz(x[i])){cout<<x[i][j]<<" ";} cout<<endl;}
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
#define endl '\n'
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007
#define bitc __builtin_popcountll

int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (double)(clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n";

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

void splitx(string s, char c, vector<string> &v){
    int i=0, j;
    while(i<sz(s)){
        j=i; string temp;
        while(j<sz(s) && s[j]!=c){temp+=s[j]; j++;}
        v.pb(temp); i=j+1;
    }
}

/*################################ ¯\_(ツ)_/¯ ################################*/



signed main(){
	fast
	string s, t;
	cin>>s>>t;

	int n = sz(s);
	int m = sz(t);

	vvi dp(n, vi(m, 0));

	For(i, 0, n){
		For(j, 0, m){
			if(i==0){
				if(s[i]==t[j]){
					dp[i][j]=1;
				}else if(j && dp[i][j-1]==1){
					dp[i][j]=1;
				}
			}else if(j==0){
				if(s[i]==t[j]){
					dp[i][j]=1;
				}else{
					dp[i][j]=dp[i-1][j];
				}
			}else{
				if(s[i]==t[j]){
					dp[i][j] = dp[i-1][j-1]+1;
				}
				dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
			}			
		}
	}

	// print2v(dp);	
	vi inds;
	int val = dp[n-1][m-1];
	int i=n-1, j=m-1;
	while(j>=0 && i>=0){
		while(i && dp[i-1][j]==dp[i][j]) i--;
		while(j && dp[i][j-1]==dp[i][j]) j--;
		if(j!=0) inds.pb(j);
		else if(dp[i][j]) inds.pb(0);
		j--;
	}
	// printv(inds);
	reverse(all(inds));
	string ans;
	trav(inds){
		ans+=t[it];
	}
	cout<<ans<<endl;
    // end_routine()
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }

    ll last = 0;
    ll count = 0;
    rep(i, n) {
        if (a[i] == last + 1) {
            last++;
            continue;
        } else {
            count++;
        }
    }

    if (last == 0) {
        cout << -1 << endl;
    } else {
        cout << count << endl;
    }
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) os << v[i] << " \n"[i+1==v.size()]; return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N;
  int K = (N & 1 ? N : N+1);
  vector<pii> G;
  for (int i = 1; i <= N; i++) {
    for (int j = i+1; j <= N; j++) {
      if (i+j == K) continue;
      G.emplace_back(i,j);
    }
  }
  cout << G.size() << endl;
  for (auto p : G) cout << p << endl;

  return 0;
}

Measured memory_bytes: 512
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    string s;
    cin >> s;

    if (s.back() == 's') {
        s += "es";
    }else {
        s+="s";
    }
    

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3616
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
a = input()
b = input()
if a[2] == b[0] and a[1] == b[1] and a[0] == b[2]:
    print("YES")
else:
    print("NO")
"""

#B
n = I()
n = int(math.sqrt(n))
print(n**2)

Measured memory_bytes: 38384
#include <stdio.h>

int		main()
{
	int		N;
	int		X;
	int		price;

	scanf("%d\n", &N);
	X = N / 1.08;
	while (price < N)
	{
		price = X * 1.08;
		X++;
	}
	X--;
	if (price >= (N + 1))
		printf(":(\n");
	else
		printf("%d\n", X);
	return (0);
}


Measured memory_bytes: 128
#include <stdio.h>
#define MAX 100000

int Partition(int*, int, int);

int main(){
  int i, n, x;
  int A[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  x = Partition(A,0,n-1);

  for(i=0;i<n-1;i++){
    if(x == i){
      printf("[%d] ",A[i]);
      continue;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  
  return 0;
}

int Partition(int *A, int p, int r){
  int x, i, j;
  int tmp;
  
  x = A[r];
  i = p - 1;

  for(j=p;j<r;j++){
    if(A[j]<= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
  
  return i+1;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
 
using namespace std;
ll CNB(ll i) {
  return i*(i-1)/2;
}

int main() {
  ll N;
  cin>>N;
  vec C(N);
  map<ll,ll> A;
  ll B;
  rep(i,0,N) {
    cin>>C[i];
    A[C[i]]++;
  }
  ll count=0;
  for(auto p:A) {
    count+=CNB(p.second);
  }
  ll D;
  D=count;
  
  rep(i,0,N) {
    count=D;
    count-=CNB(A[C[i]]);
    count+=CNB(A[C[i]]-1);
    cout<<count<<endl;
  }
  
}
    

Measured memory_bytes: 11008
import numpy as np
N, M = map(int, input().split())

a = np.zeros((M,2))

for i in range(M):
	a[i] = list(map(int, input().split()))

a = a[np.argsort(a[:,1])]

index = 0
ans = 0
for tmp in a:
	if tmp[0] <= index:
		continue
	else:
		ans += 1
		index = tmp[1] - 1

print(ans)

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


int main() {
#ifndef ONLINE_JUDGE
	//for getting input from input.txt
	freopen("input.txt" , "r" , stdin) ;
	//for writing output to output.txt
	freopen("output.txt" , "w" , stdout) ;
#endif
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n ;
	cin >> n ;
	vector<long long> small ;
	vector<long long>large  ;
	for (int i = 0 ; i < n ; ++i) {
		long long a , b ;
		cin >> a >> b  ;
		small.push_back(a) ;
		large.push_back(b) ;
	}

	sort(small.begin() , small.end()) ;
	sort(large.begin() , large.end()) ;
	if (n % 2 == 1) {
		long long d = large[(n) / 2] - small[(n) / 2] + 1 ;
		cout << d << endl ;
	}
	else {
		long long a, b ;
		a = small[n / 2 - 1] +  small[n / 2 ]   ;

		b = large[n / 2 - 1]  + large[n / 2] ;
		cout << b - a + 1 << endl ;

	}


}

Measured memory_bytes: 6584
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

int solve(int N, vector<string> a)
{
    int rn = 0;
    for (int x=0; x<N; x++)
    {
        bool ok = true;
        for (int y=0; y<N; y++)
            if (a[y][x]=='.')
                ok = false;
        if (!ok)
            rn++;
    }

    int oo = 99999999;
    int ans = oo;
    for (int ty=0; ty<N; ty++)
    {
        bool ok = false;
        for (int y=0; y<N; y++)
            if (a[y][ty]=='#')
                ok = true;
        if (ok)
        {
            int cnt = 0;
            for (int x=0; x<N; x++)
                if (a[ty][x]=='.')
                    cnt++;
            ans = min(ans, cnt+rn);
        }
        else
        {
            bool ok = false;
            for (int x=0; x<N; x++)
                if (a[ty][x]=='#')
                    ok = true;
            if (ok)
            {
                int cnt = 0;
                for (int x=0; x<N; x++)
                    if (a[ty][x]=='.')
                        cnt++;
                ans = min(ans, cnt+rn+1);
            }
        }
    }
    return ans<oo ? ans : -1;
}

int naive(int N, vector<string> a)
{
    int oo = 9999;
    vector<int> D(1<<(N*N), oo);
 
    auto hash = [&](){
        int hash = 0;
        for (int y=0; y<N; y++)
            for (int x=0; x<N; x++)
                hash = hash<<1 | (a[y][x]=='#' ? 1 : 0);
        return hash;
    };
 
    D[hash()] = 0;
    vector<bool> F(1<<(N*N), false);
    priority_queue<pair<int,int>> Q;
    Q.push(make_pair(0, hash()));
 
    while (!Q.empty())
    {
        int h = Q.top().second;
        int d = -Q.top().first;
 
        Q.pop();
        if (F[h])
            continue;
        F[h] = true;
 
        for (int y=0; y<N; y++)
            for (int x=0; x<N; x++)
                a[y][x] = ".#"[h&1],
                h>>=1;
 
        vector<string> tmp = a;
        for (int sy=0; sy<N; sy++)
        for (int sx=0; sx<N; sx++)
        {
            for (int i=0; i<N; i++)
                a[i][sx] = tmp[sy][i];
            int h = hash();
            if (D[h] > d+1)
            {
                D[h] = d+1;
                Q.push(make_pair(-(d+1), h));
            }
            a = tmp;
        }
    }
    return D[(1<<(N*N))-1]<oo ? D[(1<<(N*N))-1] : -1;
}

int main()
{
    /*
    int N = 4;
    for (int b=0; b<(1<<(N*N)); b++)
    {
        vector<string> a(N, string(N, '.'));
        int t = b;
        for (int y=0; y<N; y++)
            for (int x=0; x<N; x++)
                a[y][x] = ".#"[t&1],
                t>>=1;
        int nans = naive(N, a);
        int sans = solve(N, a);
        if (nans != sans)
        {
            for (auto s: a)
                cout<<s<<endl;
            cout<<nans<<" "<<sans<<endl;
        }
    }
    */
    int N;
    cin>>N;
    vector<string> a(N);
    for (int i=0; i<N; i++)
    {
        cin>>a[i];
    }

    cout<<solve(N, a)<<endl;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	std::vector<int> v(n);
	for (size_t i = 0; i < n; i++) {
		std::cin >> v[i];
	}
	sort(v.begin(),v.end());
	double ans1,ans2;
	ans1 = v[v.size()-1];
	ans2 = v[0];


	for (size_t i = 0; i < v.size(); i++) {
		if (abs(ans1/2 - ans2) > abs(ans1/2 - v[i])) {
			ans2 = v[i];
		}
	}

	std::cout << (int)ans1 << ' ' << (int)ans2 << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
using namespace std;
signed main(){
    int n; cin>>n;
    vector<int> a(n),sums(n),remain(n);
    int sum=0;
    rep(i,n){
        cin>>a.at(i);
        sum+=a.at(i);
        sums.at(i)=sum;
    }
    rep(i,n) remain.at(i)=sum-sums.at(i);
    int ans=LONG_LONG_MAX;
    rep(i,n-1){
        ans=min(ans,abs(remain.at(i)-sums.at(i)));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

#define ll long long
#define VEC2(type, name, dim0, dim1, init_val) vector<vector<type>> name(dim0, vector<type>(dim1, init_val))
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name)

#define REP(name, start, end) for(ll name = (start); (name) < (end); ++(name))
#define REPR(name, end, start) for(ll name = (start - 1); (name) >= (end); --(name))
#define ALL(iterable) (iterable).begin(), (iterable).end()

int main()
{
	cout << fixed << setprecision(6);
	IN(string, s);
	IN(string, t);

	map<char, vector<ll>> charIndice;
	map<char, ll> usedCount;
	REP(i, 0, s.length()) {
		charIndice[s[i]].push_back(i);
		usedCount[s[i]] = 0;
	}
	REP(i, 0, t.length()) {
		if (charIndice.find(t[i]) == charIndice.end()) {
			cout << -1 << endl;
			return 0;
		}
	}
	

	ll loopcnt = 0;
	ll curIdx = -1;
	REP(i, 0, t.length()) {
		bool isDone = false;
		if (usedCount[t[i]] < charIndice[t[i]].size()) {
			REP(j, usedCount[t[i]], charIndice[t[i]].size()) {
				if (charIndice[t[i]][j] > curIdx) {
					curIdx = charIndice[t[i]][j];
					usedCount[t[i]] = j + 1;
					isDone = true;
					break;
				}
			}
		}
		if(!isDone) {
			curIdx = -1;
			++loopcnt;
			for (auto& uc : usedCount)uc.second = 0;
			--i;
			continue;
		}
	}

	cout << loopcnt * s.length() + curIdx + 1 << endl;
	return 0;
}

Measured memory_bytes: 1728
N = int(input())
S = list(map(int, input()))
ans = 0
first = [0] * 10
a = 0
for i in range(N):
  if first[S[i]] == 0:
    first[S[i]] = 1
    a += 1
    second = [0] * 10
    b = 0
    for j in range(i+1, N):
      if second[S[j]] == 0:
        second[S[j]] = 1
        b += 1
        third = [0] * 10
        c = 0
        for k in range(j+1, N):
          if third[S[k]] == 0:
            third[S[k]] = 1
            ans += 1
            c += 1
            if c == 10:
              break
        if b == 10:
          break
    if a == 10:
      break
print(ans)

Measured memory_bytes: 9564
#!/usr/bin/env python3
s = input()
l = ["A", "C", "G", "T"]
ans = 0
tmp = 0
for i in range(len(s)):
    if s[i] in l:
        tmp += 1
        if ans <= tmp:
            ans = tmp
    else:
        tmp = 0
print(ans)
    

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

int main() {
	char C;
	for (int i = 0; ; i++) {
		scanf("%c", &C);
		if (C == '\n') {
			cout << endl;
			break;
		}
		if (65 <= C && C <= 96) C += 32;
		else if (97 <= C && C <= 127) C -= 32;
		cout << C;
	}
}


Measured memory_bytes: 3152
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int a,b,c=0;
	cin>>a>>b;
	int f=0;
	FOR(i,1,4){
		c=i;
		if((a*b*c)%2==1)f=1;
	}
	if(f)cout<<"Yes";
	else cout<<"No";
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define N 1050
#define LL long long
const int mod=1e9+7;
using namespace std;
LL n,m,k;
int a,b,c;
char s[N][N];
inline int qpow(int d,LL z){
	int ret=1;z%=(mod-1);
	for(;z;z>>=1,d=1ll*d*d%mod)
		if(z&1)ret=1ll*ret*d%mod;
	return ret;
}
struct node{
	int a[2][2];
	friend node operator *(const node a,const node b){
		static node c;
		c.a[0][0]=(1ll*a.a[0][0]*b.a[0][0]+1ll*a.a[0][1]*b.a[1][0])%mod;
		c.a[0][1]=(1ll*a.a[0][1]*b.a[1][1]+1ll*a.a[0][0]*b.a[0][1])%mod;
		c.a[1][0]=(1ll*a.a[1][0]*b.a[0][0]+1ll*a.a[1][1]*b.a[1][0])%mod;
		c.a[1][1]=(1ll*a.a[1][1]*b.a[1][1]+1ll*a.a[1][0]*b.a[0][1])%mod;
		return c;
	}
}ans,d;
inline node qpow(node d,LL z){
	static node ret;
	ret.a[0][0]=ret.a[1][1]=1;
	ret.a[0][1]=ret.a[1][0]=0;
	for(;z;z>>=1,d=d*d)if(z&1)ret=ret*d;
	return ret;
}
int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)c+=s[i][j]=='#';
	if(k==1)return puts("1"),0;
	for(int i=1;i<=n;++i)a+=(s[i][1]=='#'&&s[i][m]=='#');
	for(int j=1;j<=m;++j)b+=(s[1][j]=='#'&&s[n][j]=='#');
//	cout<<a<<" "<<b<<" "<<c<<endl;
	if(!a&&!b)return printf("%d\n",qpow(c,k-1)),0;
	if(a&&b)return puts("1"),0;
	int ok=0;
	if(!b)b=a,ok=1;a=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			if(ok&&s[i][j]=='#'&&s[i][j+1]=='#')++a;
			if(!ok&&s[i][j]=='#'&&s[i+1][j]=='#')++a;
		}
	}
//	cout<<c<<" "<<a<<" "<<b<<endl;
	d.a[0][0]=c;d.a[0][1]=a;d.a[1][1]=b;
	ans=qpow(d,k-1);
	cout<<(ans.a[0][0]-ans.a[0][1]+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <algorithm> 
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	long long a[4];
	bool j[4];
	for(int i=0;i<3;i++)	
	{
		cin>>a[i];
		j[i]=a[i]%2;
	}
	if(j[0]&&j[1]&&j[2])
	{
		sort(a,a+3);
		cout<<a[0]*a[1];
		return 0; 
	}
	cout<<0;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }

    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}
class Program
{
    public static void Main()
    {
        long MAX = 1000000000000;
        int a, b, q;

        var tt = ReadIntArray();
        a = tt[0];
        b = tt[1];
        q = tt[2];

        var s = new long[a+2];
        var t = new long[b+2];
        var x = new long[q];

        for (int i = 1; i <= a; i++){ s[i] = long.Parse(ReadLine()); }
        s[0] = -MAX; s[a+1] = MAX;

        for (int i = 1; i <= b; i++){ t[i] = long.Parse(ReadLine()); }
        t[0] = -MAX; t[b+1] = MAX;

        for (int i = 0; i < q; i++){ x[i] = long.Parse(ReadLine()); }

        for (int i = 0; i < q; i++)
        {
            long ans = Solve(s, t, x[i]);
            WriteLine(ans);
        }
    }

    static int Search(long[] a, long x)
    {
        int l = 0, r = a.Length - 2;

        while(true)
        {
            if (l > r){ return -1; } // Must not occur in this program.

            int m = (l + r) / 2;

            if (a[m]  >= x)
            {
                r = m - 1;
            }
            else if (a[m+1] < x)
            {
                l = m + 1;
            }
            else
            {
                return m;
            }
        }
    }

    static long Solve(long[] s, long[] t, long x)
    {
        long ans = 1000000000000;

        long sl, sr, tl, tr;

        int i = Search(s, x); sl = s[i]; sr = s[i+1];
        int j = Search(t, x); tl = t[j]; tr = t[j+1];

        ans = Math.Max(sr, tr) - x;

        long d = x - Math.Min(sl, tl);
        ans = Math.Min(ans, d);

        long d_sr = sr - x;
        long d_tl = x - tl;
        long d1 = 2 * Math.Min(d_sr, d_tl) + Math.Max(d_sr, d_tl);
        ans = Math.Min(ans, d1);

        long d_sl = x - sl;
        long d_tr = tr - x;
        long d2 = 2 * Math.Min(d_tr, d_sl) + Math.Max(d_tr, d_sl);
        ans = Math.Min(ans, d2);

        return ans;
    }

}


Measured memory_bytes: 18640
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

int mod_string(string s, int MOD){
  int res = 0;
  for(int i = 0; i < s.size(); i++){
    res = (res * 10 + s[i]-'0') % MOD;
  }
  return res;
}

signed main(){

  string s; cin >> s;

  int t = mod_string(s, 9);
  if(t == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3896
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,R = I()
if N < 10:
    print(R+(10-N)*100)
else:
    print(R)

Measured memory_bytes: 72728
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  string s, t;
  cin >> s >> t;

  int ans = 0;
  rep(i, s.size()){
    if (s.at(i) != t.at(i)){
      ans ++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    char a, b;
    cin >> a >> b;
    if (a < b) out("<");
    else if (a > b) out(">");
    else out("=");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, l;
    cin >> n >> l;
    ll sum = 0;
    rep(i, n) sum += l + i;
    ll diff = LONG_LONG_MAX, val;
    rep(i, n) {
        ll tmp = 0;
        rep(j, n) {
            if (j == i) continue;
            tmp += l + j;
        }
        if (diff > abs(sum - tmp)) {
            diff = abs(sum - tmp);
            val = tmp;
        }
    }
    cout << val << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
using namespace std;

const int N = 333;

int n, m;
char color[N][N];
int f[N][N], tmp[N][N];

int solve(int i, int j) {
	for (int k = 0; k <= n; k++) {
		for (int l = 0; l <= n; l++) {
			if (k == 0 || l == 0) {
				tmp[k][l] = 0;
			} else {
				tmp[k][l] = tmp[k - 1][l - 1] + (color[k - 1][i] == color[l - 1][j]);
			}
		}
	}
	for (int k = 0; k <= n; k++) {
		for (int l = 0; l <= n; l++) {
			if (k == 0 || l == 0) {
				f[k][l] = 0;
			} else {
				f[k][l] = min(f[k - 1][l], f[k][l - 1]) + tmp[k][l];
			}
		}
	}
	return f[n][n];
}

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", color[i]);
	}
	int ans = 0;
	for (int i = 0; i + 1 < m; i++) {
		ans += solve(i, i + 1);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H, vector<int>(W, 0));
    int odd = 0;
    rep(i, 0, H) rep(j, 0, W) {
        cin >> a[i][j];
        if (a[i][j] & 1) odd++;
    }
    vector<tuple<int, int, int, int>> ans;
    int num = 0, x = 0, y = 0;
    rep(iter, 0, W*H) {
        if (a[x][y] & 1) num++;

        int nx = x, ny = y;
        if(x % 2 == 0) {
            if (ny == W-1) nx++;
            else ny++;
        }
        else {
            if (ny == 0) nx++;
            else ny--;
        }
        if (num & 1) if (num < odd) ans.emplace_back(x+1, y+1, nx+1, ny+1);
        x = nx, y = ny;
    }
    cout << ans.size() << endl;
    for (auto p : ans) {
        int a, b, c, d;
        tie(a, b, c, d) = p;
        cout << a << " " << b << " " << c << " " << d << endl;
    }
}

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

using namespace std;

int N;
long long int K;

long long int a[1005];
long long int s[1005];

vector<long long int > V;

int main(void) {

	cin >> N>>K;

	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}

	for (int i = 1; i <= N; i++) {
		s[i] = a[i] + s[i - 1];
	}

	for (int i = 1; i <= N; i++) {
		for (int j = i; j <= N; j++) {
			V.push_back(s[j] - s[i-1]);
		}
	}
	sort(V.begin(), V.end());

	/*for (int i = 0; i < (int)V.size(); i++) {
		cout << V[i] << endl;
	}*/


	long long int ans = 0;
	long long int tmp = 1;

	for (int i = 1; i <= 59; i++) {
		tmp *= (long long int) 2;
	}

	while (tmp > (long long int) 0) {
		
		//long long int NUM = upper_bound(V.begin(), V.end(), ans + tmp*2-1) - lower_bound(V.begin(), V.end(), ans + tmp);
		
		long long int NUM = 0;
		for (int i = 0; i < (int)V.size(); i++) {
			//if (ans+tmp <= V[i] && V[i] <= ans+tmp * 2 - 1) { NUM++; }
			if (((ans + tmp) & V[i]) == (ans + tmp)) { NUM++; }
		}
		//cout << "tmp= " << tmp <<"  NUM= " <<NUM<<endl;
		if (NUM >= (long long int) K) { ans += tmp; }
		tmp /= (long long int) 2;
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 6512
FLAG = bool()
H_list = []
W_list = []

while 1:
    H,W = list(map(int,input().split()))
    H_list.append(H)
    W_list.append(W)

    if H == 0 and W == 0:
        break

for k in range(len(H_list) - 1):
    for i in range(H_list[k]):
        if i % 2 == 0:
            FLAG = True
        else:
            FLAG = False

        for j in range(W_list[k]):
            if FLAG == True:
                print('#',end='')
                FLAG = False
            else:
                print('.',end='')
                FLAG = True
        print('')
    print('')





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

int main()
{
	int q = 0;
	int	p0x = 0, p0y = 0, p1x = 0, p1y = 0, p2x = 0, p2y = 0,p3x = 0, p3y = 0;
	int t = 0;

	cin >> q;
	
	for (int i = 0; i < q; i++) {
		cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> p3x >> p3y;

		if ((p1x - p0x) * (p3y - p2y) - (p1y - p0y) * (p3x - p2x) == 0)
			t = 2;
		else if ((p1x - p0x) * (p3x - p2x) + (p1y - p0y) * (p3y - p2y) == 0)
			t = 1;
		else
			t = 0;

		cout << t << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a[10];
	for (int b = 0; b < 10; b++)cin >> a[b];
	sort(a, a + 10);
	for (int c = 9; c > 6; c--)printf("%d\n", a[c]);
}

Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#define LEN 100005
using namespace std;
typedef struct  {
    char name[100];
    int t;
}p;

p Q[LEN];
int head ,tail,n;

void enqueue(p x){
    Q[tail]=x;
    tail = (tail+1)%LEN;
    }
void dequeue(p x){
    x=Q[head];
    
}
int main (){
p a;
int n,q;
cin >>n>>q;
for(int i=0;i<n;i++){
    cin >> Q[i].name>>Q[i].t;
}
head=0;tail=n;

int c=0;
while(tail != head){
  dequeue(a);
    if(Q[head].t<=q){
        c+=Q[head].t;
        cout << Q[head].name<<" "<<c<<endl;
    }
    else {
        c +=q;
        Q[head].t-=q;
        a=Q[head];
         enqueue(a);

    }
head =(head+1)%LEN;
}
return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//
int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string s, t;
    cin >> s >> t;
    if(s == t){
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 0; i < s.size(); ++i){
        s = (s[s.size() - 1]) + s;
        s.erase(s.begin() + s.size() - 1);
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



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

int main()
{
  string s1;
  string s2;
  cin >> s1 >> s2;

  ll sum = 0;
  rep(i, s1.size()){
    if (s1[i] != s2[i]) {
      sum ++;
    }
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3824
def price(x)
  case x
  when 1 then 300000
  when 2 then 200000
  when 3 then 100000
  else 0
  end
end

x, y = gets.split.map(&:to_i)
z = 0
z = 400000 if x == 1 && y == 1
puts z +  price(x) + price(y)

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

int main() {
  int n;
  while(cin>>n, n) {
    int s[n][n];
    int mi[n];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) {
        cin >> s[j][i];
        if (j==0 || s[j][i] < s[mi[i]][i]) {
          mi[i] = j;
        }
      }
    int i;
    for(i=0; i<n; i++) {
      int j;
//      cout << mi[i] << " ";
      for (j=0; j<n; j++) {
        if (s[mi[i]][i] < s[mi[i]][j]) {
          break;
        }
      }
      if (j == n) {
        cout << s[mi[i]][i] << endl;
        break;
      }
    }
    if (i == n) {
      cout << 0 << endl;
    }
  }
}

Measured memory_bytes: 0
//gomenne
#include<iostream>
using namespace std;
int N,A[2000];
long ans,K,mod=1e9+7;
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)
	{
		long cnt=0,t=0;
		for(int j=0;j<N;j++)if(A[j]>A[i])cnt++,t+=j<i;
		ans+=K*(K-1)/2%mod*cnt%mod+t*K%mod;
		ans%=mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
 using namespace std;
 int main() {

 int N,A;
 cin>>N>>A;

 int L=A;
 int R=A+N-1;

 int eat;
 if(R<=0)eat=R;
 else if(L>=0)eat=L;
 else eat=0;
  
 int answer=(R+L)*(R-L+1)/2-eat;

 cout<<answer<<endl;

 return 0;
   
 }


Measured memory_bytes: 256
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>
#include <iomanip>
#include <stack>

using namespace std;
using namespace boost::multiprecision;

long long r, D, x;

void solve() {
	cin >> r >> D >> x;
	for (int i = 1; i <= 10; i++) {
		x = x * r - D;
		cout << x << endl;
	}
	return;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define MOD 1000000007

int main(){
  long n;
  cin>>n;
  vector<long> dp(n,0);
  vector<long> acc(n,0);
  dp[n-1] = n;
  acc[n-1] = n;

  for(int i=n-2; i>=0; i--){
    dp[i] = (n-1)*n;
    if(i<n-3){
      dp[i] -= n-i-3;
      dp[i] += acc[i+3];
    }
    dp[i] += dp[i+1];
    dp[i] %= MOD;
    acc[i] = (acc[i+1]+dp[i])%MOD;
  }

  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 15872